[antlr-interest] simple novice grammar question
Greg Gimler
ggimler at hotmail.com
Tue May 25 06:02:51 PDT 2004
I'm trying to define a simple parser which constructs a series of boolean
conditions. Basically, just like a Java or C boolean condition.
So the string "( (x=='somestring') && (y>3 || z>4) )" would be accepted by
this language. Likewise,
Strings: "( (x>3) (y>2) )", "()", "x>3 y=='somestring'" ,and " (x>3
y=='somestring')" should all fail.
I looked at some of the sample GNU C and Java grammars for this section but
it proved to be a little above my understanding of the antlr syntax. Right
now, my parser works for most strings but lets
"(x>3)(y=='somestring')" pass as a valid string when I would like it to
fail.
I've attached just the parser below (if seeing my lexer helps, let me know).
// parser rules
startRule
: filter
;
filter
: LPAREN^ bool_or RPAREN!
;
bool_or
: bool_and (OR^ bool_and)*
;
bool_and
: bool_comp_seq (AND^ bool_comp_seq)*
;
bool_comp_seq
: bool_comp
;
bool_comp
: factor ((EQ^|NEQ^|LT^|LTE^|GT^|GTE^) factor)*
;
factor
: LPAREN^ bool_or RPAREN!
| IDENTIFIER
| (NUMBER|STRING)
;
If anyone could provide some assistance getting this fixed I would
appreciate it. Whenever I've tried, I end up with warnings that I don't
know how to remedy. Perhaps there's a better way of defining what I already
have? Thanks.
-Greg
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/antlr-interest/
<*> To unsubscribe from this group, send an email to:
antlr-interest-unsubscribe at yahoogroups.com
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list