Related articles |
---|
Lex , Yacc Problem dbansidhar@indiainfo.com (2003-09-14) |
Re: Lex , Yacc Problem paulchen32@freenet.de (Jens Kallup) (2003-09-22) |
Re: Lex , Yacc Problem rkrayhawk@aol.com (2003-09-22) |
Re: Lex , Yacc Problem blackmarlin@asean-mail.com (2003-09-23) |
From: | "Jens Kallup" <paulchen32@freenet.de> |
Newsgroups: | comp.compilers |
Date: | 22 Sep 2003 23:39:18 -0400 |
Organization: | T-Online |
References: | 03-09-051 |
Keywords: | yacc |
Posted-Date: | 22 Sep 2003 23:39:18 EDT |
Hello,
try to use an C array of type integer and an position
counter. Initialize the array element with 0 and parse the code. Each
time you parse a #if, evaluate it an set at array[positon counter] an
1 and increment the position counter. Next time you parse #if, check
the array[position counter minus 1] if it 1 and when, do nothing.
Each time you parse #endif, decrease position counter (minus 1) and
you can do a check, if array[position counter] is 1 (not execute) or 0
(execute).
symbolic code:.
int pos_counter = 0;
int if_array[2048] = { 0,0,0 .... };
parse_code()
{
if (pos_counter > 0) {
if (if_array[pos_counter - 1] == 1) { return; }
}
parse_code here
]
YACC:
parse_if
: '#' TOKEN_IF commands {
pos_counter = pos_counter + 1;
}
;
commands
:
| '#' TOKEN_ENDIF { pos_counter = pos_counter - 1; }
| TOKEN_MOV {
parse_code();
}
;
Cheers
Jens
Return to the
comp.compilers page.
Search the
comp.compilers archives again.