首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >fsyacc:允许在语言中定义运算符

fsyacc:允许在语言中定义运算符
EN

Stack Overflow用户
提问于 2011-05-25 07:47:49
回答 1查看 208关注 0票数 1

fsyacc有没有办法处理解析时引入的运算符?我正在尝试为万花筒构建一个解析器,它是一种玩具语言,用作LLVM tutorial的示例。万花筒允许定义运算符和优先级。例如:

代码语言:javascript
复制
# 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);
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-05-25 07:53:46

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

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

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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6118133

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档