1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | %{ #include <stdlib.h> #include <stdio.h> #include "y.tab.h" int yyerror(char *); %} %% [a-z] { yylval = *yytext - 'a'; return VAR; } [0-9]+ { yylval = atoi(yytext); return INT; } |
meine parser.y Datei:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | {% #define YYSTYPE int #include <math.h> #include <stdio.h> int yyerror(char *); int yylex(void) ; int sym[26]; %} /* Definizioni */ %token INT VAR %left '+' '-' %left '*' '/' %% program: program statement '\n' | ; statement: expr { printf("%d\n", $1); } | VAR '=' expr { sym[$1] = $3; } ; expr: INT | VAR { $$ = sym[$1]; } | expr '+' expr { $$ = $1 + $3; } | expr '-' expr { $$ = $1 - $3; } | expr '*' expr { $$ = $1 * $3; } | expr '/' expr { $$ = $1 / $3; } | '(' expr ')' { $$ = $2; } ; %% |
Befehle die ich für die Kompilierung benutz habe:
1 2 3 | yacc -b parser -dtv parser.y lex scanner.l gcc parser.tab.c lex.yy.c main.c |
Aber ich erhalte diesen Error:
1 2 3 4 | /tmp/cc0ypwyq.o: In function `yyparse': parser.tab.c:(.text+0x922): undefined reference to `newDecList' parser.tab.c:(.text+0x951): undefined reference to `newIntExp' /tmp/cciuv2vw.o: In function `main': main.c:(.text+0x2e0): undefined reference to `showAbsyn' collect2: error: ld returned 1 exit status |
Ich habe alles versucht aber leider finde ich den Fehler nicht. Kann es sein, dass ich falsche Befehle benutze?
Bearbeitet von Developer92:
Titel korrigiert, Codeblöcke richtig gesetzt. Was man mit ein bisschen Syntax alles erreichen kann ☺