diff --git a/src/lex/lexer.l b/src/lex/lexer.l index c9bf739..2307af7 100644 --- a/src/lex/lexer.l +++ b/src/lex/lexer.l @@ -79,7 +79,15 @@ [0-9]+ {DEBUG("\"%s\" tokenized with \'ValInt\'", yytext); yylval.string = strdup(yytext); return(ValInt); }; [0-9]*\.[0-9]+ {DEBUG("\"%s\" tokenized with \'ValFloat\'", yytext); yylval.string = strdup(yytext); return(ValFloat);}; [a-zA-Z_0-9]+ {DEBUG("\"%s\" tokenized with \'Ident\'", yytext); yylval.string = strdup(yytext); return(Ident); }; -\"([^\"\n])*\" {DEBUG("\"%s\" tokenized with \'ValStr\'", yytext); yylval.string = strdup(yytext); return(ValStr);}; -\"\"\"([^\"\n]|\\\n)*\"\"\" {DEBUG("\"%s\" tokenized with \'ValMultistr\'", yytext); yylval.string = strdup(yytext); return(ValMultistr);}; +\"([^\"\n])*\" { + yytext = yytext +1; + yytext[yyleng - 2] = 0; + + DEBUG("\"%s\" tokenized with \'ValStr\'", yytext); yylval.string = strdup(yytext); return(ValStr);}; +\"\"\"([^\"\n]|\\\n)*\"\"\" { + yytext = yytext +3; + yytext[yyleng - 4] = 0; + + DEBUG("\"%s\" tokenized with \'ValMultistr\'", yytext); yylval.string = strdup(yytext); return(ValMultistr);}; .; %% diff --git a/src/main.c b/src/main.c index 03ab6b9..fab7659 100644 --- a/src/main.c +++ b/src/main.c @@ -6,6 +6,7 @@ #define LOG_LEVEL LOG_LEVEL_DEBUG extern FILE *yyin; +AST_NODE_PTR root; /** * @brief Log a debug message to inform about beginning exit procedures @@ -65,7 +66,11 @@ int main(int argc, char *argv[]) { } yyin = file; + root = AST_new_node(AST_Module, NULL); yyparse(); + FILE *output = fopen("test.txt", "w"); + AST_fprint_graphviz(file, root); + fclose(output); return 0; } diff --git a/src/yacc/parser.y b/src/yacc/parser.y index e654eff..89c4433 100644 --- a/src/yacc/parser.y +++ b/src/yacc/parser.y @@ -6,7 +6,7 @@ int yyerror(char*); extern int yylex(); - + extern AST_NODE_PTR root; } @@ -111,15 +111,8 @@ %left OpBitand OpBitor OpBitxor OpBitnot %% -program: program programbody {AST_push_node($1, $2); - FILE *file = fopen("test.txt", "w"); - AST_fprint_graphviz(file, $1); - fclose(file);} - | programbody {AST_NODE_PTR program = AST_new_node(AST_Module, NULL); - AST_push_node(program, $1); - FILE *file = fopen("test.txt", "w"); - AST_fprint_graphviz(file, program); - fclose(file); }; +program: program programbody {AST_push_node(root, $2);} + | programbody {AST_push_node(root, $1);}; programbody: moduleimport {$$ = $1;} | fundef{$$ = $1;}