[antlr-interest] Simple grammar, but #if #endif and are making it harder

Xavier xverges at gmail.com
Tue Dec 4 04:57:45 PST 2007


> Still, I would go for 2 passes (be they in-memory; or using a real intermediate file)

Thanks, Harald. 2 passes and real intermediate file will make me feel
safer in my baby steps :-)

-Xavier

On Dec 4, 2007 12:13 PM, Harald Mueller <harald_m_mueller at gmx.de> wrote:
> Hi - re item 2., after a quick scan over the documentation, I'd say that the following is legitimate:
>
>     POLICY !!DisableTaskMgr
> #if version < 4.0
>        EXPLAIN !!DisableTaskMgr_Explain
> #endif
> #if version >= 4.0
>        EXPLAIN !!...something else...
> #endif
>        VALUENAME "DisableTaskMgr"
>    END POLICY
>
> However, according to the documentation, there can only be one EXPLAIN clause in a POLICY. Therefore, if your grammar should mimick Microsoft's definition, you have to *evaluate* the #ifs *before* running the parser. Usually, this means that having all in one grammar gets really ugly.
>
> In your case, one could try a one-pass grammar, because the #if's as well as the other commands appear to be line-oriented (are they really? I did not find any positive statement on this ...), so some mingling machinery might be possible.
>
> Still, I would go for 2 passes (be they in-memory; or using a real intermediate file - how large is your input going to be? everything below a few 10000 lines does not need read-write optimization, IMHO): It is simply simpler.
>
> Regards
> Harald M.
>
> -------- Original-Nachricht --------
> > Datum: Tue, 4 Dec 2007 11:35:47 +0100
> > Von: Xavier <xverges at gmail.com>
> > An: antlr-interest at antlr.org
> > Betreff: [antlr-interest] Simple grammar,     but #if #endif and are making it harder
>
>
> > I have to translate .ADM files, that specify Windows Policy Settings
> > http://msdn2.microsoft.com/en-us/library/aa372405.aspx
> >
> > I'm having a hard time getting started,mostly because I'm new to ANTLR
> > and I don't know how to deal with comments and #if #endif sections.
> >
> > 1. To learn how to deal with #if #endif, is there a simpler starting
> > point than the full featured C Preprocessor from Youngki KU
> > http://www.antlr.org/grammar/1166665121622/Cpp.tar
> >
> > 2. What does look like a better approach?
> > 2.1. Having a preprocessor step (a grammar to deal with comments and
> > #ifdefs) and handling the "meat" in a later step
> > 2.2. Using a single grammar definition
> >
> > Thanks in advance for any advice.
> >
> > -Xavier
>
> --
> GMX FreeMail: 1 GB Postfach, 5 E-Mail-Adressen, 10 Free SMS.
> Alle Infos und kostenlose Anmeldung: http://www.gmx.net/de/go/freemail
>



-- 
-Xavier


More information about the antlr-interest mailing list