@@ -23,7 +23,7 @@ GreekBase
2323│ ├── ast_builder.py ← used for generating AST tree from ANTLR tree
2424│ ├── astGreek.py ← AST tree node classes
2525│ ├── semantic_checker.py ← semantic errors handling etc.
26- │ └──
26+ │ └── codegen.py ← C (from AST) code generator
2727├── examples/ ← example source files
2828├── output/ ← generated C source files
2929├── run.sh ← bash script for generating ANTLR files
@@ -41,7 +41,8 @@ GreekBase
4141 ./[run.sh](./run.sh)
4242in order to generate the parser and its tools needed later.
4343
44- For now, printing the AST tree is possible, as well as receiving semantic errors and warnings.
44+ For now, printing the AST tree is possible, as well as receiving semantic errors and warnings in the console.
45+ Output C source file is saved to ./[ output/] ( ./output/ ) directory if there are now [ Error] s.
4546
46472 . To do so, please run [ main.py] ( ./main.py ) .
4748
@@ -51,7 +52,6 @@ For now, printing the AST tree is possible, as well as receiving semantic errors
5152x : int := 5;
5253y : int := 10;
5354x : int;
54- z := 5.5;
5555
5656if x < y then
5757 x := x + 1;
@@ -63,8 +63,26 @@ print y;
6363```
64642 . AST tree:
6565``` python
66- Program(line=1, column=0, statements=[VariableDeclaration(line=1, column=0, varType=<class 'int'>, id='x', varValue=IntLiteral(line=1, column=11, value=5)), VariableDeclaration(line=2, column=0, varType=<class 'int'>, id='y', varValue=IntLiteral(line=2, column=11, value=10)), VariableDeclaration(line=3, column=0, varType=<class 'int'>, id='x', varValue=None), Assignment(line=4, column=0, id='z', value=FloatLiteral(line=4, column=5, value=5.5)), IfStatement(line=6, column=0, condition=Condition(line=6, column=3, left=Identifier(line=6, column=3, value='x'), operator='<', right=Identifier(line=6, column=7, value='y')), then_branch=[Assignment(line=7, column=4, id='x', value=AdditionOperator(line=7, column=9, left=Identifier(line=7, column=9, value='x'), operator='+', right=IntLiteral(line=7, column=13, value=1)))], else_branch=[Assignment(line=8, column=5, id='y', value=AdditionOperator(line=8, column=10, left=Identifier(line=8, column=10, value='y'), operator='-', right=IntLiteral(line=8, column=14, value=1)))]), PrintStatement(line=11, column=0, value=Identifier(line=11, column=6, value='x')), PrintStatement(line=12, column=0, value=Identifier(line=12, column=6, value='y'))])
66+ Program(line=1, column=0, statements=[VariableDeclaration(line=1, column=0, varType=<class 'int'>, id='x', varValue=IntLiteral(line=1, column=11, value=5)), VariableDeclaration(line=2, column=0, varType=<class 'int'>, id='y', varValue=IntLiteral(line=2, column=11, value=10)), VariableDeclaration(line=3, column=0, varType=<class 'int'>, id='x', varValue=None), IfStatement(line=5, column=0, condition=Condition(line=5, column=3, left=Identifier(line=5, column=3, value='x', type=None), operator='<', right=Identifier(line=5, column=7, value='y', type=None)), then_branch=[Assignment(line=6, column=4, id='x', value=AdditionOperator(line=6, column=9, left=Identifier(line=6, column=9, value='x', type=None), operator='+', right=IntLiteral(line=6, column=13, value=1)))], else_branch=[Assignment(line=7, column=5, id='y', value=AdditionOperator(line=7, column=10, left=Identifier(line=7, column=10, value='y', type=None), operator='-', right=IntLiteral(line=7, column=14, value=1)))]), PrintStatement(line=10, column=0, value=Identifier(line=10, column=6, value='x', type=None)), PrintStatement(line=11, column=0, value=Identifier(line=11, column=6, value='y', type=None))])
6767```
68683 . Semantic check:
6969
70- ![ ] ( ./img/example1_semantic.png )
70+ ![ ] ( ./img/example1_semantic1.png )
71+
72+ 4 . Code in C:
73+ ``` C
74+ #include < stdio.h>
75+ int main (){
76+ int x = 5;
77+ int y = 10;
78+ int x;
79+ if(x < y){
80+ x = x + 1;
81+ }else {
82+ y = y - 1;
83+ }
84+ printf ("%d", x);
85+ printf("%d", y);
86+ return 0;
87+ }
88+ ```
0 commit comments