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


Groups > comp.compilers > #2768 > unrolled thread

Re: Why are ambiguous grammars usually a bad idea? Why are languages usually defined and implemented with ambiguous grammars?

Started byFernando <pronesto@gmail.com>
First post2021-12-27 03:56 -0800
Last post2021-12-27 03:56 -0800
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.


Contents

  Re: Why are ambiguous grammars usually a bad idea? Why are languages usually defined and implemented with ambiguous grammars? Fernando <pronesto@gmail.com> - 2021-12-27 03:56 -0800

#2768 — Re: Why are ambiguous grammars usually a bad idea? Why are languages usually defined and implemented with ambiguous grammars?

FromFernando <pronesto@gmail.com>
Date2021-12-27 03:56 -0800
SubjectRe: Why are ambiguous grammars usually a bad idea? Why are languages usually defined and implemented with ambiguous grammars?
Message-ID<21-12-006@comp.compilers>
Hi Roger,

One problem with ambiguous grammars is that ambiguities might confuse the
semantics of the programming language. One example is with the associativity
and precedence of operators. Concerning associativity, the ambiguous grammar
below does not specify if subtraction is left or right associative:

E ::= E - E | num

And, there is this classic example from C-like languages involving conditional
statements:

<cmd> ::= if <bool_expr> then <cmd>
       |  if <bool_expr> then <cmd> else <cmd>

What would be the meaning of a statement like the one below? Depending on how
you fix the ambiguity, it's possible to make the else refer to the innermost
or the outermost conditional.

if (a > b) then if (c > d) then print(1) else print(2)

Regards,

Fernando

[toc] | [standalone]


Back to top | Article view | comp.compilers


csiph-web