for added
parent
e80f2e0392
commit
148e0e23c6
|
@ -9,6 +9,8 @@ void yyerror(const char *s) {
|
||||||
line_number,
|
line_number,
|
||||||
s,
|
s,
|
||||||
yytext);
|
yytext);
|
||||||
|
|
||||||
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
%}
|
%}
|
||||||
|
@ -37,6 +39,7 @@ void yyerror(const char *s) {
|
||||||
|
|
||||||
"while" { return WHILE; }
|
"while" { return WHILE; }
|
||||||
"do" { return DO; }
|
"do" { return DO; }
|
||||||
|
"for" { return FOR; }
|
||||||
|
|
||||||
"if" { return IF; }
|
"if" { return IF; }
|
||||||
"else" { return ELSE; }
|
"else" { return ELSE; }
|
||||||
|
|
|
@ -16,7 +16,7 @@ bool debug = false; // debug mode
|
||||||
}
|
}
|
||||||
|
|
||||||
%token <str> IDENTIFIER NUMBER
|
%token <str> IDENTIFIER NUMBER
|
||||||
%token LBRACE RBRACE LPAREN RPAREN SEMICOLON ASSIGN PLUS MINUS MULT DIV MOD RET PRINT WHILE DO IF ELSE AND OR NOT LT GT EQ
|
%token LBRACE RBRACE LPAREN RPAREN SEMICOLON ASSIGN PLUS MINUS MULT DIV MOD RET PRINT WHILE DO FOR IF ELSE AND OR NOT LT GT EQ
|
||||||
%token FUNC COMMA
|
%token FUNC COMMA
|
||||||
|
|
||||||
%type <str> expr program statement block func_decl param_list params
|
%type <str> expr program statement block func_decl param_list params
|
||||||
|
@ -55,6 +55,17 @@ statement:
|
||||||
LPAREN expr RPAREN SEMICOLON
|
LPAREN expr RPAREN SEMICOLON
|
||||||
{ if (debug) printf("\033[1;34mDO-WHILE LOOP ENDED\033[0m\n"); }
|
{ if (debug) printf("\033[1;34mDO-WHILE LOOP ENDED\033[0m\n"); }
|
||||||
|
|
||||||
|
| FOR { if (debug) printf("\033[1;34mFOR LOOP DETECTED\033[0m\n"); }
|
||||||
|
LPAREN
|
||||||
|
expr SEMICOLON { if (debug) printf("\033[1;34mFOR INITIALIZE ENDED\033[0m\n"); }
|
||||||
|
expr SEMICOLON { if (debug) printf("\033[1;34mFOR CONDITION ENDED\033[0m\n"); }
|
||||||
|
expr
|
||||||
|
RPAREN
|
||||||
|
{ if (debug) printf("\033[1;34mFOR BODY STARTS\033[0m\n"); }
|
||||||
|
block
|
||||||
|
{ if (debug) printf("\033[1;34mFOR LOOP ENDED\033[0m\n"); }
|
||||||
|
;
|
||||||
|
|
||||||
| IF LPAREN expr RPAREN block
|
| IF LPAREN expr RPAREN block
|
||||||
{ if (debug) printf("\033[1;34mIF BLOCK ENDED\033[0m\n"); }
|
{ if (debug) printf("\033[1;34mIF BLOCK ENDED\033[0m\n"); }
|
||||||
| IF LPAREN expr RPAREN block
|
| IF LPAREN expr RPAREN block
|
||||||
|
|
Loading…
Reference in New Issue