Re: parsing boolean queries

Joachim Pimiskern <Joachim.Pimiskern@de.bosch.com>
30 Jun 2000 00:54:45 -0400

          From comp.compilers

Related articles
parsing boolean queries marctardif@yahoo.com (2000-06-27)
Re: parsing boolean queries Joachim.Pimiskern@de.bosch.com (Joachim Pimiskern) (2000-06-30)
Re: parsing boolean queries cbrtjr@ix.netcom.com (Charles E. Bortle, Jr.) (2000-06-30)
| List of all articles for this month |

From: Joachim Pimiskern <Joachim.Pimiskern@de.bosch.com>
Newsgroups: comp.compilers
Date: 30 Jun 2000 00:54:45 -0400
Organization: Robert Bosch GmbH
References: 00-06-102
Keywords: parse

Hi Marc,


marctardif@yahoo.com schrieb in Nachricht 00-06-102...
> %%
> statement:
> expression { printf("%s\n", ($1==0)?"false":"true"); } ;
>
> expression:
> expression '&' expression { $$ = $1 & $3; } |
> expression '|' expression { $$ = $1 | $3; } |
> '(' expression ')' { $$ = $2; } |
> NUMBER { $$ = $1; } ;
> %%
>
>Problem is that the expressions are expecting true/false values,
>whereas I can only provide names until the whole input is parsed. Once
>the names are all gathered, I can proceed to step 2 and replace names
>with true/false values. Only then can I input determine if the boolean
>query is true false.


you need to re-#define YYSTYPE, which is int by default.
I would use pointers to a self-defined struct type
which may contain the names you mentioned.


Within the semantic actions, it's your's to evaluate
these pointers, for example:


expression '&' expression {
                                                      int a,b;
                                                      a = getVariableValue($1);
                                                      b = getVariableValue($2);
                                                      $$ = a && b;
                                                    }


>Does this mean I have to generate my own parse
>tree from within yacc? If so, is there any sample c source code I
>could read for inspiration?


In this case this would be (IMHO) an overkill.


Regards,
Joachim
[I don't see how to avoid generating a parse tree or something like it
if you don't know what the names mean until you've parsed the entire
expression. -John]



Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.