I am having trouble making a program checker and optimiser for LBF using CUP. When I try to compile my specification using "java java_cup.Main parser.cup" I get the following
Opening files...
Parsing specification from standard input...
Checking specification...
Warning: Terminal "IMP" was declared but never used
Warning: Terminal "DIMP" was declared but never used
Building parse tables...
Computing non-terminal nullability...
Computing first sets...
Building state machine...
Filling in tables...
Checking for non-reduced productions...
*** Production "var_part ::= VAR " never reduced
*** Production "var_list ::= var_part " never reduced
*** Production "var_list ::= var_list COMMA var_part " never reduced
*** Production "function_definition ::= FUNCTION FUN_ID EQEQ expr SEMI " never r
educed
*** Production "function_definition ::= FUNCTION FUN_ID LPAREN var_list RPAREN EQEQ expr SEMI " never reduced
Writing parser...
Closing files...
------- CUP v0.10k Parser Generation Summary -------
0 errors and 7 warnings
16 terminals, 7 non-terminals, and 14 productions declared,
producing 16 unique parse states.
2 terminals declared but not used.
0 non-terminals declared but not used.
0 productions never reduced.
0 conflicts detected (0 expected).
Code written to "parser.java", and "sym.java".
---------------------------------------------------- (v0.10k)
and when I try to run my parser on a test LBF file I get an error if I hit the word "function" My CUP file is shown below
import java_cup.runtime.*;
import java.util.HashMap;
action code {:
private HashMap<String,Integer> functions; // contains functions and number of parameters.
functions=new HashMap<String,Integer>();
:}
parser code {:
public void report_error(String message, Object info) {
StringBuffer m = new StringBuffer("Error");
if (info instanceof java_cup.runtime.Symbol) {
java_cup.runtime.Symbol s = ((java_cup.runtime.Symbol) info);
if (s.left >= 0) {
m.append(" in line "+(s.left+1));
if (s.right >= 0)
m.append(", column "+(s.right+1));
}
}
m.append(" : "+message);
System.err.println(m);
}
public void report_fatal_error(String message, Object info) {
report_error(message, info);
System.exit(1);
}
:};
/* Terminals (tokens returned by the scanner). */
terminal IMP,DIMP,EQEQ,AND,OR,NEG,LPAREN,RPAREN,SEMI,COMMA,FUNCTION;
terminal Boolean BOOL_CONST;
terminal String VAR;
terminal String FUN_ID;
/* Non terminals */
non terminal Object expr_list, expr_part,function_definition,var_list,var_part;
non terminal Boolean expr;
/* Precedences */
precedence left OR;
precedence left AND;
precedence left NEG;
/* The grammar */
expr_list ::= expr_list expr_part
|
expr_part;
expr_part ::= expr:e
{: System.out.println("= " + e); :}
;
function_definition ::= FUNCTION FUN_ID:fid LPAREN var_list:vl RPAREN EQEQ expr SEMI
{: System.out.println("cup found function"); :}
|
FUNCTION FUN_ID EQEQ expr SEMI
{: System.out.println("cup found function2"); :}
;
var_list ::= var_list COMMA var_part
|
var_part
;
var_part ::= VAR
;
expr ::= expr:e1 AND expr:e2
{: if(e1.booleanValue() && e2.booleanValue()){RESULT = Boolean.TRUE;} else{RESULT = Boolean.FALSE;} :}
|
expr:e1 OR expr:e2
{: if(e1.booleanValue() || e2.booleanValue()) {RESULT=Boolean.TRUE;} else{RESULT = Boolean.FALSE;} :}
|
BOOL_CONST:b
{: RESULT = b.booleanValue(); :}
|
NEG expr:e
{: if(e.booleanValue()){RESULT =Boolean.FALSE;} else{RESULT = Boolean.TRUE;} :}
|
LPAREN expr:e RPAREN
{: RESULT = e; :}
;
any insight into how to get rid of the warnings, and how to make my CUP file work would be greatly appreciated. Thanks in advance.
Edited by: PhischPhood on Jan 6, 2008 3:17 AM