start addeding atomic propositions

This commit is contained in:
Marcell Vazquez-Chanlatte 2016-11-04 14:45:30 -07:00
parent 4c46db7f71
commit c46e325cf8
4 changed files with 21 additions and 2 deletions

View file

@ -21,7 +21,7 @@ from sympy import Symbol, Number
from stl import ast
STL_GRAMMAR = Grammar(u'''
phi = (g / f / lineq / or / and / paren_phi)
phi = (g / f / lineq / AP / or / and / paren_phi)
paren_phi = "(" __ phi __ ")"
@ -47,6 +47,8 @@ time = prime / time_index
time_index = "[" "t" __ pm __ const "]"
prime = "'"
AP = ~r"[a-zA-z\d]+"
pm = "+" / "-"
dt = "dt"
unbound = id "?"
@ -145,6 +147,9 @@ class STLVisitor(NodeVisitor):
def visit_pm(self, node, _):
return Number(1) if node.text == "+" else Number(-1)
def visit_AP(self, node, _):
return ast.AtomicPred(node.text)
def parse(stl_str:str, rule:str="phi") -> "STL":
return STLVisitor().visit(STL_GRAMMAR[rule].parse(stl_str))