Parser for language, look like C/C++
Input Text (written with my own syntax)
|
\|
Lexical Analyzer (devide text on lexems
and check all allowed symbols)
|
\|
List of Lexems ( intermediate
representation of input lexems as json list)
|
\|
Syntactic Analyzer (check on valid syntax and build AST tree
as result)
|
\|
AST Tree ( intermediate
representation of input program)\
|
\|
Reverse
Polish Notation (well, no comments)
and Executing
Gorod = Block .
Block = "{"
{VarDefinition}
{Statement}
"}" .
VarDefinition = Type Ident {"," Ident} ";" .
Type = "int" .
Ident = letter {letter | digit | "_"} .
Statement = [Assignment] ";"
| "read" "(" Ident ")" ";"
| "write" "(" Expr ")" ";"
| "if" "(" LogicExpr ")" Block
| "for" Assignment "to" Expr "by" Expr "while" "(" LogicExpr ")" Block "rof" ";" .
Assignment = Ident "=" Expr .
Expr = CondExpr
| Add .
Add = Mult [( "+" | "-" ) Mult] .
Mult = Power [( "*" | "/" ) Power] .
Power = Group ["^" Power] .
Group = "(" Expr ")"
| Number
| Ident .
CondExpr = LogicExpr ["?" Expr ":" Expr] .
LogicExpr = Ident ("<" | ">") Expr .
Number = [ "-" ] digit{digit} .
{
int k; int sum, input, i;
sum = 0;
for i=0; to 3^144 by k+1 while(sum<1000){
read(input);
if (input > 0)
{
sum = sum + input;
write(sum);
}
}rof;
sum = sum^2;
write(sum);
}
[
{
"line": 1,
"posInLine": 1,
"type": "token",
"value": "{"
},
{
"line": 2,
"posInLine": 3,
"type": "token",
"value": "int"
},
{
"id": 0,
"line": 2,
"posInLine": 7,
"type": "ident",
"value": "k"
},
........