debug messages added
parent
00e45f0c6a
commit
84efc813ad
|
@ -54,6 +54,7 @@ LETTER_OR_DIGIT [a-zA-Z0-9_]
|
|||
}
|
||||
|
||||
{LETTER}{LETTER_OR_DIGIT}* {
|
||||
yylval.str = strdup(yytext);
|
||||
return IDENTIFIER;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,15 +22,16 @@ void free_node(char *str) {
|
|||
}
|
||||
|
||||
%token SHORT_DECLARATION LBRACE RBRACE SEMICOLON ASSIGN LPAREN RPAREN COMMA
|
||||
%token VAR FUNC RETURN IDENTIFIER STRING_LITERAL FLOAT_LITERAL NUMBER
|
||||
%token PLUS MINUS MULT DIV MOD EXP
|
||||
%token VAR FUNC RETURN STRING_LITERAL FLOAT_LITERAL NUMBER
|
||||
%token PLUS MINUS MULT DIV MOD
|
||||
%token STRING
|
||||
%token UINT UINT8 UINT16 UINT32 UINT64
|
||||
%token INT INT8 INT16 INT32 INT64
|
||||
|
||||
%token <str> IDENTIFIER
|
||||
|
||||
%left PLUS MINUS
|
||||
%left MULT DIV MOD
|
||||
%left EXP
|
||||
%left UMINUS
|
||||
|
||||
%%
|
||||
|
@ -55,23 +56,23 @@ statements_list:
|
|||
;
|
||||
|
||||
expr:
|
||||
RETURN math_expr { }
|
||||
RETURN math_expr { printf("\033[1;35mRETURN math expr\033[0m\n") }
|
||||
| RETURN literal { printf("\033[1;35mRETURN literal\033[0m\n") }
|
||||
| IDENTIFIER ASSIGN math_expr { }
|
||||
| math_expr { }
|
||||
;
|
||||
|
||||
math_expr:
|
||||
math_expr PLUS math_expr { }
|
||||
| math_expr MINUS math_expr { }
|
||||
| math_expr MULT math_expr { }
|
||||
| math_expr DIV math_expr { }
|
||||
| math_expr MOD math_expr { }
|
||||
| math_expr EXP math_expr { }
|
||||
| MINUS math_expr %prec UMINUS { }
|
||||
| LPAREN math_expr RPAREN { }
|
||||
| NUMBER { }
|
||||
| FLOAT_LITERAL { }
|
||||
| IDENTIFIER { }
|
||||
math_expr PLUS math_expr { printf("PLUS\n"); }
|
||||
| math_expr MINUS math_expr { printf("MINUS\n"); }
|
||||
| math_expr MULT math_expr { printf("MULT\n"); }
|
||||
| math_expr DIV math_expr { printf("DIV\n"); }
|
||||
| math_expr MOD math_expr { printf("MOD\n"); }
|
||||
| MINUS math_expr %prec UMINUS { printf("UMINUS\n"); }
|
||||
| LPAREN { printf("LPAREN\n"); } math_expr RPAREN { printf("RPAREN\n"); }
|
||||
| NUMBER { printf("NUMBER\n"); }
|
||||
| FLOAT_LITERAL { printf("FLOAT LITERAL\n"); }
|
||||
| IDENTIFIER { printf("IDENTIFIER: %s\n", $1); }
|
||||
;
|
||||
|
||||
/* Остальные правила остаются без изменений */
|
||||
|
@ -104,7 +105,8 @@ literal:
|
|||
;
|
||||
|
||||
arg_declaration:
|
||||
IDENTIFIER type { }
|
||||
IDENTIFIER type
|
||||
{ printf("\033[1;35mARG: %s\n\033[0m", $1); }
|
||||
;
|
||||
|
||||
arg_list:
|
||||
|
@ -117,15 +119,18 @@ return_type:
|
|||
;
|
||||
|
||||
func_declaration:
|
||||
FUNC IDENTIFIER LPAREN arg_list RPAREN return_type block { }
|
||||
FUNC IDENTIFIER
|
||||
{ printf("\033[1;35mHELLO, FUNC: %s\n\033[0m", $2); }
|
||||
LPAREN arg_list RPAREN return_type block
|
||||
{ printf("\033[1;35mBY, FUNC: %s\n\n\033[0m", $2); }
|
||||
;
|
||||
|
||||
var_declaration:
|
||||
IDENTIFIER SHORT_DECLARATION math_expr { }
|
||||
| IDENTIFIER SHORT_DECLARATION literal { }
|
||||
| VAR IDENTIFIER type { }
|
||||
| VAR IDENTIFIER type ASSIGN math_expr { }
|
||||
| VAR IDENTIFIER type ASSIGN literal { }
|
||||
IDENTIFIER SHORT_DECLARATION math_expr { printf("\033[1;33mSHORT DECL with math expr: %s\n\033[0m", $1); }
|
||||
| IDENTIFIER SHORT_DECLARATION literal { printf("\033[1;33mSHORT DECL with literal: %s\n\033[0m", $1); }
|
||||
| VAR IDENTIFIER type { { printf("\033[1;33mVAR DECL without init value: %s\n\033[0m", $2); } }
|
||||
| VAR IDENTIFIER type ASSIGN math_expr { { printf("\033[1;33mVAR DECL with math expr init value: %s\n\033[0m", $2); } }
|
||||
| VAR IDENTIFIER type ASSIGN literal { { printf("\033[1;33mVAR DECL with literal init value: %s\n\033[0m", $2); } }
|
||||
;
|
||||
|
||||
%%
|
||||
|
|
|
@ -1,8 +1,13 @@
|
|||
|
||||
|
||||
func test() {
|
||||
return "123";
|
||||
}
|
||||
|
||||
return a;
|
||||
func test(a int, b string) {
|
||||
s := "123njda skjad";
|
||||
a := 2;
|
||||
return a + 1;
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
|
Loading…
Reference in New Issue