Related articles |
---|
YACC parser & conditional compilation directives spx4vc@cf.ac.uk (Vadim) (1995-06-23) |
Re: YACC parser & conditional compilation directives johnm@soda.CSUA.Berkeley.EDU (1995-06-27) |
Re: YACC parser & conditional compilation directives ccrlphr@xensei.com (1995-06-27) |
Re: YACC parser & conditional compilation directives scott@infoadv.mn.org (Scott Nicol) (1995-07-05) |
Newsgroups: | comp.compilers |
From: | Scott Nicol <scott@infoadv.mn.org> |
Keywords: | yacc |
Organization: | Compilers Central |
References: | 95-06-091 |
Date: | Wed, 5 Jul 1995 02:37:45 GMT |
>One way is to do something like this:
>
> * %token IF ELSE ENDIF ...
> * %type <int> condition
> * %type <compiled> cond_compile compile_this statement ...
> * ...
> * %%
> * ...
> * cond_compile: compile_this
> * | IF condition cond_compile ELSE cond_compile ENDIF { if ($2) $$=$3 else
>$$=$5; }
> * ;
> * condition: ... { $$=evaluate($1,$....) /* evaluate the condition */ }
> * compile_this: statement
> * | compile_this statement { $$=concat($1,$2); /* concat the compiled
>statements */}
> * ;
> * statement: command param1 param2 ... { $$=compile($1,...); /* compile and
>put result in $$ */}
> * | kind2_stat ...
> * ;
The problem with this method is that you are analyzing all of the code,
even the code which is #ifdef'ed away. If you believe that conditional
compilation means "don't look at code which is conditionally excluded",
then the above method is clearly wrong.
A better method is to do things in two passes. If for some reason two
passes is unsuitable, hacking the lexer works, too.
--
Scott Nicol email: scott@infoadv.mn.org
Information Advantage, Inc. work: (612) 820-3846
Edina, MN home: (612) 488-5406
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.