尝试构建一个可以解析简单布尔表达式的语法。
当有多个表达式时,我遇到了一个问题。
我需要能够解析1..n
and/or
'ed 表达式。
下面的每个示例都是一个完整的表达式:
(myitem.isavailable("1234") or myitem.ispresent("1234")) and myitem.isready("1234")
myitem.value > 4 and myitem.value < 10
myitem.value = yes or myotheritem.value = no
语法:
@start = conditionalexpression* | expressiontypes;
conditionalexpression = condition expressiontypes;
expressiontypes = expression | functionexpression;
expression = itemname dot property condition value;
functionexpression = itemname dot functionproperty;
itemname = Word;
propertytypes = property | functionproperty;
property = Word;
functionproperty = Word '(' value ')';
value = Word | QuotedString | Number;
condition = textcondition;
dot = '.';
textcondition = 'or' | 'and' | '<' | '>' | '=';