- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在用 flex 和 bison 构建一个编译器。问题是使用 char *
会带来很多问题,所以我正在尝试将所有内容迁移到 string
。
剩下的唯一问题是有一个带有字符串的union
。我知道这不是一个标准,但是使用指针应该没有问题。
相关代码:
#include <string>
using namespace std;
//-- SYMBOL SEMANTIC VALUES -----------------------------
%union {
struct lc{
string * code;
string * start;
string * verdadero;
string * falso;
string * next;
}code;
}
奇怪的是我收到的错误:
file.ypp:39:6: error: ‘string’ does not name a type
string * start;
file.ypp:40:6: error: ‘string’ does not name a type
string * verdadero;
file.ypp:41:6: error: ‘string’ does not name a type
string * falso;
file.ypp:42:6: error: ‘string’ does not name a type
string * next;
编辑:忘记提到在 union
中使用 std::string
有同样的问题
最佳答案
问题是 %{
中的代码... %}
仅包含 y.tab.c
Bison 生成的文件。它不包含在 y.tab.h
中文件。 %union
另一方面,代码包含在 y.tab.h
中(它是 YYSTYPE
定义的一部分)。所以如果你的 %union
取决于其他声明,只需将这些声明(或 #include
)放在 %{
中... %}
并不总是有效。
相反,您需要手动确保这些声明始终发生在之前您
#include "y.tab.h"
在任何其他文件中——任何你有#include "y.tab.h"
的地方确保
你有#include <string>
(和 using
如果你真的想要的话)在
#include "y.tab.h"
之前线。将它全部放在您包含的另一个头文件中是一个不错的选择。
或者,对于 bison(但不是 yacc),您可以使用 %code requires {
... }
在 .y
的第一部分文件。此类 block 中的任何内容都将被逐字复制到 both y.tab.h
中和 y.tab.c
文件。
关于C++:字符串和 union Bison ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23633928/
我有一个使用 Yacc 编写的语法。语法的相关部分摘录在这里 postfix : primary | postfix '[' expr ']' | postfix '[' ex
如何在 bison/yacc 中使用继承的属性? 说,我有这样的语法 - 程序 -> stmts 我想做的是在 Bison 身上: 程序:stmts {$$.next = newLabel(); $1
有什么方法可以更改 Bison 错误消息的格式?例如,不要说 syntax error, unexpected T_ID, expected ';' or T_IMPORT说 unexpected i
我的语法有这两个标记声明: %token RP %token ELSE 而这两条规则: Statement : IF LP Exp RP Statement; Statement : IF LP
如果有一个表单的输入文件: BEGIN stuff.... END BEGIN stuff ... END 我的 .y 文件是这样的 %token BEGIN %token END %star
我希望为现有语言创建一个 JavaScript 解析器,该语言目前具有笨拙的“手工制作”C# 和 Java 解析器。我想使用 Jison,并且也一直在尝试学习 Bison 的基础知识。 我不确定如何回
目前我正在研究一个源到源编译器,我已经编写了一个野牛解析器,可以正确地为输入创建 AST。我现在需要对语法树进行多次转换,因此我需要向树中插入许多节点。 我可以手动创建所有要添加到语法树中的结构体/联
如果有一个表单的输入文件: BEGIN stuff.... END BEGIN stuff ... END 我的 .y 文件是这样的 %token BEGIN %token END %star
我正在寻找为现有语言创建 JavaScript 解析器的方法,该语言目前具有笨拙的“手工制作”C# 和 Java 解析器。想用Jison,也在努力学习Bison的基础。 一个我不确定如何回答的问题是
我正在使用 flex/bison 编写解析器(我可以用 Python 编写解析器,但我总是更喜欢经典。) 当我用这个编译代码时: gcc -lfl -ly chance.tab.c lex.yy.c
正在使用 flex/bison 开发编译器。我的构建输出中有此警告。 警告:在默认操作中键入冲突 ('s' '') 请问有什么帮助吗? 最佳答案 它似乎与源中的 %token 和 %type 声明有关
考虑这个 lex.l 文件: %{ #include "y.tab.h" %} digit [0-9] letter [a-zA-Z] %% "+"
我正在为 bison 中的一个简单的 Pascal 编译器编写语法,我想可视化我在 pascal.y 中指定的语法的解析树。是否可以基于我的 pascal.y 文件以图形方式显示语法树? 最佳答案 野
我正在尝试编写一个能够使用以下输入的语法: begin #this is a example x = 56; while x > 0 do begin point 15
我正在尝试使用 BNF 语法编写 Flex/Bison 文件。但是,当我尝试编译时出现错误,而且我不确定如何调试它们。 BNF语法: ::= | head() ::=:: | @ | tail() |
我正在用 Flex/Bison 编写一个小程序来标记/解析我创建的查询语言。 我想知道是否有任何方法可以在 Flex/Bison 中创建任何关键字。 我的意思是:flex 将输入分解成一个标记列表,但
我正在尝试使用 flex 和 bison 创建过滤器,因为我想从复杂的语言中获取某些语法元素。我的计划是使用 flex + bison 来识别语法,并转储出感兴趣元素的位置。 (然后使用脚本根据转储的
我正在尝试实现一个可以进行浮点运算的 Flex/bison 计算器。我的 Flex 代码如下所示 %{ #include "calc.tab.h" #include void yyerror(cha
我正在尝试使用 FLEX 和 BISON 进行一些练习。 这是我写的代码: calc_pol.y %{ #define YYSTYPE double #include "calc_pol.tab.h"
我有一个使用括号和方括号作为分隔符的语法。当由 bison 生成的解析器输入带有不平衡分隔符的输入时,传递给 yyerror 的 YYLTYPE* 中的错误位置是输入的结尾。所以,例如,在输入 x
我是一名优秀的程序员,十分优秀!