I can't compile my flex and yacc code because of following errors...
flex konw.lex
bison -v -d konw.y -o konw.c
gcc -g konw.c lex.yy.c -lfl -o konw
lex.yy.c: In function `yy_get_next_buffer':
lex.yy.c:996: error: syntax error before ';' token
lex.yy.c:996: error: syntax error before ')' token
lex.yy.c:1056: error: syntax error before ';' token
lex.yy.c:1056: error: syntax error before ')' token
lex.yy.c: In function `yy_get_previous_state':
lex.yy.c:1100: error: syntax error before ';' token
lex.yy.c:1100: error: syntax error before ')' token
lex.yy.c:1108: error: `yy_c' undeclared (first use in this function)
lex.yy.c:1108: error: (Each undeclared identifier is reported only once
lex.yy.c:1108: error: for each function it appears in.)
lex.yy.c: At top level:
lex.yy.c:1117: error: syntax error before "return"
lex.yy.c: In function `yy_scan_string':
lex.yy.c:1493: error: syntax error before ';' token
lex.yy.c:1493: error: syntax error before ')' token
lex.yy.c: In function `yy_scan_bytes':
lex.yy.c:1521: error: syntax error before ';' token
lex.yy.c:1521: error: syntax error before ')' token
mingw32-make.exe: *** [konw] Error 1
My source code:
FLEX
====
%{
#include "konw.h"
#include <stdio.h>
#include <string.h>
%}
%x koment dekl_int dekl_char for for1 for2 for3 for4
ZMIENNA [a-zA-Z][a-zA-Z0-9]+
LICZBA [0-9]+
%%
Flex-RegEx
"/*" BEGIN(koment);
<koment>"*/" BEGIN(INITIAL);
<koment>.
<koment>\n
int { BEGIN(dekl_int); return L_INT; }
<dekl_int>[ \t]* /* ignoruj biale spacje */
<dekl_int>{ZMIENNA} return L_ID;
<dekl_int>";" { BEGIN(INITIAL); return L_SREDNIK; }
char { BEGIN(dekl_char); return L_CHAR; }
<dekl_char>[ \t]* /* ignoruj biale spacje */
<dekl_char>{ZMIENNA} return L_ID;
<dekl_char>";" { BEGIN(INITIAL); return L_SREDNIK; }
for[ \t]* { BEGIN(for); return L_FOR; }
<for>"(" { BEGIN(for1); return L_LEWY; }
<for1>[ \t]* /* ignoruj biale spacje */
<for1>[^';']* printf("%s",yytext);
<for1>";" { BEGIN(for2); return L_SREDNIK; }
<for2>";" { BEGIN(for3); return L_SREDNIK; }
<for2>[ \t]* /* ignoruj biale spacje */
<for2>[^';']* { printf("%s",yytext); BEGIN(for3); }
<for3>")" { BEGIN(for4); return L_PRAWY; }
<for3>[ \t]* /* ignoruj biale spacje */
<for3>[^')']* printf("%s",yytext);
<for4>";" { BEGIN(INITIAL); return L_SREDNIK; }
<for4>[ \t]* /* ignoruj biale spacje */
<for4>. printf("%c",yytext[0]);
. return yytext[0];
%%
int yywrap(void){
return 1;
}
YACC
====
%{
#include <stdio.h>
int yylex(void);
%}
%token L_FOR L_LEWY L_PRAWY L_SREDNIK L_INT L_CHAR L_ID L_NUM L_FUNKCJA
%start program
%%
program
: kod
;
kod
: instrukcja
| kod instrukcja
;
deklaracja
: L_INT L_ID
| L_CHAR L_ID
;
petla_for
: L_FOR L_LEWY wyrazenie L_SREDNIK wyrazenie L_SREDNIK wyrazenie L_PRAWY instrukcja
;
operator
: '/'
| '='
| '!='
| '<'
| '>'
;
wyrazenie
: L_ID operator L_ID
| L_ID operator L_NUM
;
funkcja
: L_FUNKCJA L_LEWY deklaracja L_PRAWY
;
instrukcja
: L_SREDNIK
| deklaracja L_SREDNIK
| petla_for
| wyrazenie
| funkcja
;
%%
void yyerror(char *s){
fprintf(stderr, "%s\n", s);
exit(2);
}
int main(void){
yyparse();
return 0;
}
What is wrong ?
Wojtek