bison 相关问题

Bison是GNU解析器生成器。它生成LALR解析器,但也可以为非LALR的语法生成GLR解析器。它具有与其旧前任Yacc(另一个编译器编译器)兼容的模式。

yyparse() 未在 Bison/Flex C++ 项目中声明,仅适用于某些版本的 gcc/bison/flex

首先,我对 Bison 和 Flex 还很陌生。我知道这些工具是为在 C 中使用而设计的,而且我感觉我的所有问题都来自于在 C++ 中使用它们。我不确定我是否已经做到了...

回答 2 投票 0

在 C++ 项目中使用 flex/bison 时避免“警告 C4005: 'INT8_MIN': 宏重新定义”

我有一个使用flex/bison 的C++ 项目。 词法分析器生成的代码包括以下部分: /* C99 系统有 。非 C99 系统可能会也可能不会。 */ #如果已定义(

回答 1 投票 0

Bison 错误恢复和平衡括号

假设我们有一个文件,其中每一行都由平衡括号的字符串组成。我们可以通过将以下经典语法放入 Bison 中来认识到这一点: /* 忽略序言和词法分析器

回答 1 投票 0

如何使用我的 Bison 解析器“链接”或读取输入?

我知道解析器读取词法分析器生成的标记。我有一个使用 Flex++ 创建的工作词法分析器,它读取文本文件并将标记输出到标准输出。就解析器而言,我......

回答 1 投票 0

如何用Jflex在Bison中表达语法规则

我一直在尝试制作一个从词法分析器(jflex)获取标记的解析器,并且我使用 Java 和 bison 作为解析器。这是到目前为止我的解析器代码: %define api.prefix {示例} %定义API。

回答 1 投票 0

解决解析带有可选参数的AgeSQL子句时的reduce/reduce冲突

我正在开发一个项目,以在 Postgres psql 上添加对 Cypher 子句的支持。我正在尝试提高解析器性能,解决规则之间的冲突。我创建了一个最小的示例

回答 1 投票 0

结合flex和bison进行文件解析

所以我在 flex/bison 中有这个程序。 我的两个问题是: 1)我不知道如何让它适用于文件输入,因为我的大学练习需要它使用文件。 我尝试使用 iostream 库...

回答 1 投票 0

Bison %nonassoc vs %token?

我读了很多资料,但还是不明白:%nonassoc 和 %token 之间有什么区别? 我理解 %left 和 %right 之间的区别,但对我来说前两个听起来是一样的......

回答 2 投票 0

在 Flex/Bison 中如何处理这种情况下的优先级

我正在做一些工作来解析我们项目中的内部配置文件。配置可以是一个简单的字符串,也可以是我们为内部使用而创建的“函数”。函数...

回答 1 投票 0

Bison 语义谓词语法错误,杂散的'#'

我正在尝试使用 Bison 的语义谓词功能,但在尝试让它工作时遇到了一些问题。 当我尝试使用 GCC 编译生成的 .tab.c 文件时出现问题。我是

回答 1 投票 0

filename.tab.c 和 filename.tab.h 不使用 Flex Bison 生成计算器程序

所以我是 Flex Bison 的新手。我正在尝试实现一个包含 (,),+,-,*,/ 的计算器程序。我创建了两个文件,.l 和 .y 这里的问题是它没有生成 ...

回答 0 投票 0

用于嵌入式裸机系统的 flex/bison

我为 Cortex M 开发软件,为此我使用 Arm GNU 工具链。 我需要解析我有语法的数据包。 不过我对 flex 有问题,因为它通常需要 l...

回答 1 投票 0

返回Bison中第一个表达式的值

我正在用 Bison 和 flex 编写解析器来解析“自制”语言。该语言包含以下类型的某些常量表达式: [运算符、操作数 1、操作数 2] 其中操作数 c ...

回答 0 投票 0

如何在 Bison 中释放 yyptr 堆栈?

我正在使用 Bison 生成解析器,词法分析器是用 Ragel 编写的。当我用 Valgrind 运行我的代码时,它给了我这个输出: 2个块中的200,014个字节肯定丢失在丢失记录中 139,4 ...

回答 0 投票 0

为什么我编译mysql,cmake找不到bison

这里输入图片描述我在windows下尝试用cmake编译mysql,发现cmake找不到bison,我把bison可执行文件添加到系统环境变量中,我试...

回答 0 投票 0

'int'之前的预期不合格ID

我在任何声明中都遇到了这个错误,比如 $$ = 新向量 例如: parser.y:109:29: 错误:'int' 之前应有不合格的 id 109 | stmts : stmt TSEMIC {$$ = 新向量 我在任何声明中都遇到了这个错误 $$ = new vector<int> 如: parser.y:109:29: error: expected unqualified-id before ‘int’ 109 | stmts : stmt TSEMIC {$$ = new vector<int>; *$$ = $1;} | ^~~ parser.y:109:29: error: expected ‘)’ before ‘int’ 109 | stmts : stmt TSEMIC {$$ = new vector<int>; *$$ = $1;} | ~ ^~~ | ) parser.y:109:61: error: expected unqualified-id before ‘int’ 109 | stmts : stmt TSEMIC {$$ = new vector<int>; *$$ = $1;} | ^ parser.y:109:61: error: expected ‘)’ before ‘int’ 109 | stmts : stmt TSEMIC {$$ = new vector<int>; *$$ = $1;} | 编译后找不到原因,这里是 .y 文件,只有语法部分会产生错误。 %define parse.error verbose %{ #include <stdio.h> #include <iostream> #include <vector> #include <string> using namespace std; extern int yylex(); extern int yylineno; extern char *yytext; extern int yyerrornum; void yyerror (const char *msg) { cout << "line " << yylineno <<": " << msg << " at token " << yytext << endl ; yyerrornum++; } #include "Codigo.hpp" #include "Exp.hpp" expresionstruct makecomparison(std::string &s1, std::string &s2, std::string &s3) ; expresionstruct makearithmetic(std::string &s1, std::string &s2, std::string &s3) ; // Añado la declaración de la función unir. Si la hacéis diferente, debéis cambiar esta declaración. vector<int> unir(vector<int> lis1, vector<int> lis2); Codigo codigo; %} /* qué atributos tienen los símbolos */ %union { string *str ; vector<string> *list ; expresionstruct *expr ; int number ; vector<int> *numlist; } /* declaración de tokens. Esto debe coincidir con tokens.l */ %token <str> TIDENTIFIER TINTEGER TDOUBLE %token <str> TCEQ TCNE TCLT TCLE TCGT TCGE TEQUAL %token <str> TLPAREN TRPAREN TLBRACE TRBRACE TCOMMA TDOT %token <str> TPLUS TMINUS TMUL TDIV %token <str> TCOLON TSEMIC TASSIG %token <str> RPROGRAM RIS RBEGIN RENDPROGRAM RVAR RINTEGER RFLOAT RENDPROCEDURE RPROCEDURE RIN ROUT RIF RTHEN RELSE RENDIF RGET RPUT_LINE RDO RWHILE RENDWHILE REXIT /* declaración de símbolos no terminales con atributos */ %type <str> ident %type <str> numeric %type <expr> expr %type <number> M %type <numlist> N %type <int> stmt %type <int> stmts //Falta declarar stmt stmts %left TASSIG %left TCEQ TCNE TCLT TCLE TCGT TCGE TEQUAL %left TPLUS TMINUS %left TMUL TDIV %start program %% program : RPROGRAM { codigo.anadirInstruccion("prog" ) ;} ident RIS decls RBEGIN stmts RENDPROGRAM TSEMIC { codigo.anadirInstruccion("halt"); codigo.escribir() ; } ; decls : RVAR list TCOLON type TSEMIC decls |%empty ; type : RFLOAT | RINTEGER ; list : ident | list TCOMMA ident ; stmts : stmt TSEMIC {$$ = new vector<int>; *$$ = $1;} | stmts stmt TSEMIC {$$ = new vector<int>; *$$ = unir($1,$2);} ; vector<int> unir(vector<int> lis1, vector<int> lis2){ vector<int> res; res = lis1; res.insert(res.end(), lis2.begin(), lis2.end()); return res; } 这是 .cpp 部分: #include "Codigo.hpp" using namespace std; /****************/ /* Constructora */ /****************/ Codigo::Codigo() { siguienteId = 1; } /***********/ /* nuevoId */ /***********/ string Codigo::nuevoId() { string nId("__t"); nId += to_string(siguienteId++); return nId; } /*********************/ /* anadirInstruccion */ /*********************/ void Codigo::anadirInstruccion(const string &instruccion) { string cadena; cadena = to_string(obtenRef()) + ": " + instruccion; instrucciones.push_back(cadena); } /***********************/ /* anadirDeclaraciones */ /***********************/ void Codigo::anadirDeclaraciones(const vector<string> &idNombres, const string &tipoNombre) { vector<string>::const_iterator iter; for (iter=idNombres.begin(); iter!=idNombres.end(); iter++) { anadirInstruccion(tipoNombre + " " + *iter ); } } /*********************/ /* anadirParametros */ /*********************/ void Codigo::anadirParametros(const vector<string> &idNombres, const string &tipoNombre) { vector<string>::const_iterator iter; for (iter=idNombres.begin(); iter!=idNombres.end(); iter++) { anadirInstruccion("param_" + tipoNombre + " " + *iter ); } } /**************************/ /* completarInstrucciones */ /**************************/ void Codigo::completarInstrucciones(vector<int> &numInstrucciones, const int valor) { string referencia = " " + to_string(valor) ; vector<int>::iterator iter; for (iter = numInstrucciones.begin(); iter != numInstrucciones.end(); iter++) { instrucciones[*iter-1].append(referencia); } } /************/ /* escribir */ /************/ void Codigo::escribir() const { vector<string>::const_iterator iter; for (iter = instrucciones.begin(); iter != instrucciones.end(); iter++) { cout << *iter << " ;" << endl; } } /************/ /* obtenRef */ /************/ int Codigo::obtenRef() const { return instrucciones.size() + 1; } 还有.hpp #ifndef CODIGO_HPP_ #define CODIGO_HPP_ #include <iostream> #include <sstream> #include <fstream> #include <set> #include <vector> /* Estructura de datos para el código generado. El código, en vez de escribirlo directamente, * se guarda en esta estructura y, al final, se escribirán en un fichero. */ class Codigo { private: /**************************/ /* REPRESENTACION INTERNA */ /**************************/ /* Instrucciones que forman el código. */ std::vector<std::string> instrucciones; /* Clave para generar identificaciones nuevos. Cada vez que se crea un idse incrementa. */ int siguienteId; public: /************************************/ /* METODOS PARA GESTIONAR EL CODIGO */ /************************************/ /* Constructora */ Codigo(); /* Crea un nuevo identificador del tipo "__t1, __t2, ...", siempre diferente. */ std::string nuevoId() ; /* Añade una nueva instrucción a la estructura. */ void anadirInstruccion(const std::string &instruccion); /* Dada una lista de variables y su tipo, crea y añade las instrucciones de declaración */ void anadirDeclaraciones(const std::vector<std::string> &idNombres, const std::string &tipoNombre); /* Dada una lista de parámetros y su tipo, crea y añade las instrucciones de declaración */ void anadirParametros(const std::vector<std::string> &idNombres, const std::string &tipoNombre) ; /* Añade a las instrucciones que se especifican la referencia que les falta. * Por ejemplo: "goto" => "goto 20;" */ void completarInstrucciones(std::vector<int> &numInstrucciones, const int valor); /* Escribe las instrucciones acumuladas en la estructura en el fichero de salida. */ void escribir() const; /* Devuelve el número de la siguiente instrucción. */ int obtenRef() const; }; #endif /* CODIGO_HPP_ */ 所有定义都在这段代码中,令牌、函数定义在其他档案中,在那里找不到任何问题,我猜是一些错误的声明,但这是我第一次在使用相同的声明编译代码后得到这个错误没有出现这个错误。 因为我是新用户,我不能写评论。 但是,最后一个语法规则和附加代码之间缺少%% 应该是这样的: stmts : stmt TSEMIC {$$ = new vector<int>; *$$ = $1;} | stmts stmt TSEMIC {$$ = new vector<int>; *$$ = unir($1,$2);} ; %% vector<int> unir(vector<int> lis1, vector<int> lis2){ vector<int> res; res = lis1; res.insert(res.end(), lis2.begin(), lis2.end()); return res; }

回答 1 投票 0

yacc - 字段类型不完整

yacc 似乎不喜欢我的标记属于我定义的类型。 在语法 (.y) 文件顶部的 %{ ... %} 块中,我包含了一个定义以下结构的头文件: 类型定义

回答 2 投票 0

Flex 和 Bison:用简单的语法面对错误

我总是面临如下语法错误。 错误:语法错误行:1 at word * Bison/Flex 代码如下。 %关键字实体“实体” %关键字是“是” %% 程序 ...

回答 0 投票 0

我如何在 GNU Bison 项目中创建新问题?

我如何在 GNU Bison 项目中创建新问题? 我已经调查了 https://www.gnu.org/software/bison/,并且 http://savannah.gnu.org/projects/bison/ 在 http://savannah.gnu.org/projects/bison/ - ...

回答 0 投票 0

Bison 和 Flex 在编译和执行过程中的语法问题

我目前正在从事一个项目,该项目包括使用 Bison 和 Flex 解析代表机票的文本文件的内容。我创建了两个文件,ticket.y 和 ticket.l,来定义 g...

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.