[antlr-interest] Multipass parsing
John D. Mitchell
johnm-antlr at non.net
Sun Mar 28 17:23:59 PST 2004
>>>>> "FranklinChen" == FranklinChen <FranklinChen at cmu.edu> writes:
>>>>>>> "FranklinChen" == FranklinChen <FranklinChen at cmu.edu> writes:
[...]
>> For your example, with Antlr, you can write a separate grammar for each
>> of the languages and then invoke the appropriate grammar at the
>> appropriate spot.
> Can you sketch out sample grammars and code that would handle what I
> posted? Seriously. I've read the entire ANTLR documentation site and
> the jGuru FAQ site and the source code for all the examples (for Java
> generation), and I cannot offhand come up with what I am looking for.
I'm running off for a few days but I'm available on a consulting basis for
this type of work.
[...]
> - As my toy example tries to indicate, "-" can mean three different
> things, depending on the context
That's what parsers and tree grammars are good at.
> The whitespace first pass is important, because I want to pass
> grape[fruit] completely differently from grape [fruit]
FWIW, that's a *really* bad idea in a language.
> I want to be able to deal with unexpected input at fine granularity and
> recovery, to minimize parse failures, e.g., if I see 1+2* is 7 I want to
> not go below the "word" level in the first "token" "1+2*" because I don't
> want to try to parse an expression and fail.
As I noted, you can write a very permissive lexer and a permissive parser
and then do whatever specific checks via multiple tree grammars.
Have fun,
John
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