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.
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:-
- flex
- bison
- gcc
- 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 .
Example programs including all kind of programming features implemented by the interpreter has been provided under the "test" directory. Features implemented so far:-
- Statements
- Variables
- Expressions (mathematical/logical/function calling etc.)
- Control (If-else)
- Loop (for-to-by)
- Function declaration and calling
- 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
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
.....
This is a buggy and toy program made solely for learning purpose. Never use it on production. Not even at your own risk.