When I try to execute the CUP command to parse the CUP file, it always throws the following error:
Error: Syntax error @ Symbol: EOF
Error : Internal error: Unexpected exception
Error: Syntax error @ Symbol: EOF
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "java.lang.Class.getFields()" because the return value of "java_cup.runtime.lr_parser.getSymbolContainer()" is null
Error : Internal error: Unexpected exception
at java_cup.runtime.lr_parser.symbl_name_from_id(lr_parser.java:456)
at java_cup.runtime.lr_parser.report_expected_token_ids(lr_parser.java:446)
at java_cup.runtime.lr_parser.syntax_error(lr_parser.java:433)
at java_cup.runtime.lr_parser.parse(lr_parser.java:725)
at java_cup.Main.parse_grammar_spec(Main.java:496)
at java_cup.Main.main(Main.java:196)
The content of my CUP file is using the example code from the official website:
// CUP specification for a simple expression evaluator (no actions)
import java_cup.runtime.*;
/* Preliminaries to set up and use the scanner. */
init with {: scanner.init(); :};
scan with {: return scanner.next_token(); :};
/* Terminals (tokens returned by the scanner). */
terminal SEMI, PLUS, MINUS, TIMES, DIVIDE, MOD;
terminal UMINUS, LPAREN, RPAREN;
terminal Integer NUMBER;
/* Non terminals */
non terminal expr_list, expr_part;
non terminal Integer expr, term, factor;
/* Precedences */
precedence left PLUS, MINUS;
precedence left TIMES, DIVIDE, MOD;
precedence left UMINUS;
/* The grammar */
expr_list ::= expr_list expr_part |
expr_part;
expr_part ::= expr SEMI;
expr ::= expr PLUS expr
| expr MINUS expr
| expr TIMES expr
| expr DIVIDE expr
| expr MOD expr
| MINUS expr %prec UMINUS
| LPAREN expr RPAREN
| NUMBER
;
Here’s my environment setup:
I want to know what's going on and how to fix it.
I figured out the problem. The command worked fine when I ran it manually, and I eventually discovered that my automation script omitted the path to the cup file when passing the parameters.