简体   繁体   中英

Javacc: was expecting one of string literal

I am a bit new to 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.

So replace your quotes with plain ASCII quotes and the error will go away.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM