问题描述
fsyacc是否可以处理解析时引入的运算符?我正在尝试为万花筒构建一个解析器,这是一种玩具语言,用作LLVM教程的示例。万花筒允许将操作员与优先级一起定义。例如:
# 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);
解决方法
fsyacc中没有魔术可以帮助实现动态优先级(这在大多数解析工具中很少见),但是此处描述的策略相同
http://llvm.org/docs/tutorial/LangImpl2.html#parserbinops
我想是您需要的(我只是看了一眼)。