[antlr-interest] Cannot Find Eval.tokens File
Michael Duffy
duffymo at gmail.com
Fri Oct 17 11:27:58 PDT 2008
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
;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20081017/81360918/attachment.html
More information about the antlr-interest
mailing list