"for" is a keyword in the C language. Because of this you may not use "for" as the name of a token in your scanner. Replace "for" with something different, and your program will compile.
I have changed all wrong tokens and this is the result:
flex konw.lex
bison -v -d konw.y -o konw.c
gcc -g konw.c lex.yy.c -lfl -o konw
The proper code:
FLEX
====
%{
#include "konw.h"
#include <stdio.h>
#include <string.h>
%}
%x koment dekl_liczba dekl_znak petla petla1 petla2 petla3 petla4
ZMIENNA [a-zA-Z][a-zA-Z0-9]+
LICZBA [0-9]+
%%
Flex-RegEx
"/*" BEGIN(koment);
<koment>"*/" BEGIN(INITIAL);
<koment>.
<koment>\n
int { BEGIN(dekl_liczba); return L_LICZBA; }
<dekl_liczba>[ \t]* /* ignoruj biale spacje */
<dekl_liczba>{ZMIENNA} return L_ID;
<dekl_liczba>";" { BEGIN(INITIAL); return L_SREDNIK; }
char { BEGIN(dekl_znak); return L_ZNAK; }
<dekl_znak>[ \t]* /* ignoruj biale spacje */
<dekl_znak>{ZMIENNA} return L_ID;
<dekl_znak>";" { BEGIN(INITIAL); return L_SREDNIK; }
for[ \t]* { BEGIN(petla); return L_PETLA; }
<petla>"(" { BEGIN(petla1); return L_LEWY; }
<petla1>[ \t]* /* ignoruj biale spacje */
<petla1>[^';']* printf("%s",yytext);
<petla1>";" { BEGIN(petla2); return L_SREDNIK; }
<petla2>";" { BEGIN(petla3); return L_SREDNIK; }
<petla2>[ \t]* /* ignoruj biale spacje */
<petla2>[^';']* { printf("%s",yytext); BEGIN(petla3); }
<petla3>")" { BEGIN(petla4); return L_PRAWY; }
<petla3>[ \t]* /* ignoruj biale spacje */
<petla3>[^')']* printf("%s",yytext);
<petla4>";" { BEGIN(INITIAL); return L_SREDNIK; }
<petla4>[ \t]* /* ignoruj biale spacje */
<petla4>. printf("%c",yytext[0]);
. return yytext[0];
%%
YACC
====
%{
#include <stdio.h>
int yyerror( char *s );
%}
%token L_PETLA L_LEWY L_PRAWY L_SREDNIK L_LICZBA L_ZNAK L_ID L_NUM L_FUNKCJA
%start program
%%
program
: kod
;
kod
: instrukcja
| kod instrukcja
;
deklaracja
: L_LICZBA L_ID
| L_ZNAK L_ID
;
petla
: L_PETLA 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
| wyrazenie
| funkcja
;
%%
int yyerror(char* s)
{
fprintf (stderr, "%s", s);
}
Regards,
Wojtek