masterboy / uCML-Structural-Programming-Language

uCML Structural Programming Language Interpreter and Runtime Environment

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

uCML Interpreter and Runtime Environment

uCML is a structural / functional programming language that was assigned to be implemented by my university compiler course teacher. I had a dream to build a real working programming language since when I was a school kid just got introduced to computer programming through PHP based web development. As I have a very curious mind, I never stopped wondering how things work in the electronics world. How a computer works, how programming works, this sort of question used to torture me until I got the answers and got satisfied by the answers. So, I took it into my own hands to build a working interpreter to understand how the it really works.

Build

Since I use windows as my primary operating system in my personal work place, I had to download the GNU implementation for windows. You need these things in your system to build the interpreter from source code:-

  1. flex
  2. bison
  3. gcc
  4. make

The build process is farely simple. It's just a "make" command away:-

$ make

After running this command you'll get an executable called "uc.exe" on Windows and "uc" on Unix/Linux under the src folder. I've tested it on Windows (7 32/64) and Linux (WSL Ubuntu 16.04). It works seemlessly in both systems. It is recommended to copy the executable binary into the "build" directory for better testing (more on this later), the windows executable is already provided there .

Running Programs

Example programs including all kind of programming features implemented by the interpreter has been provided under the "test" directory. Features implemented so far:-

  1. Statements
  2. Variables
  3. Expressions (mathematical/logical/function calling etc.)
  4. Control (If-else)
  5. Loop (for-to-by)
  6. Function declaration and calling
  7. Anonymous function (I don't know the purpose, but my teacher insisted, so I did)

You can run the programs by calling the uc executable with program file name. For example:-

$ cd base_dir
$ "./build/uc" test/factorial.ucml
10      
9       
8       
7       
6       
5       
4       
3       
2       
1       
0       
3628800 

Test Cases

You may find running all the programs one by one a cumbersome task. Since I'm more fluent in Java than I am in C, I made a Test Runner program "TestRunner.java" (compiled class file is also provided in the base directory) that takes "build/uc" as the interpreter and uses "test/*" as input programs and runs all the programs one by one. It also echoes the output generated by each ucml programs from test directory to the console.

$ java TestRunner
>> Running: ./uc test/anonymous_function.ucml
<< Success!                                  
180                                          
                                             
>> Running: ./uc test/basic_everything.ucml  
<< Success!                                  
19                                           
4456                                         
751                                          
41                                           
180                                          
1                                            
0                                            
1                                            
1                                            
0                                            
0                                            
0   
.....

Comment

This is a buggy and toy program made solely for learning purpose. Never use it on production. Not even at your own risk.

About

uCML Structural Programming Language Interpreter and Runtime Environment


Languages

Language:C 68.5%Language:Yacc 19.3%Language:Java 5.5%Language:Lex 5.5%Language:Makefile 1.2%