-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpcb_function_sm.py
48 lines (27 loc) · 1.01 KB
/
pcb_function_sm.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import asp.tree_grammar
import ast
import types
# grammar for functions that return either doubleint or one of the
# user-defined Obj types
asp.tree_grammar.parse('''
UnaryFunction(input=Identifier, body=Expr)
Expr = Constant
| Identifier
| BinaryOp
| BoolConstant
| IfExp
| Attribute
| FunctionReturn
| Compare
Identifier(name=types.StringType)
Compare(left=Expr, op=(ast.Eq | ast.NotEq | ast.Lt | ast.LtE | ast.Gt | ast.GtE), right=Expr)
Constant(value = types.IntType | types.FloatType)
BinaryOp(left=Expr, op=(ast.Add | ast.Sub), right=Expr)
BoolConstant(value = types.BooleanType)
IfExp(test=(Compare|Attribute|Identifier|BoolConstant), body=Expr, orelse=Expr)
# this if for a.b
Attribute(value=Identifier, attr=Identifier)
# a return here is different than in the predicate classes. Here, the return must have a
# constructor, so it looks like "return FooClass(value)"
FunctionReturn(ret_type = Identifier, value = Expr*)
''', globals())