Re: Yacc and a calculator (Norman Ramsey)
14 Feb 1996 21:21:36 -0500

          From comp.compilers

Related articles
Yacc and a calculator (Dan Weinlader) (1996-02-13)
Re: Yacc and a calculator (1996-02-14)
Re: Yacc and a calculator (1996-02-16)
| List of all articles for this month |

From: (Norman Ramsey)
Newsgroups: comp.compilers
Date: 14 Feb 1996 21:21:36 -0500
Organization: Department of Computer Science, Purdue University
References: 96-02-143
Keywords: yacc, parse

Dan Weinlader <> wrote:
  >Suppose I wish to allow
  >the user to enter 8 5 and have it parsed as 8*5, how do I do that?
  >I have tried:
  >expression: ...
  > | ...
  > | expression expression { ... }
  >but that produces shift/reduce conflicts. The problem is not precedence,
  >but associativity, right? So how do I tell Yacc (Bison to be exact) what
  >the assocativity is for this expression?

I like what the SML/NJ people did: simply treat an expression as a
sequence of identifiers and resolve ambiguity at the semantic level
using a simple operator-precedence algorithm. Something of the sort
is more or less necessary because ML supports dynamic changes in
`fixity', precedence and associativity. Anyway, in your
operator-precedence algorithm, if you see non-operator in the input
and a non-operator on the stack you simply insert a * operator and
Norman Ramsey


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.