[antlr-interest] another lookahead issue with TokenStreamRewriteEngine

Terence Parr parrt at cs.usfca.edu
Thu Feb 5 11:23:37 PST 2004


On Feb 5, 2004, at 9:29 AM, SainTiss wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hi,
>
> In the java.g grammar, I'm trying to parse a list of statements, by 
> repeatedly
> calling a rule statementComplete:
>
> statementComplete:
> 	statement;
>
> A statement, afaik, always ends with SEMI or "}". However, it seems 
> that the
> parser sometimes reads beyond that, probably for lookahead reasons.
> For example, when parsing the following:
>
> Method method = (Method) m;
> final int myInt = 5;
>
> After calling statementComplete once, and then calling the 
> rewriteEngine's
> toOriginalString() method, I get:
>
> "Method method = (Method) m;
> final"
>
> so the newline and "final" have been read as well, even though they 
> obviously
> aren't part of the first statement. Is there a way to get rid of this?
> Preferrably a way to make sure no tokens are read beyond the actual
> statement?

Would adding EOF to the end of statementCOmplete help?

>
> Thanks,
>
> Hans
>
> PS Terence: there are a couple of minor bugs in the 
> TokenStreamRewriteEngine
> as well:
> 1) In a couple of places, "programName" should be passed on to the
> addToSortedRewriteList, but isn't... (e.g. in public void 
> replace(String
> programName, Token from, Token to, String text))
> 2) A delete operation should be defined as replace with text "", not 
> text
> null, because the latter will put the characters n-u-l-l in the 
> string...

Thanks...i'll look at this.

Ter

>
> - --
> Ark Linux - Linux for the Masses (http://arklinux.org)
>
> Capitalism:
> You don't have any cows. The bank will not lend you money to buy cows,
> because you don't have any cows to put up as collateral.
>
> Representative Democracy:
> You have two cows. Your neighbors pick someone to tell you who gets 
> the milk.
>
> In a world without walls and fences, who needs windows and gates?
>
> Hans Schippers
> 2LIC INF
> UA 2003-2004
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.2.3 (GNU/Linux)
>
> iD8DBQFAIn1dXlnUYIbmLOQRAjn+AKCOJ3E1IgQINUCiW0Y1vRAkrd4c+ACfUBXW
> c/p6MDQaUxcVMAvR11U0rwA=
> =ugzy
> -----END PGP SIGNATURE-----
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
--
Professor Comp. Sci., University of San Francisco
Creator, ANTLR Parser Generator, http://www.antlr.org
Co-founder, http://www.jguru.com
Co-founder, http://www.knowspam.net enjoy email again!
Co-founder, http://www.peerscope.com pure link sharing





 
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