When I went to generate a grammar for walking the AST for the expression
evaluation I got the following pop-up message:
"cannot find tokens file <unset-dir>\Expr.tokens
Consult the console for more information."
The console is empty. I tell ANTLRWorks to write generated files to a
directory /generated, a child of the directory where I store grammars. The
Expr.tokens file is there, along with all the .java files.
How do I tell ANTLR the path for finding the tokens file?
Here's the complete grammar:
tree grammar Walker;
options
{
tokenVocab=Expr;
ASTLabelType=CommonTree;
}
@header
{
import java.util.Map;
import java.util.HashMap;
}
@members
{
Map memory = new HashMap();
}
program : statement+;
statement: expr { System.out.println($expr.value); }
| ^(EQUALS ID expr) { memory.put($ID.text, new
Integer($expr.value)); }
;
expr returns [int value]
: ^('+' a=expr b=expr) { $value = a+b; }
| ^('-' a=expr b=expr) { $value = a-b; }
| ^('*' a=expr b=expr) { $value = a*b; }
| ID
{
Integer v = memory.get($ID.text);
if (v != null)
{
$value = v.intValue();
}
else
{
System.err.println("undefined variable " + $ID.text);
}
}
| INT
;
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---
List: http://www.antlr.org:8080/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org:8080/mailman/options/antlr-interest/your-email-address