bisonc++ - 没有生产规则?
bisonc++ - No production rules?
我正在尝试使用 bisonc++ 编译以下内容:
%baseclass-preinclude <iostream>
%lsp-needed
%token NUMBER COMMENT KEYWORD VARIABLE LOGICAND LOGICOR LOGICEQUALS DOUBLELESSER
%token DOUBLEGREATER MOD LESSER GREATER OPEN CLOSE NEGATE CURLYOPEN CURLYCLOSE SEMICOLON
%left EQUALS
%left PLUS MINUS
%left TIMES
%left DIVISION
%%
start:
expressions
{
std::cout << "start -> expressions" << std::endl;
}
;
expressions:
// empty
{
std::cout << "expressions -> epsylon" << std::endl;
}
|
exp expressions
{
std::cout << "expressions -> exp expressions" << std::endl;
}
;
exp:
NUMBER
{
std::cout << "exp -> NUMBER" << std::endl;
}
|
COMMENT
{
std::cout << "exp -> COMMENT" << std::endl;
}
|
exp LOGICAND exp
{
std::cout << "exp -> exp LOGICAND exp" << std::endl;
}
|
exp LOGICOR exp
{
std::cout << "exp -> exp LOGICOR exp" << std::endl;
}
|
exp LOGICEQUALS exp
{
std::cout << "exp -> exp LOGICEQUALS exp" << std::endl;
}
|
exp DOUBLELESSER exp
{
std::cout << "exp -> exp DOUBLELESSER exp" << std::endl;
}
|
exp DOUBLEGREATER exp
{
std::cout << "exp -> exp DOUBLEGREATER exp" << std::endl;
}
|
exp PLUS exp
{
std::cout << "exp -> exp PLUS exp" << std::endl;
}
|
exp MINUS exp
{
std::cout << "exp -> exp MINUS exp" << std::endl;
}
|
exp TIMES exp
{
std::cout << "exp -> exp EQUAL exp" << std::endl;
}
|
exp EQUAL exp
{
std::cout << "exp -> exp EQUAL exp" << std::endl;
}
|
exp DIVISION exp
{
std::cout << "exp -> exp DIVISION exp" << std::endl;
}
|
exp MOD exp
{
std::cout << "exp -> exp MOD exp" << std::endl;
}
|
exp LESSER exp
{
std::cout << "exp -> exp LESSER exp" << std::endl;
}
|
exp GREATER exp
{
std::cout << "exp -> exp GREATER exp" << std::endl;
}
|
OPEN exp CLOSE
{
std::cout << "exp -> OPEN exp CLOSE" << std::endl;
}
|
NEGATE exp
{
std::cout << "exp -> NEGATE exp" << std::endl;
}
|
CURLYOPEN exp CURLYCLOSE
{
std::cout << "exp -> CURLYOPEN exp CURLYCLOSE" << std::endl;
}
|
exp SEMICOLON
{
std::cout << "exp -> SEMICOLON" << std::endl;
}
|
KEYWORD VARIABLE SEMICOLON
{
std::cout << "exp -> KEYWORD VARIABLE SEMICOLON" << std::endl;
}
;
但是,它一直返回错误
') encountered.1] Line 1: unrecognized input (`
': identifier or character-constant expected.
[bead.y: fatal] Line 23: No production rules
134950080
我显然有一些生产规则,但不知道我做错了什么。我从另一个工作示例中复制了大部分代码,并根据自己的喜好对其进行了修改。怎么了?
我遇到了同样的问题,我的老师向我展示了一些 windows 编辑器在您的文件中创建了不可见的垃圾,因此请使用终端编辑您的文件。
- 微微yourfile.y
- 在第一行之前按 Enter,然后将其删除。
- 保存
就是这样!
您的文件不符合 UNIX(calculate.l 和 calculate.y)
如果您在 Windows 上操作并使用 Nodepad++,只需执行以下操作:
- Edit/EOL conversion/UNIX 格式
- Encoding/Convert 将您的文件转换为无 BOM 的 UTF-8
- 保存并使用 flex 和 bisonc++ 重新编译
希望对您有所帮助
我正在尝试使用 bisonc++ 编译以下内容:
%baseclass-preinclude <iostream>
%lsp-needed
%token NUMBER COMMENT KEYWORD VARIABLE LOGICAND LOGICOR LOGICEQUALS DOUBLELESSER
%token DOUBLEGREATER MOD LESSER GREATER OPEN CLOSE NEGATE CURLYOPEN CURLYCLOSE SEMICOLON
%left EQUALS
%left PLUS MINUS
%left TIMES
%left DIVISION
%%
start:
expressions
{
std::cout << "start -> expressions" << std::endl;
}
;
expressions:
// empty
{
std::cout << "expressions -> epsylon" << std::endl;
}
|
exp expressions
{
std::cout << "expressions -> exp expressions" << std::endl;
}
;
exp:
NUMBER
{
std::cout << "exp -> NUMBER" << std::endl;
}
|
COMMENT
{
std::cout << "exp -> COMMENT" << std::endl;
}
|
exp LOGICAND exp
{
std::cout << "exp -> exp LOGICAND exp" << std::endl;
}
|
exp LOGICOR exp
{
std::cout << "exp -> exp LOGICOR exp" << std::endl;
}
|
exp LOGICEQUALS exp
{
std::cout << "exp -> exp LOGICEQUALS exp" << std::endl;
}
|
exp DOUBLELESSER exp
{
std::cout << "exp -> exp DOUBLELESSER exp" << std::endl;
}
|
exp DOUBLEGREATER exp
{
std::cout << "exp -> exp DOUBLEGREATER exp" << std::endl;
}
|
exp PLUS exp
{
std::cout << "exp -> exp PLUS exp" << std::endl;
}
|
exp MINUS exp
{
std::cout << "exp -> exp MINUS exp" << std::endl;
}
|
exp TIMES exp
{
std::cout << "exp -> exp EQUAL exp" << std::endl;
}
|
exp EQUAL exp
{
std::cout << "exp -> exp EQUAL exp" << std::endl;
}
|
exp DIVISION exp
{
std::cout << "exp -> exp DIVISION exp" << std::endl;
}
|
exp MOD exp
{
std::cout << "exp -> exp MOD exp" << std::endl;
}
|
exp LESSER exp
{
std::cout << "exp -> exp LESSER exp" << std::endl;
}
|
exp GREATER exp
{
std::cout << "exp -> exp GREATER exp" << std::endl;
}
|
OPEN exp CLOSE
{
std::cout << "exp -> OPEN exp CLOSE" << std::endl;
}
|
NEGATE exp
{
std::cout << "exp -> NEGATE exp" << std::endl;
}
|
CURLYOPEN exp CURLYCLOSE
{
std::cout << "exp -> CURLYOPEN exp CURLYCLOSE" << std::endl;
}
|
exp SEMICOLON
{
std::cout << "exp -> SEMICOLON" << std::endl;
}
|
KEYWORD VARIABLE SEMICOLON
{
std::cout << "exp -> KEYWORD VARIABLE SEMICOLON" << std::endl;
}
;
但是,它一直返回错误
') encountered.1] Line 1: unrecognized input (`
': identifier or character-constant expected.
[bead.y: fatal] Line 23: No production rules
134950080
我显然有一些生产规则,但不知道我做错了什么。我从另一个工作示例中复制了大部分代码,并根据自己的喜好对其进行了修改。怎么了?
我遇到了同样的问题,我的老师向我展示了一些 windows 编辑器在您的文件中创建了不可见的垃圾,因此请使用终端编辑您的文件。
- 微微yourfile.y
- 在第一行之前按 Enter,然后将其删除。
- 保存
就是这样!
您的文件不符合 UNIX(calculate.l 和 calculate.y) 如果您在 Windows 上操作并使用 Nodepad++,只需执行以下操作:
- Edit/EOL conversion/UNIX 格式
- Encoding/Convert 将您的文件转换为无 BOM 的 UTF-8
- 保存并使用 flex 和 bisonc++ 重新编译
希望对您有所帮助