1

Does fsyacc have some way to deal with operators that are introduced at parse time? I'm trying to build a parser for Kaleidoscope which is a toy language used as an example for the LLVM tutorial. Kaleidoscope allows operators to be defined along with precedence levels. Eg:

# Logical unary not.
def unary!(v)
  if v then
    0
  else
    1;

# Define > with the same precedence as <.
def binary> 10 (LHS RHS)
  RHS < LHS;

# Binary "logical or", (note that it does not "short circuit")
def binary| 5 (LHS RHS)
  if LHS then
    1
  else if RHS then
    1
  else
    0;

# Define = with slightly lower precedence than relationals.
def binary= 9 (LHS RHS)
  !(LHS < RHS | LHS > RHS);
Keith
  • 2,820
  • 5
  • 28
  • 39

1 Answers1

2

There is no magic in fsyacc to help with the dynamic precedence (this is rare in most parsing tools), but the same strategy described here

http://llvm.org/docs/tutorial/LangImpl2.html#parserbinops

is what you need, I think (I only glanced).

Brian
  • 117,631
  • 17
  • 236
  • 300