[antlr-interest] related question: multiple grammars..

Fırat KÜÇÜK firatkucuk at gmail.com
Thu Mar 29 01:20:17 PDT 2007

2007/3/29, Eitan Suez <eitan.suez at gmail.com>:
> as a followup to my last post..
>   the antlr betabook discusses in an early chapter
>   the analogy to humans' ability to parse language.
>   how when we read, we have one grammar for
>   assembling the letters into words and a separate
>   grammar for assembling words into phrases.
>   basically that there's a hierarchy of languages.
>   anyhow, is there a construct that will allow me
>   to parse a file at more than one level?
>   for example, i'm trying to learn antlr v3 by writing
>   a css parser (or i'm trying to write a css parser using
>   antlr v3 and i'm an antlr newbie).  css is really
>   two languages:  there's the primary language,
>   then there's the sublanguage for interpreting
>   selectors.

You can use two different parser for two grammar style.
For instance a Java Grammar. You can write a java parser and a apidoc
parser for parsing /** ... */ style javadoc.

or you can write an all in one grammar.

>   one can get by ignoring whitespace for the main
>   language but not for the selectors.
>   so, back to my question:  is there a way to
>   say to antlr in one grammar:  when you come
>    across a certain kind of block in this stream, use
>   subgrammar x to parse that.  some vague
>   analog to a sort of "include" statement in the domain of
>   parsing.
> thanks, eitan

Öğr. Gör. Fırat KÜÇÜK
ADAMYO Distance Learning

More information about the antlr-interest mailing list