Parser question about lab 4

1 view
Skip to first unread message

Per Strömdahl

unread,
Mar 7, 2010, 6:35:02 PM3/7/10
to proglang-course-2010
We have defined application as
EApplication. Exp2 ::= Ident [Exp];
with
separator nonempty Exp "";

In "good1.fun", the line
main = fst (twice (\x -> x)) 6 7
is found. Let's call "(twice (\x -> x))" A, "6" B and "7" C.
Then the correct parsing of this line would be
main = (fst(A,B)) C
but our grammar parses this as
main = (fst(A,B,C))

"Ident [Exp]" in our grammar can't know about how many arguments "fst"
should take,
does anyone have any advice to give about how to parse Applications ?

Krasimir Angelov

unread,
Mar 8, 2010, 1:12:16 AM3/8/10
to proglang-c...@googlegroups.com
You cannot and should not try to do this in the grammar. The correct
way is to have something like:

Exp ::= Exp Exp

where Exp should be some ExpN where N is the right precedence level.
Every expression could be applied to every other expression. For
instance your grammar doesn't support expression like:

(\x -> x) 0

After you have the grammar then the interpreter should take care of
how many arguments are passed to the function.

Reply all
Reply to author
Forward
0 new messages