Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.compilers > #976 > unrolled thread
| Started by | torbenm@diku.dk (Torben Ægidius Mogensen) |
|---|---|
| First post | 2011-02-01 13:35 +0100 |
| Last post | 2011-02-01 13:35 +0100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.compilers
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: how to parse this? torbenm@diku.dk (Torben Ægidius Mogensen) - 2011-02-01 13:35 +0100
| From | torbenm@diku.dk (Torben Ægidius Mogensen) |
|---|---|
| Date | 2011-02-01 13:35 +0100 |
| Subject | Re: how to parse this? |
| Message-ID | <11-02-002@comp.compilers> |
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 top | Article view | comp.compilers
csiph-web