funcs added
parent
2841810eba
commit
aaa21812f3
|
@ -9,8 +9,6 @@ void yyerror(const char *s) {
|
||||||
line_number,
|
line_number,
|
||||||
s,
|
s,
|
||||||
yytext);
|
yytext);
|
||||||
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
%}
|
%}
|
||||||
|
@ -36,6 +34,9 @@ void yyerror(const char *s) {
|
||||||
"if" { return IF; }
|
"if" { return IF; }
|
||||||
"else" { return ELSE; }
|
"else" { return ELSE; }
|
||||||
|
|
||||||
|
"func" { return FUNC; }
|
||||||
|
"," { return COMMA; }
|
||||||
|
|
||||||
"//" {
|
"//" {
|
||||||
int c;
|
int c;
|
||||||
while ((c = input()) != '\n' && c != 0);
|
while ((c = input()) != '\n' && c != 0);
|
||||||
|
|
|
@ -17,8 +17,9 @@ 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 IF ELSE AND OR NOT
|
%token LBRACE RBRACE LPAREN RPAREN SEMICOLON ASSIGN PLUS MINUS MULT DIV MOD RET PRINT WHILE IF ELSE AND OR NOT
|
||||||
|
%token FUNC COMMA
|
||||||
|
|
||||||
%type <str> expr program statement block
|
%type <str> expr program statement block func_decl param_list params
|
||||||
|
|
||||||
%left OR
|
%left OR
|
||||||
%left AND
|
%left AND
|
||||||
|
@ -55,6 +56,28 @@ statement:
|
||||||
{ if (debug) printf("\033[1;34mELSE BLOCK STARTED\033[0m\n"); }
|
{ if (debug) printf("\033[1;34mELSE BLOCK STARTED\033[0m\n"); }
|
||||||
block
|
block
|
||||||
{ if (debug) printf("\033[1;34mELSE BLOCK ENDED\033[0m\n"); }
|
{ if (debug) printf("\033[1;34mELSE BLOCK ENDED\033[0m\n"); }
|
||||||
|
|
||||||
|
| func_decl
|
||||||
|
;
|
||||||
|
|
||||||
|
func_decl:
|
||||||
|
FUNC IDENTIFIER {
|
||||||
|
if (debug) printf("\033[1;35mFUNCTION: %s\033[0m\n", $2);
|
||||||
|
free($2);
|
||||||
|
}
|
||||||
|
LPAREN param_list RPAREN
|
||||||
|
{ if (debug) printf("\033[1;35mFUNCTION PARAMS END\033[0m\n"); }
|
||||||
|
block
|
||||||
|
{ if (debug) printf("\033[1;35mFUNCTION END\033[0m\n"); }
|
||||||
|
;
|
||||||
|
|
||||||
|
param_list:
|
||||||
|
| params
|
||||||
|
;
|
||||||
|
|
||||||
|
params:
|
||||||
|
IDENTIFIER { if (debug) printf("\033[1;35mPARAM: %s\033[0m\n", $1); free($1); }
|
||||||
|
| params COMMA IDENTIFIER { if (debug) printf("\033[1;35mPARAM: %s\033[0m\n", $3); free($3); }
|
||||||
;
|
;
|
||||||
|
|
||||||
// Блок - { program }, т.е. это последовательность утверждений и она находится в скобках { }
|
// Блок - { program }, т.е. это последовательность утверждений и она находится в скобках { }
|
||||||
|
|
Loading…
Reference in New Issue