[antlr-interest] How compile my first parser?
Borneq
a.moderacja at gmail.com
Mon Jul 5 05:04:50 PDT 2010
I compile grammar from book "The Definitive ANTLR Reference" of Parr:
grammar T;
/** Match things like "call foo;" */
r : 'call' ID ';' {System.out.println("invoke "+$ID.text);} ;
ID: 'a'..'z' + ;
WS: (' ' |'\n' |'\r' )+ {$channel=HIDDEN;} ; // ignore whitespace
Grammal compiles OK, program antlrworks-1.4.jar creates TLexer.java
and TParser.java. I create Test.java :
import org.antlr.runtime.* ;
public class Test {
public static void main(String[] args) throws Exception{
//create a CharStream that reads from standard input
ANTLRInputStream input = new ANTLRInputStream(System.in);
//create a lexer that feeds off of input CharStream
TLexer lexer = new TLexer(input);
//create a buffer of tokens pulled from the lexer
CommonTokenStream tokens = new CommonTokenStream(lexer);
// create a parser that feeds off the tokens buffer
TParser parser = new TParser(tokens);
// begin parsing at rule r
parser.r();
}
}
In Eclipse I import antlr-3.2.jar where is ANTLRInputStream.class, but
Eclipse not found it and underline it.
How compile Test.java with Eclipse?
More information about the antlr-interest
mailing list