Доброго времени суток. Не так давно изучаю bison и flex, поэтому нужна помощь. Есть задача описать входной язык Lua. Нашёл всю грамматику тут https://lua.org.ru/contents_ru.html. При сборке возникает ошибка, которую я никак не могу решить, помогите решить эту проблему. Собираю так: bison -d имя файла.y flex имя файла.l g++ -o имя lex.yy.c y.tab.c
Bison файл
%{
#include <iostream>
#include <string>
using namespace std;
void yyerror(char const* msg);
extern FILE *yyin;
int yylex();
%}
%union{
std::string* stringVal;
}
%verbose
%token <stringVal> LTOE GTOE TILDEEQUAL DEQUAL DSLASH DLESS DGREATER DPOINT TPOINT
%token <stringVal> NOT NIL FALSE TRUE RETURN
%token <stringVal> OR AND WHILE REPEAT UNTIL IF THEN ELSE ELSEIF
%token <stringVal> FOR IN FUNCTION LOCAL DO END GOTO BREAK DCOLON
%token <stringVal> NAME STRING STRINGG
%token INT HEX FLOAT
%left OR
%left AND
%left '<' '>' LTOE GTOE TILDEEQUAL DEQUAL
%left '|'
%left '~'
%left '&'
%left DLESS DGREATER
%right DPOINT
%left '+' '-'
%left '*' '/' '%' DSLASH
%left '#' NOT
%left UNARY
%right '^'
%start chunk
%%
chunk : block
;
block : stat | stat retstat
;
stat : /*empty*/
| stat ';'
| stat varlist '=' explist
| stat functioncall
| stat label
| stat BREAK
| stat GOTO NAME
| stat DO block END
| stat WHILE exp DO block END
| stat REPEAT block UNTIL exp
| stat IF exp THEN block statelseif elseblock END
| stat FOR NAME '=' exp ',' exp exz DO block END
| stat FOR namelist IN explist DO block END
| stat FUNCTION funcname funcbody
| stat LOCAL FUNCTION NAME funcbody
| stat LOCAL namelist
| stat LOCAL namelist '=' explist
;
statelseif: /*('elseif' exp 'then' block)* */
/*empty*/
| statelseif ELSEIF exp THEN block
;
exz
: /*empty*/
| ',' exp
;
elseblock
: /*empty*/
| ELSE block
;
retstat
: RETURN | RETURN explist | RETURN ';'
;
label : DCOLON NAME DCOLON
funcname
: NAME np
| NAME np ':' NAME
;
np
: /*empty*/
| np '.' NAME
;
varlist
: var |varlist ',' var
;
var : NAME | prefixexp '[' exp ']' | prefixexp '.' NAME
namelist
: NAME
| namelist ',' NAME
;
explist
: exp
| explist ',' exp
;
exp : NIL | FALSE | TRUE
| number
| string
| TPOINT
| functiondef
| prefixexp
| tableconstructor
| exp '^' exp
| NOT exp
| '#' exp
| exp '*' exp
| exp '/' exp
| exp '%' exp
| exp DSLASH exp
| exp '+' exp
| exp '-' exp
| exp DPOINT exp
| exp '<' exp
| exp '>' exp
| exp LTOE exp
| exp GTOE exp
| exp TILDEEQUAL exp
| exp DEQUAL exp
| exp AND exp
| exp OR exp
| exp '&' exp
| exp '|' exp
| exp '~' exp
| exp DLESS exp
| exp DGREATER exp
| '-' exp %prec UNARY
| '~' exp %prec UNARY
;
prefixexp : var | functioncall | '(' exp ')'
functioncall : prefixexp args | prefixexp ':' NAME args
args: '('/*empty*/')'
| '(' explist ')'
| tableconstructor
| string
;
functiondef : FUNCTION funcbody
funcbody: '('/*empty*/')' block END
| '('parlist')' block END
parlist: namelist
| namelist ',' TPOINT
| namelist TPOINT
;
tableconstructor: '{'/*empty*/'}'
| '{' fieldlist '}'
;
fieldlist: field fieldlistREP
| field fieldlistREP fieldsep
;
fieldlistREP: /*empty*/
| fieldlistREP fieldsep field
;
field : '[' exp ']' '=' exp | NAME '=' exp | exp
fieldsep : ',' | ';'
number
: INT | HEX | FLOAT
;
string
: STRING | STRINGG
;
%%
void yyerror(char const* msg) {}
int main() {
yyin = fopen("bisontest.txt", "r");
//yyparse();
if (yyparse() == 0) {
cout << "Success" << endl;
} else {
cout << "Syntax error" << endl;
}
return 0;
}
flex файл
%option noyywrap yylineno
%{
#include <stdlib.h>
#include <stdio.h>
#include <string>
#include "bisondoc.tab.h"
using namespace std;
void showError();
int ch;
%}
%%
[ \t\r\n]+ { /* игнорируем пробелы, табы и переносы строк */ }
"(" {return 40;}
")" {return 41;}
"[" {return 91;}
"]" {return 93;}
"{" {return 123;}
"}" {return 125;}
"<" {return 60;}
">" {return 62;}
"," {return 44;}
"." {return 46;}
"+" {return 43;}
"-" {return 45;}
"*" {return 42;}
"/" {return 47;}
"=" {return 61;}
":" {return 58;}
";" {return 59;}
"%" {return 37;}
"&" {return 38;}
"|" {return 124;}
"~" {return 126;}
"#" {return 35;}
"^" {return 94;}
["] {return 34;}
"'" {return 39;}
"\\" {return 92;}
"<=" {yylval.stringVal = new std::string(yytext, yyleng); return (LTOE);}
">=" {yylval.stringVal = new std::string(yytext, yyleng); return (GTOE);}
"~=" {yylval.stringVal = new std::string(yytext, yyleng); return (TILDEEQUAL);}
"==" {yylval.stringVal = new std::string(yytext, yyleng); return (DEQUAL);}
"//" {yylval.stringVal = new std::string(yytext, yyleng); return (DSLASH);}
"<<" {yylval.stringVal = new std::string(yytext, yyleng); return (DLESS);}
">>" {yylval.stringVal = new std::string(yytext, yyleng); return (DGREATER);}
".." {yylval.stringVal = new std::string(yytext, yyleng); return (DPOINT);}
"..." {yylval.stringVal = new std::string(yytext, yyleng); return (TPOINT);}
"not" {yylval.stringVal = new std::string(yytext, yyleng); return (NOT);}
"nil" {yylval.stringVal = new std::string(yytext, yyleng); return (NIL);}
"false" {yylval.stringVal = new std::string(yytext, yyleng); return (FALSE);}
"true" {yylval.stringVal = new std::string(yytext, yyleng); return (TRUE);}
"return" {yylval.stringVal = new std::string(yytext, yyleng); return (RETURN);}
"or" {yylval.stringVal = new std::string(yytext, yyleng); return (OR);}
"and" {yylval.stringVal = new std::string(yytext, yyleng); return (AND);}
"while" {yylval.stringVal = new std::string(yytext, yyleng); return (WHILE);}
"repeat" {yylval.stringVal = new std::string(yytext, yyleng); return (REPEAT);}
"until" {yylval.stringVal = new std::string(yytext, yyleng); return (UNTIL);}
"if" {yylval.stringVal = new std::string(yytext, yyleng); return (IF);}
"then" {yylval.stringVal = new std::string(yytext, yyleng); return (THEN);}
"else" {yylval.stringVal = new std::string(yytext, yyleng); return (ELSE);}
"elseif" {yylval.stringVal = new std::string(yytext, yyleng); return (ELSEIF);}
"for" {yylval.stringVal = new std::string(yytext, yyleng); return (FOR);}
"in" {yylval.stringVal = new std::string(yytext, yyleng); return (IN);}
"function" {yylval.stringVal = new std::string(yytext, yyleng); return (FUNCTION);}
"local" {yylval.stringVal = new std::string(yytext, yyleng); return (LOCAL);}
"do" {yylval.stringVal = new std::string(yytext, yyleng); return (DO);}
"end" {yylval.stringVal = new std::string(yytext, yyleng); return (END);}
"goto" {yylval.stringVal = new std::string(yytext, yyleng); return (GOTO);}
"break" {yylval.stringVal = new std::string(yytext, yyleng); return (BREAK);}
"::" {yylval.stringVal = new std::string(yytext, yyleng); return (DCOLON);}
[a-zA-Z_][a-zA-Z_0-9]* {yylval.stringVal = new std::string(yytext, yyleng); return (NAME);}
\"[ -~]*\" {yylval.stringVal = new std::string(yytext, yyleng); return (STRING);}
\'[ -~]*\' {yylval.stringVal = new std::string(yytext, yyleng); return (STRINGG);}
[0-9]+ {return (INT);}
0[xX][0-9a-fA-F]+ {return (HEX);}
([0-9]*\.[0-9]+|[0-9]+\.) {return (FLOAT);}
. {showError(); return 0;}
%%
void showError(){
printf("Other input\n");
}