小编nao*_*ken的帖子

野牛YYSTYPE:尝试使用char*

我需要使用flex和bison来解析一些代码.

YYSTYPE的默认类型是int,即使我从未以这种方式声明它.这是野牛的默认值吗?

传回字符串对我有很大的帮助.我看了这个:如何解决Bison警告"......没有声明类型" 这看起来是一个很好的方法.(我不需要联盟的全部功能,只需要char*部分,但我不妨使用联盟,因为它可能会在以后有用.)

它不适合我.我收到这些错误:

y:111.37-38: $1 of `ConstExpression' has no declared type
y:113.34-35: $1 of `ConstFactor' has no declared type
y:114.35-36: $1 of `ConstFactor' has no declared type
y:119.34-35: $1 of `Type' has no declared type
y:109.23-48: warning: type clash on default action: <str> != <>
y:115.23-27: warning: type clash on default action: <str> != <>
[...more of the same snipped...]
Run Code Online (Sandbox Code Playgroud)

以下是我的y语法文件中的声明:

%union {
     char *str;
 }

%type<str> ConstExpression ConstFactor Type
Run Code Online (Sandbox Code Playgroud)

这是我.l文件中的一行: …

bison flex-lexer

5
推荐指数
1
解决办法
8017
查看次数

标签 统计

bison ×1

flex-lexer ×1