[antlr-interest] I don't understand.....
Lloyd Dupont
lloyd at galador.net
Wed Apr 3 04:03:46 PST 2002
why this (stupid) grammar has problem ?
why OPTION 2 has problem ? it seems quite clear to me !
by the way it is roughly the same than OPTION 1 which work, why ?
//-------------------------------- main.g ----------------------------------
header {
import java.io.FileInputStream;
}
class Main extends Parser;
options {
buildAST = true;
}
{
public static void main(String[] args)
throws Exception
{
DCReader l = new DCReader(new FileInputStream("file"));
Main p = new Main(l);
System.out.println("start parsing ...");
p.file();
System.out.println("find: " + p.getAST());
}
}
/*
// ------------------- OPTION 1
file: (ID {System.out.println("ID");}
| NUM {System.out.println("NUM");}
) +;
class DCReader extends Lexer;
ID: (CHAR) + ;
NUM: (DIGIT) + ;
protected CHAR: 'a' .. 'z' | 'A' .. 'Z' | '_' | '$' | '.' ;
protected DIGIT: '0' .. '9' ;
WS : (' ' | '\t' | '\f' )+ { _ttype = Token.SKIP; } ;
/**/
// ------------------- OPTION 2
file: (name {System.out.println("name");}
| number {System.out.println("number");}
) +;
name: (CHAR) + ;
number: (DIGIT) + ;
class DCReader extends Lexer;
CHAR: 'a' .. 'z' | 'A' .. 'Z' | '_' | '$' | '.' ;
DIGIT: '0' .. '9' ;
WS : (' ' | '\t' | '\f' )+ { _ttype = Token.SKIP; } ;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20020403/1aa05b27/attachment.html
More information about the antlr-interest
mailing list