Its a test project for learning how compilers and transpilers like babel work behind the scenes.
It takes your code from <filename>.tomper
file, compile it, and then displays the result in the terminal
- Lexer, parser, transfomer, code generator, and compiler, all implemented from scratch.
- Compiles code from file of your choice.
- Support the following operations:
Operation | Support |
---|---|
Addition (+) | β |
Subtraction (-) | β |
Multiplication (x) | β |
Division (/) | β |
The program has 3 parts:
- Call Expressions
- Caller function
- Parameters
- Call expressions are the expression containing the operations we want to perform like: addition, subtraction etc.
- Every call expression must be written inside round parentheses
( ... )
.
- Caller functions are the functions representing the type of operation to be performed.
- Currently there are only 4 caller functions:
add
,subtract
,multiply
, anddivide
. - Caller functions are written inside the call expressions:
( add ... )
,( subtract ... )
( multiply ... )
( divide ... )
- Every caller function will have two parameters. These parameters can either be numbers or other call expression.
- Parameters are written inside the call expressions, after the caller functions.
- There should be only two parameters (since we are using binary operators like
+
,-
,*
,/
), separated by spaces.
Input | Compiled | Output |
---|---|---|
( add 2 4 ) |
(2+4) | 6 |
( subtract 5 3 ) |
(5-3) | 2 |
( add 2 ( subtract 5 3 ) ) |
(2+(5-3)) | 4 |
( add ( multiply 4 5 ) ( divide 20 4 ) ) |
((4*5)+(20/4)) | 25 |
Clone the repository to your local machine.
git clone git@github.com:varunKT001/tcc.git
You can test different components by using the following command:
npm run test
Create a file inside the root of the project with a .tomper
extension.
Write your code inside the file (following the syntax given above).
( add ( add 2 4 ) ( subtract 5 3 ) )
Compile and run the file using the following command:
npm run compile <filename>.tomper