[英]Javacc: was expecting one of string literal
I am a bit new to javacc.我对 javacc 有点陌生。 Could someone please explain me why I keep getting this error.有人可以解释一下为什么我不断收到此错误。 Is it not the right way to write the grammar?这不是写语法的正确方法吗?
I keep getting this error despite writing the right grammar.尽管编写了正确的语法,但我仍然收到此错误。
following is my code:以下是我的代码:
options {
Static = false ;
}
PARSER_BEGIN(Adder)
class Adder {
static void main(String[] args) throws ParseException, TokeMgrError {
Adder parser = new Adder(System.in);
parser.Start;
}
}
PARSER_END(Adder)
SKIP :{
” ”
| ”\n”
| ”\r”
| ”\r\n”}
TOKEN :{<PLUS : ”+”>}
TOKEN :{<NUMBER : ([”0”-”9”])+>}
void Start() :
{}
{
<NUMBER>
(
<PLUS>
<NUMBER>
)*
<EOF>6
this is the error I get:这是我得到的错误:
C:\Users\musta>java -cp C:\javacc-6.0\bin\lib\javacc.jar javacc adder.jj
Java Compiler Compiler Version 6.0_1 (Parser Generator)
(type "javacc" with no arguments for help)
Reading from file adder.jj . . .
org.javacc.parser.ParseException: Encountered " <IDENTIFIER> "\u00e2\u20ac "" at line 14, column 9.
Was expecting one of:
<STRING_LITERAL> ...
"<" ...
Detected 1 errors and 0 warnings.
String literals can only start with normal ASCII quotes ( "
) not "pretty" unicode quotes ( ”
). So it doesn't recognize your string literals as such and instead recognizes them as identifiers. Since identifiers aren't allowed in these places, you get this error message.字符串文字只能以普通的 ASCII 引号 ( "
) 开头,而不是“漂亮的”unicode 引号 ( ”
)。因此,它不会识别您的字符串文字,而是将它们识别为标识符。由于这些地方不允许使用标识符,您收到此错误消息。
So replace your quotes with plain ASCII quotes and the error will go away.所以用普通的 ASCII 引号替换你的引号,错误就会消失。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.