[antlr-interest] simple parser lookahead problem

Anthony Youngman Anthony.Youngman at ECA-International.com
Wed May 12 07:46:57 PDT 2004


I've got the following code in my parser ...

----------------------
// Can I distinguish between COLON and COLONPRINT here, I need to look
// ahead but not eat a SEMI or nl. It'll work if I can get catexpr to
// take priority.

printst : ( PRINT^ (expr (COLON)? )? );

catexpr : pmexpr ( COLON^ pmexpr)* ;
--------------------

plus a bit more code that effectively says

expr : catexpr ;

How do I resolve the ambiguity by doing a lookahead in printst - I
effectively want to look for an "end of statement" marker eg a newline
or semicolon. Unfortunately, ":" has three different meanings, as
exemplified in this simple line of code ...

XXX: PRINT A : B :

Where the first colon says "this is a label" (I haven't even touched
this yet!), the second says "concatenate the variables A and B
together", and the third says "don't print a newline at the end". Yeuch!
At the moment I'm disambiguating in the lexer, but I don't think that's
a good idea ... it'll be messy :-( but I really haven't got to grips
with predicates, which I think is what I need ...

Further on, I have a hiccup with my treeparser ...

printst
	: #(PRINT expr COLON) { st.write("PRINT");}
	| #(PRINT expr) { st.write("PRTLN");}
//	| #(PRINT) { st.write("CRLF");}
	;

antlr.Tool does not like the commented-out line - I'm guessing it's
incredibly simple, but it's objecting to PRINT :-(

Cheers,
Wol


****************************************************************************

This transmission is intended for the named recipient only. It may contain private and confidential information. If this has come to you in error you must not act on anything disclosed in it, nor must you copy it, modify it, disseminate it in any way, or show it to anyone. Please e-mail the sender to inform us of the transmission error or telephone ECA International immediately and delete the e-mail from your information system.

Telephone numbers for ECA International offices are: Sydney +61 (0)2 9911 7799, Hong Kong + 852 2121 2388, London +44 (0)20 7351 5000 and New York +1 212 582 2333.

****************************************************************************



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
     antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
     http://docs.yahoo.com/info/terms/
 



More information about the antlr-interest mailing list