Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.compilers > #976

Re: how to parse this?

From torbenm@diku.dk (Torben Ægidius Mogensen)
Newsgroups comp.compilers
Subject Re: how to parse this?
Date 2011-02-01 13:35 +0100
Organization SunSITE.dk - Supporting Open source
Message-ID <11-02-002@comp.compilers> (permalink)
References <11-01-095@comp.compilers>

Show all headers | View raw


nojb <n.oje.bar@gmail.com> writes:

> Hi,
>
> My language has function applications like ML, i.e. f g h means f
> applied to two parameters g and h. But the rule
>
> exp: IDENT list(exp)
>
> in Yacc will parse this as f (g h). How can I fix this?

You can either fix it by post-processing the parse tree, or you can
write the production using explicit left-recursion:

exp: application

application: IDENT exp
           | application exp

If applications are really ML-like, they don't need to start with an
identifier, so you should rather have something like

exp: exp exp

which, however, is ambiguous.  You can fix this by adding a %prec
declaration or by dividing expressions into simple and complex
expressions and only allowing simple expressions as arguments to
function applications, i.e.,

exp: exp simple
   | simple

simple: IDENT
      | LPAR exp RPAR
      | ...

where LPAR and RPAR are the token names for parentheses.

	Torben

Back to comp.compilers | Previous | Next | Find similar


Thread

Re: how to parse this? torbenm@diku.dk (Torben Ægidius Mogensen) - 2011-02-01 13:35 +0100

csiph-web