moved root node to main

moved output code to main
removed '"' from string literals
This commit is contained in:
Felix Müller 2024-05-14 14:03:45 +02:00
parent 3d3083c894
commit b3ad82cc49
3 changed files with 18 additions and 12 deletions

View File

@ -79,7 +79,15 @@
[0-9]+ {DEBUG("\"%s\" tokenized with \'ValInt\'", yytext); yylval.string = strdup(yytext); return(ValInt); }; [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);}; [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); }; [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]|\\\n)*\"\"\" {DEBUG("\"%s\" tokenized with \'ValMultistr\'", yytext); yylval.string = strdup(yytext); return(ValMultistr);}; 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);};
.; .;
%% %%

View File

@ -6,6 +6,7 @@
#define LOG_LEVEL LOG_LEVEL_DEBUG #define LOG_LEVEL LOG_LEVEL_DEBUG
extern FILE *yyin; extern FILE *yyin;
AST_NODE_PTR root;
/** /**
* @brief Log a debug message to inform about beginning exit procedures * @brief Log a debug message to inform about beginning exit procedures
@ -65,7 +66,11 @@ int main(int argc, char *argv[]) {
} }
yyin = file; yyin = file;
root = AST_new_node(AST_Module, NULL);
yyparse(); yyparse();
FILE *output = fopen("test.txt", "w");
AST_fprint_graphviz(file, root);
fclose(output);
return 0; return 0;
} }

View File

@ -6,7 +6,7 @@
int yyerror(char*); int yyerror(char*);
extern int yylex(); extern int yylex();
extern AST_NODE_PTR root;
} }
@ -111,15 +111,8 @@
%left OpBitand OpBitor OpBitxor OpBitnot %left OpBitand OpBitor OpBitxor OpBitnot
%% %%
program: program programbody {AST_push_node($1, $2); program: program programbody {AST_push_node(root, $2);}
FILE *file = fopen("test.txt", "w"); | programbody {AST_push_node(root, $1);};
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); };
programbody: moduleimport {$$ = $1;} programbody: moduleimport {$$ = $1;}
| fundef{$$ = $1;} | fundef{$$ = $1;}