The main problem is that you are trying to include your lexer in your parser. What you (at least usually) want to do is have yacc (bison, if necessary) create a header (y.tab.h), using yacc -dand including this in your lexer.
Lexer start:
%{
#include "y.tab.h"
int yylinenu= 1;
int yycolno= 1;
%}
, , , :
extern int yylinenu;
extern int yycolno;
main() error() ( main() , , , , , ...).
void yyerror(char *msg)
{
printf("Line: %d , Column: %d : %s \n", yylinenu, yycolno, msg);
}
int main(int argc, char *argv[])
{
return yyparse();
}
, , , , , . :
|WHILE LINKEKLAMMER Cond RECHTEKLAMMER Stmt
{puts("\t\tStmt : 'PRINTF' Expr ';'");}
|PRINTF Expr SEMIKOLON
{puts("\t\tStmt : 'PRINTF' Expr ';'");}
, "while", "while", "printf":
|WHILE LINKEKLAMMER Cond RECHTEKLAMMER Stmt
{puts("\t\tStmt : 'WHILE' Expr ';'");}
, :
|IF LINKEKLAMMER Cond RECHTEKLAMMER Stmt
{puts("\t\tStmt : '(' Cond ')' Stmt");}
|IF LINKEKLAMMER Cond RECHTEKLAMMER Stmt ELSE Stmt
{puts("\t\tStmt : '(' Cond ')' Stmt 'ELSE' Stmt");}
, , , "if" :
|IF LINKEKLAMMER Cond RECHTEKLAMMER Stmt
{puts("\t\tStmt : 'IF' '(' Cond ')' Stmt");}
|IF LINKEKLAMMER Cond RECHTEKLAMMER Stmt ELSE Stmt
{puts("\t\tStmt : 'IF' '(' Cond ')' Stmt 'ELSE' Stmt");}
, :
Term:Factor {puts("\t\tTerm : Factor");}
| Factor MAL Term {puts("\t\tTerm : Factor '*' Term");}
| Factor SLASH Term {puts("\t\tTerm : Factor '/' Term");}
;
Factor:SimpleExpr {puts("\t\tFactor : SimpleExpr");}
| MINUS SimpleExpr {puts("\t\tFactor : '-' SimpleExpr");}
;
, , , ( ), . , , , - .
: : (, bison/yacc/byacc generate) , :
Stmts : Stmt {puts("\t\tStmts : Stmt");}
| Stmt Stmts {puts("\t\tStmts : Stmt Stmts");}
;
To:
Stmts : Stmt {puts("\t\tStmts : Stmt");}
| Stmts Stmt {puts("\t\tStmts : Stmts Stmt");}
;