[antlr-interest] Need help on my grammar
fung li
lifung18 at hotmail.com
Mon Jul 8 18:30:08 PDT 2002
Hi all,
The following grammar trys to recognize "129 Park Avenue" or "36-129 Park
Avenue".
When I compiled the following grammar with k=1 in TreeParser section, I got
an error message:
addr.g:59: warning: nondeterminism upon
addr.g:59: k==1:NUMBER
addr.g:59: between alts 1 and 2 of block
However, with k=2, I got:
addr.g:59: warning: nondeterminism upon
addr.g:59: k==1:NUMBER
addr.g:59: k==2:NULL_TREE_LOOKAHEAD
addr.g:59: between alts 1 and 2 of block
In this case, what should I do ?
Thanks in advance.
Ben
--------------------------------------------------
class MyParser extends Parser;
options {
defaultErrorHandler=false;
buildAST=true ;
k = 2;
}
startRule: address_detail
{ System.out.println ( "->>>>> OK" ); };
address_detail : NUMBER^ STREETNAME streettype
| NUMBER^ DASH NUMBER STREETNAME streettype
;
streettype: "AVENUE" | "STREET" ;
class MyLexer extends Lexer;
options {
charVocabulary = '\3'..'\377' ;
testLiterals=false ;
}
WS : ( ' ' | '\t' | '\n' | '\r' )
{ $setType(Token.SKIP) ; } ;
COMMA: ','
{ $setType(Token.SKIP) ; } ;
DASH: '-'
;
STREETNAME
options {
testLiterals = true ;
}
: ( 'a'..'z' | 'A'..'Z' )+
;
NUMBER: ( '0'..'9' )+
;
class AddrTreeWalker extends TreeParser;
options {
k = 2 ;
}
myexpr returns [ String r ]
{
String postr="" ;
String addrstr="" ;
r = "" ;
}
: addrstr=address_detail
{
r = "ADDR=" + addrstr ;
}
;
address_detail returns [ String r ]
{
String stnt ;
StringBuffer stnameB = new StringBuffer();
String stno1 = "" ;
String stno2 = "" ;
int stncount = 0 ;
r = "" ;
}
: #( stno:NUMBER { stno1 = stno.getText() ; }
stna:STREETNAME
stnt=streettype
)
{
r = " stno=" + stno1
+ ",stna=" + stna.getText()
+ ",stnt=" + stnt
;
}
| #( st2:NUMBER { stno1 = st2.getText() ; }
DASH
st3:NUMBER { stno2 = st3.getText(); }
stna2:STREETNAME
stnt=streettype
)
{
r = " appno=" + stno1
+ ",stno=" + stno2
+ ",stna=" + stna2.getText()
+ ",stnt=" + stnt
;
}
;
streettype returns [ String r ]
{
r = "" ;
}
: "AVENUE"
| "STREET"
;
_________________________________________________________________
MSN Photos is the easiest way to share and print your photos:
http://photos.msn.com/support/worldwide.aspx
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list