fuzzy-dl-owl2 1.0.1__py3-none-any.whl → 1.0.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,70 +0,0 @@
1
- from lark import Lark, Transformer, v_args
2
-
3
- calc_grammar = """
4
- ?start: sum
5
- | NAME "=" sum -> assign_var
6
-
7
- ?sum: product
8
- | sum "+" product -> add
9
- | sum "-" product -> sub
10
-
11
- ?product: atom
12
- | product "*" atom -> mul
13
- | product "/" atom -> div
14
-
15
- ?atom: NUMBER -> number
16
- | "-" atom -> neg
17
- | NAME -> var
18
- | "(" sum ")"
19
-
20
- %import common.CNAME -> NAME
21
- %import common.NUMBER
22
- %import common.WS_INLINE
23
-
24
- %ignore WS_INLINE
25
- """
26
-
27
-
28
- @v_args(inline=True) # Affects the signatures of the methods
29
- class CalculateTree(Transformer):
30
- from operator import add, mul, neg, sub
31
- from operator import truediv as div
32
-
33
- number = float
34
-
35
- def __init__(self):
36
- self.vars = {}
37
-
38
- def assign_var(self, name, value):
39
- print(name, value)
40
- self.vars[name] = value
41
- return value
42
-
43
- def var(self, name):
44
- try:
45
- return self.vars[name]
46
- except KeyError:
47
- raise Exception("Variable not found: %s" % name)
48
-
49
-
50
- calc_parser = Lark(calc_grammar, parser="lalr", transformer=CalculateTree())
51
- calc = calc_parser.parse
52
-
53
-
54
- def main():
55
- while True:
56
- try:
57
- s = input("> ")
58
- except EOFError:
59
- break
60
- print(calc(s))
61
-
62
-
63
- def test():
64
- print(calc("a = 1+2"))
65
- print(calc("1+a*-3"))
66
-
67
-
68
- if __name__ == "__main__":
69
- # test()
70
- main()