8
考慮語法這部分:如何使用Scala Parser Combinator更改代碼以將運算符優先級考慮在內?
def expression = SimpleExpression ~ opt(relation ~ SimpleExpression)
def relation = "=" | "#" | "<=" | "<" | ">=" | ">" | "IN" | "IS"
def SimpleExpression = opt("+" | "-") ~ rep1sep (term, AddOperator)
def AddOperator = "+" | "-" | "OR"
def term = factor ~ rep(MulOperator ~ factor)
def MulOperator = "*" | "/" | "DIV" | "MOD" | "&"
def factor: Parser[Any] = number | "(" ~ expression ~ ")" | "~" ~ factor
是否需要重寫它的部分來創建新的規則,或者是有隻是一個方法(如|
與|||
的第一對最長的規則匹配)我目前缺少哪些必要的東西?
您的具體問題是什麼? – ziggystar