[antlr-interest] why antlr not accept string as input stream?
=?gb2312?B?us6zrA==?=
hc7750 at 163.com
Mon Jan 31 18:01:50 PST 2005
e.g.
class MyParser extends Parser;
options
{
k=2;
}
expr: NUMBER (PLUS|SUB) expr | NUMBER;
class MyLexer extends Lexer;
options
{
k = 2;
}
PLUS: '+';
SUB: '-';
NUMBER: ('0'..'9')+;
WS: ( '\t'|'\f'|' '| ('\r'|'\n'|"\r\n"){newline();})+ {$setType(Token.SKIP);};
=============================================================================
import java.io.*;
import antlr.CommonAST;
import antlr.collections.AST;
import antlr.debug.misc.ASTFrame;
import java.util.*;
class Test{
public static void main(String[] args) {
try {
MyLexer lexer = new MyLexer("12+23-34");
MyParser parser = new MyParser(lexer);
parser.expr();
} catch(Exception e) {
System.err.println("exception: "+e);
}
}
}
=================================================================
Then an error occurs :
C:\Documents and Settings\Administrator\1>javac Test.java
Test.java:9: cannot resolve symbol
symbol : constructor MyLexer (java.lang.String)
location: class MyLexer
MyLexer lexer = new MyLexer("12+23-34");;
^
1 error
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20050201/01282970/attachment.html
More information about the antlr-interest
mailing list