[antlr-interest] Help me the chemmestry forumla grammer?
Jun Tsai
jun.tsai at gmail.com
Fri Mar 10 20:11:14 PST 2006
hi all.
I want to parse a chemestry forumla.such as:
A2(B3)2C3 => A2B6C3
A2(AB3)2C3 =>A4B6C3
A(CB3)2C3 =>A1B6C5
How to do it?
I use :
parser:
entry : (atom)+
;
atom : (c:CHAR n:NUM)
{System.out.println("c:"+c.getText()+" ");}
| (LPAREN entry RPAREN n:NUM)
{
System.out.println("okay "+n.getText());
}
Lexer:
NUM :('0'..'9')*;
Thanks.
Jun Tsai
--
Welcome to China Java Users Group(CNJUG).
http://cnjug.dev.java.net
More information about the antlr-interest
mailing list