[antlr-interest] Re: Semantic predicates that aren't & hoisting
David Jung
jungdl at ornl.gov
Fri Mar 11 21:01:12 PST 2005
John D. Mitchell said:
>>>>>> "David" == David Jung <jungdl at ornl.gov> writes:
>>>>>>> John D. Mitchell said:
> [...]
>
>>> Ugh. Notice how your example input is actually malformed...
>
>> My input is not mal-formed with respect to what I want to achieve
>> (i.e. the original problem I posed), but it is mal-formed according to
>> the grammar you've proposed. That is why I couldn't see how that
>> grammar
>> solves my problem - it doesn't.
>
> Ugh. Sure it does. You just didn't allow for multiple expressions at the
> top level:
>
> program : expr EOF ;
>
> Follow the grammar and make it say what you mean (and make sure you mean
> what you say (through the grammar :-)).
I really don't get it. Do you mean that changing the 'program' rule
will somehow allow the grammar to parse:
"{if {a>0;} then {f();g();} x();}"?
In English, this program will yield the value of x() unconditionally,
but first will call both f() and then g() only if a > 0.
Perhaps it would be easier if you just replied with the grammar
you think can parse that as:
program
expr
...
exprList
'{'
exprListOrStmt
expr <--- grammar erroneously wants a ';' after this
ifExpr
'if'
expr
...
exprList
'{'
exprListOrStmt
expr
...
condExpr
...
IDENT
'>'
expr
...
'0'
';'
'then'
expr
...
exprList
'{'
exprListOrStmt
expr
...
callExpr
...
'f'
'(' ')'
';'
expr
...
callExpr
...
'g'
'(' ')'
';'
'}'
<--- grammar wants ';' here, but finds 'x'
expr
...
callExpr
...
'x'
'(' ')'
';'
'}'
EOF
Your certainly makes me uncertain. :)
-David.
More information about the antlr-interest
mailing list