1

fsyacc 是否有某种方法来处理在解析时引入的运算符?我正在尝试为 Kaleidoscope 构建一个解析器,它是一种玩具语言,用作LLVM 教程的示例。Kaleidoscope 允许定义运算符以及优先级。例如:

# 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);
4

1 回答 1

2

fsyacc 中没有魔法可以帮助处理动态优先级(这在大多数解析工具中很少见),但是这里描述的策略相同

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

是你需要的,我想(我只看了一眼)。

于 2011-05-24T23:53:46.440 回答