[antlr-interest] Language Preprocessor.
Bogdan Mitu
bogdan_mt at yahoo.com
Fri Apr 12 03:51:30 PDT 2002
--- Trey Spiva <Trey.Spiva at embarcadero.com> wrote:
> I was wondering if I can mark actions as being Java or C++. If I could I
> would
> be able to have both java and C++ action in the same grammar file and just
> change
> the language to be produced. I am think of something like a C++
> preprocessor.
Hi Trey,
I think a better solution is to mark the points where action should be
inserted in a language-independent manner and later use a simple parser to
replace the markers with actual code. The association <marker>-<code to be
inserted> can be stored in a different file. This way the grammar is kept
generic and easy to read, and by changing the file, you can generate "real"
grammars with actions for Java, C++ or whatever.
This is somewhat similar to the suggestion of Monty to use noweb (literate
programming). I wrote a simple tool that allows me to place markers of the
form:
rule: alfa <init> ( beta <add> )+ ;
and to specify in another file what <init> and <add> mean. If you want, I
can send it to you.
Best regards,
Bogdan
> #if language Java
> {
> < ACTIONS >
> }
> #else if language C++
> {
> < ACTIONS >
> }
>
>
> Trey Spiva
> Senior Software Engineer
> trey.spiva at embarcadero.com
>
>
__________________________________________________
Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax
http://taxes.yahoo.com/
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list