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) |
From: | marctardif@yahoo.com |
Newsgroups: | comp.compilers |
Date: | 27 Jun 2000 00:57:35 -0400 |
Organization: | Deja.com - Before you buy. |
Keywords: | parse, question, comment |
How can I:
1. Parse a boolean query completely.
2. Use the parsed names to retrieve values from my current program.
3. Use the returned values in the original query.
4. Test if the boolean query is true or false.
If I try to use lex and yacc for step 1, I can't seem to be able to
retrieve values from my current program AFTER parsing. For example,
consider the following yacc code for parsing a simple boolean query
(assuming a proper lex file):
%%
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. 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?
Any ('suggestions' OR 'documentation' OR 'source code') would be much
appreciated.
Marc Tardif
[One possibility is to parse once to find out what the names are, then
parse again to evaluate the expression. Or parse once and build a
data structure like a parse tree or RPN operator list, then interpret
the data structure to evaluate the expression. -John]
Return to the
comp.compilers page.
Search the
comp.compilers archives again.