ZTWHHH commited on
Commit
55d42e7
·
verified ·
1 Parent(s): 3746fed

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +1 -0
  2. evalkit_tf437/lib/python3.10/site-packages/sympy/multipledispatch/__pycache__/__init__.cpython-310.pyc +0 -0
  3. evalkit_tf437/lib/python3.10/site-packages/sympy/multipledispatch/__pycache__/conflict.cpython-310.pyc +0 -0
  4. evalkit_tf437/lib/python3.10/site-packages/sympy/multipledispatch/__pycache__/utils.cpython-310.pyc +0 -0
  5. evalkit_tf437/lib/python3.10/site-packages/sympy/multipledispatch/tests/__pycache__/test_core.cpython-310.pyc +0 -0
  6. evalkit_tf437/lib/python3.10/site-packages/sympy/multipledispatch/utils.py +105 -0
  7. evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/__init__.py +4 -0
  8. evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/__pycache__/__init__.cpython-310.pyc +0 -0
  9. evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/__pycache__/ast_parser.cpython-310.pyc +0 -0
  10. evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/__pycache__/mathematica.cpython-310.pyc +0 -0
  11. evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/__pycache__/maxima.cpython-310.pyc +0 -0
  12. evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/__pycache__/sym_expr.cpython-310.pyc +0 -0
  13. evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/__pycache__/sympy_parser.cpython-310.pyc +0 -0
  14. evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/ast_parser.py +79 -0
  15. evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/autolev/Autolev.g4 +118 -0
  16. evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/autolev/__init__.py +97 -0
  17. evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/autolev/__pycache__/__init__.cpython-310.pyc +0 -0
  18. evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/autolev/__pycache__/_build_autolev_antlr.cpython-310.pyc +0 -0
  19. evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/autolev/__pycache__/_listener_autolev_antlr.cpython-310.pyc +0 -0
  20. evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/autolev/__pycache__/_parse_autolev_antlr.cpython-310.pyc +0 -0
  21. evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/autolev/_antlr/__init__.py +5 -0
  22. evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/autolev/_antlr/__pycache__/__init__.cpython-310.pyc +0 -0
  23. evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/autolev/_antlr/autolevlexer.py +253 -0
  24. evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/autolev/_antlr/autolevlistener.py +421 -0
  25. evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/autolev/_antlr/autolevparser.py +0 -0
  26. evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/autolev/_build_autolev_antlr.py +86 -0
  27. evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/autolev/_parse_autolev_antlr.py +38 -0
  28. evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/ruletest9.al +54 -0
  29. evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/c/__init__.py +1 -0
  30. evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/c/__pycache__/__init__.cpython-310.pyc +0 -0
  31. evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/c/__pycache__/c_parser.cpython-310.pyc +0 -0
  32. evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/c/c_parser.py +1058 -0
  33. evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/latex/LICENSE.txt +21 -0
  34. evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/latex/LaTeX.g4 +312 -0
  35. evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/latex/__init__.py +66 -0
  36. evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/latex/__pycache__/__init__.cpython-310.pyc +0 -0
  37. evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/latex/__pycache__/_build_latex_antlr.cpython-310.pyc +0 -0
  38. evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/latex/__pycache__/_parse_latex_antlr.cpython-310.pyc +0 -0
  39. evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/latex/__pycache__/errors.cpython-310.pyc +0 -0
  40. evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/latex/_antlr/__init__.py +9 -0
  41. evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/latex/_antlr/__pycache__/__init__.cpython-310.pyc +0 -0
  42. evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/latex/_antlr/__pycache__/latexlexer.cpython-310.pyc +0 -0
  43. evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/latex/_antlr/latexlexer.py +512 -0
  44. evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/latex/_antlr/latexparser.py +0 -0
  45. evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/latex/_build_latex_antlr.py +91 -0
  46. evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/latex/_parse_latex_antlr.py +607 -0
  47. evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/latex/errors.py +2 -0
  48. evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/latex/lark/__init__.py +2 -0
  49. evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/latex/lark/__pycache__/__init__.cpython-310.pyc +0 -0
  50. evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/latex/lark/__pycache__/latex_parser.cpython-310.pyc +0 -0
.gitattributes CHANGED
@@ -1273,3 +1273,4 @@ falcon/lib/python3.10/site-packages/torch/lib/libc10_cuda.so filter=lfs diff=lfs
1273
  falcon/lib/python3.10/site-packages/torch/__pycache__/overrides.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
1274
  falcon/lib/python3.10/site-packages/torch/__pycache__/_meta_registrations.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
1275
  falcon/lib/python3.10/site-packages/torch/sparse/__pycache__/_triton_ops_meta.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
 
 
1273
  falcon/lib/python3.10/site-packages/torch/__pycache__/overrides.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
1274
  falcon/lib/python3.10/site-packages/torch/__pycache__/_meta_registrations.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
1275
  falcon/lib/python3.10/site-packages/torch/sparse/__pycache__/_triton_ops_meta.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
1276
+ evalkit_tf437/lib/python3.10/site-packages/transformers/utils/__pycache__/dummy_tf_objects.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
evalkit_tf437/lib/python3.10/site-packages/sympy/multipledispatch/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (418 Bytes). View file
 
evalkit_tf437/lib/python3.10/site-packages/sympy/multipledispatch/__pycache__/conflict.cpython-310.pyc ADDED
Binary file (3.78 kB). View file
 
evalkit_tf437/lib/python3.10/site-packages/sympy/multipledispatch/__pycache__/utils.cpython-310.pyc ADDED
Binary file (3.61 kB). View file
 
evalkit_tf437/lib/python3.10/site-packages/sympy/multipledispatch/tests/__pycache__/test_core.cpython-310.pyc ADDED
Binary file (7.38 kB). View file
 
evalkit_tf437/lib/python3.10/site-packages/sympy/multipledispatch/utils.py ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from collections import OrderedDict
2
+
3
+
4
+ def expand_tuples(L):
5
+ """
6
+ >>> from sympy.multipledispatch.utils import expand_tuples
7
+ >>> expand_tuples([1, (2, 3)])
8
+ [(1, 2), (1, 3)]
9
+
10
+ >>> expand_tuples([1, 2])
11
+ [(1, 2)]
12
+ """
13
+ if not L:
14
+ return [()]
15
+ elif not isinstance(L[0], tuple):
16
+ rest = expand_tuples(L[1:])
17
+ return [(L[0],) + t for t in rest]
18
+ else:
19
+ rest = expand_tuples(L[1:])
20
+ return [(item,) + t for t in rest for item in L[0]]
21
+
22
+
23
+ # Taken from theano/theano/gof/sched.py
24
+ # Avoids licensing issues because this was written by Matthew Rocklin
25
+ def _toposort(edges):
26
+ """ Topological sort algorithm by Kahn [1] - O(nodes + vertices)
27
+
28
+ inputs:
29
+ edges - a dict of the form {a: {b, c}} where b and c depend on a
30
+ outputs:
31
+ L - an ordered list of nodes that satisfy the dependencies of edges
32
+
33
+ >>> from sympy.multipledispatch.utils import _toposort
34
+ >>> _toposort({1: (2, 3), 2: (3, )})
35
+ [1, 2, 3]
36
+
37
+ Closely follows the wikipedia page [2]
38
+
39
+ [1] Kahn, Arthur B. (1962), "Topological sorting of large networks",
40
+ Communications of the ACM
41
+ [2] https://en.wikipedia.org/wiki/Toposort#Algorithms
42
+ """
43
+ incoming_edges = reverse_dict(edges)
44
+ incoming_edges = {k: set(val) for k, val in incoming_edges.items()}
45
+ S = OrderedDict.fromkeys(v for v in edges if v not in incoming_edges)
46
+ L = []
47
+
48
+ while S:
49
+ n, _ = S.popitem()
50
+ L.append(n)
51
+ for m in edges.get(n, ()):
52
+ assert n in incoming_edges[m]
53
+ incoming_edges[m].remove(n)
54
+ if not incoming_edges[m]:
55
+ S[m] = None
56
+ if any(incoming_edges.get(v, None) for v in edges):
57
+ raise ValueError("Input has cycles")
58
+ return L
59
+
60
+
61
+ def reverse_dict(d):
62
+ """Reverses direction of dependence dict
63
+
64
+ >>> d = {'a': (1, 2), 'b': (2, 3), 'c':()}
65
+ >>> reverse_dict(d) # doctest: +SKIP
66
+ {1: ('a',), 2: ('a', 'b'), 3: ('b',)}
67
+
68
+ :note: dict order are not deterministic. As we iterate on the
69
+ input dict, it make the output of this function depend on the
70
+ dict order. So this function output order should be considered
71
+ as undeterministic.
72
+
73
+ """
74
+ result = {}
75
+ for key in d:
76
+ for val in d[key]:
77
+ result[val] = result.get(val, ()) + (key, )
78
+ return result
79
+
80
+
81
+ # Taken from toolz
82
+ # Avoids licensing issues because this version was authored by Matthew Rocklin
83
+ def groupby(func, seq):
84
+ """ Group a collection by a key function
85
+
86
+ >>> from sympy.multipledispatch.utils import groupby
87
+ >>> names = ['Alice', 'Bob', 'Charlie', 'Dan', 'Edith', 'Frank']
88
+ >>> groupby(len, names) # doctest: +SKIP
89
+ {3: ['Bob', 'Dan'], 5: ['Alice', 'Edith', 'Frank'], 7: ['Charlie']}
90
+
91
+ >>> iseven = lambda x: x % 2 == 0
92
+ >>> groupby(iseven, [1, 2, 3, 4, 5, 6, 7, 8]) # doctest: +SKIP
93
+ {False: [1, 3, 5, 7], True: [2, 4, 6, 8]}
94
+
95
+ See Also:
96
+ ``countby``
97
+ """
98
+
99
+ d = {}
100
+ for item in seq:
101
+ key = func(item)
102
+ if key not in d:
103
+ d[key] = []
104
+ d[key].append(item)
105
+ return d
evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/__init__.py ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ """Used for translating a string into a SymPy expression. """
2
+ __all__ = ['parse_expr']
3
+
4
+ from .sympy_parser import parse_expr
evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (313 Bytes). View file
 
evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/__pycache__/ast_parser.cpython-310.pyc ADDED
Binary file (3.13 kB). View file
 
evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/__pycache__/mathematica.cpython-310.pyc ADDED
Binary file (29.1 kB). View file
 
evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/__pycache__/maxima.cpython-310.pyc ADDED
Binary file (2.47 kB). View file
 
evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/__pycache__/sym_expr.cpython-310.pyc ADDED
Binary file (8.65 kB). View file
 
evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/__pycache__/sympy_parser.cpython-310.pyc ADDED
Binary file (30.4 kB). View file
 
evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/ast_parser.py ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ This module implements the functionality to take any Python expression as a
3
+ string and fix all numbers and other things before evaluating it,
4
+ thus
5
+
6
+ 1/2
7
+
8
+ returns
9
+
10
+ Integer(1)/Integer(2)
11
+
12
+ We use the ast module for this. It is well documented at docs.python.org.
13
+
14
+ Some tips to understand how this works: use dump() to get a nice
15
+ representation of any node. Then write a string of what you want to get,
16
+ e.g. "Integer(1)", parse it, dump it and you'll see that you need to do
17
+ "Call(Name('Integer', Load()), [node], [], None, None)". You do not need
18
+ to bother with lineno and col_offset, just call fix_missing_locations()
19
+ before returning the node.
20
+ """
21
+
22
+ from sympy.core.basic import Basic
23
+ from sympy.core.sympify import SympifyError
24
+
25
+ from ast import parse, NodeTransformer, Call, Name, Load, \
26
+ fix_missing_locations, Constant, Tuple
27
+
28
+ class Transform(NodeTransformer):
29
+
30
+ def __init__(self, local_dict, global_dict):
31
+ NodeTransformer.__init__(self)
32
+ self.local_dict = local_dict
33
+ self.global_dict = global_dict
34
+
35
+ def visit_Constant(self, node):
36
+ if isinstance(node.value, int):
37
+ return fix_missing_locations(Call(func=Name('Integer', Load()),
38
+ args=[node], keywords=[]))
39
+ elif isinstance(node.value, float):
40
+ return fix_missing_locations(Call(func=Name('Float', Load()),
41
+ args=[node], keywords=[]))
42
+ return node
43
+
44
+ def visit_Name(self, node):
45
+ if node.id in self.local_dict:
46
+ return node
47
+ elif node.id in self.global_dict:
48
+ name_obj = self.global_dict[node.id]
49
+
50
+ if isinstance(name_obj, (Basic, type)) or callable(name_obj):
51
+ return node
52
+ elif node.id in ['True', 'False']:
53
+ return node
54
+ return fix_missing_locations(Call(func=Name('Symbol', Load()),
55
+ args=[Constant(node.id)], keywords=[]))
56
+
57
+ def visit_Lambda(self, node):
58
+ args = [self.visit(arg) for arg in node.args.args]
59
+ body = self.visit(node.body)
60
+ n = Call(func=Name('Lambda', Load()),
61
+ args=[Tuple(args, Load()), body], keywords=[])
62
+ return fix_missing_locations(n)
63
+
64
+ def parse_expr(s, local_dict):
65
+ """
66
+ Converts the string "s" to a SymPy expression, in local_dict.
67
+
68
+ It converts all numbers to Integers before feeding it to Python and
69
+ automatically creates Symbols.
70
+ """
71
+ global_dict = {}
72
+ exec('from sympy import *', global_dict)
73
+ try:
74
+ a = parse(s.strip(), mode="eval")
75
+ except SyntaxError:
76
+ raise SympifyError("Cannot parse %s." % repr(s))
77
+ a = Transform(local_dict, global_dict).visit(a)
78
+ e = compile(a, "<string>", "eval")
79
+ return eval(e, global_dict, local_dict)
evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/autolev/Autolev.g4 ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ grammar Autolev;
2
+
3
+ options {
4
+ language = Python3;
5
+ }
6
+
7
+ prog: stat+;
8
+
9
+ stat: varDecl
10
+ | functionCall
11
+ | codeCommands
12
+ | massDecl
13
+ | inertiaDecl
14
+ | assignment
15
+ | settings
16
+ ;
17
+
18
+ assignment: vec equals expr #vecAssign
19
+ | ID '[' index ']' equals expr #indexAssign
20
+ | ID diff? equals expr #regularAssign;
21
+
22
+ equals: ('='|'+='|'-='|':='|'*='|'/='|'^=');
23
+
24
+ index: expr (',' expr)* ;
25
+
26
+ diff: ('\'')+;
27
+
28
+ functionCall: ID '(' (expr (',' expr)*)? ')'
29
+ | (Mass|Inertia) '(' (ID (',' ID)*)? ')';
30
+
31
+ varDecl: varType varDecl2 (',' varDecl2)*;
32
+
33
+ varType: Newtonian|Frames|Bodies|Particles|Points|Constants
34
+ | Specifieds|Imaginary|Variables ('\'')*|MotionVariables ('\'')*;
35
+
36
+ varDecl2: ID ('{' INT ',' INT '}')? (('{' INT ':' INT (',' INT ':' INT)* '}'))? ('{' INT '}')? ('+'|'-')? ('\'')* ('=' expr)?;
37
+
38
+ ranges: ('{' INT ':' INT (',' INT ':' INT)* '}');
39
+
40
+ massDecl: Mass massDecl2 (',' massDecl2)*;
41
+
42
+ massDecl2: ID '=' expr;
43
+
44
+ inertiaDecl: Inertia ID ('(' ID ')')? (',' expr)+;
45
+
46
+ matrix: '[' expr ((','|';') expr)* ']';
47
+ matrixInOutput: (ID (ID '=' (FLOAT|INT)?))|FLOAT|INT;
48
+
49
+ codeCommands: units
50
+ | inputs
51
+ | outputs
52
+ | codegen
53
+ | commands;
54
+
55
+ settings: ID (EXP|ID|FLOAT|INT)?;
56
+
57
+ units: UnitSystem ID (',' ID)*;
58
+ inputs: Input inputs2 (',' inputs2)*;
59
+ id_diff: ID diff?;
60
+ inputs2: id_diff '=' expr expr?;
61
+ outputs: Output outputs2 (',' outputs2)*;
62
+ outputs2: expr expr?;
63
+ codegen: ID functionCall ('['matrixInOutput (',' matrixInOutput)*']')? ID'.'ID;
64
+
65
+ commands: Save ID'.'ID
66
+ | Encode ID (',' ID)*;
67
+
68
+ vec: ID ('>')+
69
+ | '0>'
70
+ | '1>>';
71
+
72
+ expr: expr '^'<assoc=right> expr # Exponent
73
+ | expr ('*'|'/') expr # MulDiv
74
+ | expr ('+'|'-') expr # AddSub
75
+ | EXP # exp
76
+ | '-' expr # negativeOne
77
+ | FLOAT # float
78
+ | INT # int
79
+ | ID('\'')* # id
80
+ | vec # VectorOrDyadic
81
+ | ID '['expr (',' expr)* ']' # Indexing
82
+ | functionCall # function
83
+ | matrix # matrices
84
+ | '(' expr ')' # parens
85
+ | expr '=' expr # idEqualsExpr
86
+ | expr ':' expr # colon
87
+ | ID? ranges ('\'')* # rangess
88
+ ;
89
+
90
+ // These are to take care of the case insensitivity of Autolev.
91
+ Mass: ('M'|'m')('A'|'a')('S'|'s')('S'|'s');
92
+ Inertia: ('I'|'i')('N'|'n')('E'|'e')('R'|'r')('T'|'t')('I'|'i')('A'|'a');
93
+ Input: ('I'|'i')('N'|'n')('P'|'p')('U'|'u')('T'|'t')('S'|'s')?;
94
+ Output: ('O'|'o')('U'|'u')('T'|'t')('P'|'p')('U'|'u')('T'|'t');
95
+ Save: ('S'|'s')('A'|'a')('V'|'v')('E'|'e');
96
+ UnitSystem: ('U'|'u')('N'|'n')('I'|'i')('T'|'t')('S'|'s')('Y'|'y')('S'|'s')('T'|'t')('E'|'e')('M'|'m');
97
+ Encode: ('E'|'e')('N'|'n')('C'|'c')('O'|'o')('D'|'d')('E'|'e');
98
+ Newtonian: ('N'|'n')('E'|'e')('W'|'w')('T'|'t')('O'|'o')('N'|'n')('I'|'i')('A'|'a')('N'|'n');
99
+ Frames: ('F'|'f')('R'|'r')('A'|'a')('M'|'m')('E'|'e')('S'|'s')?;
100
+ Bodies: ('B'|'b')('O'|'o')('D'|'d')('I'|'i')('E'|'e')('S'|'s')?;
101
+ Particles: ('P'|'p')('A'|'a')('R'|'r')('T'|'t')('I'|'i')('C'|'c')('L'|'l')('E'|'e')('S'|'s')?;
102
+ Points: ('P'|'p')('O'|'o')('I'|'i')('N'|'n')('T'|'t')('S'|'s')?;
103
+ Constants: ('C'|'c')('O'|'o')('N'|'n')('S'|'s')('T'|'t')('A'|'a')('N'|'n')('T'|'t')('S'|'s')?;
104
+ Specifieds: ('S'|'s')('P'|'p')('E'|'e')('C'|'c')('I'|'i')('F'|'f')('I'|'i')('E'|'e')('D'|'d')('S'|'s')?;
105
+ Imaginary: ('I'|'i')('M'|'m')('A'|'a')('G'|'g')('I'|'i')('N'|'n')('A'|'a')('R'|'r')('Y'|'y');
106
+ Variables: ('V'|'v')('A'|'a')('R'|'r')('I'|'i')('A'|'a')('B'|'b')('L'|'l')('E'|'e')('S'|'s')?;
107
+ MotionVariables: ('M'|'m')('O'|'o')('T'|'t')('I'|'i')('O'|'o')('N'|'n')('V'|'v')('A'|'a')('R'|'r')('I'|'i')('A'|'a')('B'|'b')('L'|'l')('E'|'e')('S'|'s')?;
108
+
109
+ fragment DIFF: ('\'')*;
110
+ fragment DIGIT: [0-9];
111
+ INT: [0-9]+ ; // match integers
112
+ FLOAT: DIGIT+ '.' DIGIT*
113
+ | '.' DIGIT+;
114
+ EXP: FLOAT 'E' INT
115
+ | FLOAT 'E' '-' INT;
116
+ LINE_COMMENT : '%' .*? '\r'? '\n' -> skip ;
117
+ ID: [a-zA-Z][a-zA-Z0-9_]*;
118
+ WS: [ \t\r\n&]+ -> skip ; // toss out whitespace
evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/autolev/__init__.py ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sympy.external import import_module
2
+ from sympy.utilities.decorator import doctest_depends_on
3
+
4
+ @doctest_depends_on(modules=('antlr4',))
5
+ def parse_autolev(autolev_code, include_numeric=False):
6
+ """Parses Autolev code (version 4.1) to SymPy code.
7
+
8
+ Parameters
9
+ =========
10
+ autolev_code : Can be an str or any object with a readlines() method (such as a file handle or StringIO).
11
+ include_numeric : boolean, optional
12
+ If True NumPy, PyDy, or other numeric code is included for numeric evaluation lines in the Autolev code.
13
+
14
+ Returns
15
+ =======
16
+ sympy_code : str
17
+ Equivalent SymPy and/or numpy/pydy code as the input code.
18
+
19
+
20
+ Example (Double Pendulum)
21
+ =========================
22
+ >>> my_al_text = ("MOTIONVARIABLES' Q{2}', U{2}'",
23
+ ... "CONSTANTS L,M,G",
24
+ ... "NEWTONIAN N",
25
+ ... "FRAMES A,B",
26
+ ... "SIMPROT(N, A, 3, Q1)",
27
+ ... "SIMPROT(N, B, 3, Q2)",
28
+ ... "W_A_N>=U1*N3>",
29
+ ... "W_B_N>=U2*N3>",
30
+ ... "POINT O",
31
+ ... "PARTICLES P,R",
32
+ ... "P_O_P> = L*A1>",
33
+ ... "P_P_R> = L*B1>",
34
+ ... "V_O_N> = 0>",
35
+ ... "V2PTS(N, A, O, P)",
36
+ ... "V2PTS(N, B, P, R)",
37
+ ... "MASS P=M, R=M",
38
+ ... "Q1' = U1",
39
+ ... "Q2' = U2",
40
+ ... "GRAVITY(G*N1>)",
41
+ ... "ZERO = FR() + FRSTAR()",
42
+ ... "KANE()",
43
+ ... "INPUT M=1,G=9.81,L=1",
44
+ ... "INPUT Q1=.1,Q2=.2,U1=0,U2=0",
45
+ ... "INPUT TFINAL=10, INTEGSTP=.01",
46
+ ... "CODE DYNAMICS() some_filename.c")
47
+ >>> my_al_text = '\\n'.join(my_al_text)
48
+ >>> from sympy.parsing.autolev import parse_autolev
49
+ >>> print(parse_autolev(my_al_text, include_numeric=True))
50
+ import sympy.physics.mechanics as _me
51
+ import sympy as _sm
52
+ import math as m
53
+ import numpy as _np
54
+ <BLANKLINE>
55
+ q1, q2, u1, u2 = _me.dynamicsymbols('q1 q2 u1 u2')
56
+ q1_d, q2_d, u1_d, u2_d = _me.dynamicsymbols('q1_ q2_ u1_ u2_', 1)
57
+ l, m, g = _sm.symbols('l m g', real=True)
58
+ frame_n = _me.ReferenceFrame('n')
59
+ frame_a = _me.ReferenceFrame('a')
60
+ frame_b = _me.ReferenceFrame('b')
61
+ frame_a.orient(frame_n, 'Axis', [q1, frame_n.z])
62
+ frame_b.orient(frame_n, 'Axis', [q2, frame_n.z])
63
+ frame_a.set_ang_vel(frame_n, u1*frame_n.z)
64
+ frame_b.set_ang_vel(frame_n, u2*frame_n.z)
65
+ point_o = _me.Point('o')
66
+ particle_p = _me.Particle('p', _me.Point('p_pt'), _sm.Symbol('m'))
67
+ particle_r = _me.Particle('r', _me.Point('r_pt'), _sm.Symbol('m'))
68
+ particle_p.point.set_pos(point_o, l*frame_a.x)
69
+ particle_r.point.set_pos(particle_p.point, l*frame_b.x)
70
+ point_o.set_vel(frame_n, 0)
71
+ particle_p.point.v2pt_theory(point_o,frame_n,frame_a)
72
+ particle_r.point.v2pt_theory(particle_p.point,frame_n,frame_b)
73
+ particle_p.mass = m
74
+ particle_r.mass = m
75
+ force_p = particle_p.mass*(g*frame_n.x)
76
+ force_r = particle_r.mass*(g*frame_n.x)
77
+ kd_eqs = [q1_d - u1, q2_d - u2]
78
+ forceList = [(particle_p.point,particle_p.mass*(g*frame_n.x)), (particle_r.point,particle_r.mass*(g*frame_n.x))]
79
+ kane = _me.KanesMethod(frame_n, q_ind=[q1,q2], u_ind=[u1, u2], kd_eqs = kd_eqs)
80
+ fr, frstar = kane.kanes_equations([particle_p, particle_r], forceList)
81
+ zero = fr+frstar
82
+ from pydy.system import System
83
+ sys = System(kane, constants = {l:1, m:1, g:9.81},
84
+ specifieds={},
85
+ initial_conditions={q1:.1, q2:.2, u1:0, u2:0},
86
+ times = _np.linspace(0.0, 10, 10/.01))
87
+ <BLANKLINE>
88
+ y=sys.integrate()
89
+ <BLANKLINE>
90
+ """
91
+
92
+ _autolev = import_module(
93
+ 'sympy.parsing.autolev._parse_autolev_antlr',
94
+ import_kwargs={'fromlist': ['X']})
95
+
96
+ if _autolev is not None:
97
+ return _autolev.parse_autolev(autolev_code, include_numeric)
evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/autolev/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (3.8 kB). View file
 
evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/autolev/__pycache__/_build_autolev_antlr.cpython-310.pyc ADDED
Binary file (2.49 kB). View file
 
evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/autolev/__pycache__/_listener_autolev_antlr.cpython-310.pyc ADDED
Binary file (50.4 kB). View file
 
evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/autolev/__pycache__/_parse_autolev_antlr.cpython-310.pyc ADDED
Binary file (1.5 kB). View file
 
evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/autolev/_antlr/__init__.py ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ # *** GENERATED BY `setup.py antlr`, DO NOT EDIT BY HAND ***
2
+ #
3
+ # Generated with antlr4
4
+ # antlr4 is licensed under the BSD-3-Clause License
5
+ # https://github.com/antlr/antlr4/blob/master/LICENSE.txt
evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/autolev/_antlr/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (187 Bytes). View file
 
evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/autolev/_antlr/autolevlexer.py ADDED
@@ -0,0 +1,253 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # *** GENERATED BY `setup.py antlr`, DO NOT EDIT BY HAND ***
2
+ #
3
+ # Generated with antlr4
4
+ # antlr4 is licensed under the BSD-3-Clause License
5
+ # https://github.com/antlr/antlr4/blob/master/LICENSE.txt
6
+ from antlr4 import *
7
+ from io import StringIO
8
+ import sys
9
+ if sys.version_info[1] > 5:
10
+ from typing import TextIO
11
+ else:
12
+ from typing.io import TextIO
13
+
14
+
15
+ def serializedATN():
16
+ return [
17
+ 4,0,49,393,6,-1,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,
18
+ 2,6,7,6,2,7,7,7,2,8,7,8,2,9,7,9,2,10,7,10,2,11,7,11,2,12,7,12,2,
19
+ 13,7,13,2,14,7,14,2,15,7,15,2,16,7,16,2,17,7,17,2,18,7,18,2,19,7,
20
+ 19,2,20,7,20,2,21,7,21,2,22,7,22,2,23,7,23,2,24,7,24,2,25,7,25,2,
21
+ 26,7,26,2,27,7,27,2,28,7,28,2,29,7,29,2,30,7,30,2,31,7,31,2,32,7,
22
+ 32,2,33,7,33,2,34,7,34,2,35,7,35,2,36,7,36,2,37,7,37,2,38,7,38,2,
23
+ 39,7,39,2,40,7,40,2,41,7,41,2,42,7,42,2,43,7,43,2,44,7,44,2,45,7,
24
+ 45,2,46,7,46,2,47,7,47,2,48,7,48,2,49,7,49,2,50,7,50,1,0,1,0,1,1,
25
+ 1,1,1,2,1,2,1,3,1,3,1,3,1,4,1,4,1,4,1,5,1,5,1,5,1,6,1,6,1,6,1,7,
26
+ 1,7,1,7,1,8,1,8,1,8,1,9,1,9,1,10,1,10,1,11,1,11,1,12,1,12,1,13,1,
27
+ 13,1,14,1,14,1,15,1,15,1,16,1,16,1,17,1,17,1,18,1,18,1,19,1,19,1,
28
+ 20,1,20,1,21,1,21,1,21,1,22,1,22,1,22,1,22,1,23,1,23,1,24,1,24,1,
29
+ 25,1,25,1,26,1,26,1,26,1,26,1,26,1,27,1,27,1,27,1,27,1,27,1,27,1,
30
+ 27,1,27,1,28,1,28,1,28,1,28,1,28,1,28,3,28,184,8,28,1,29,1,29,1,
31
+ 29,1,29,1,29,1,29,1,29,1,30,1,30,1,30,1,30,1,30,1,31,1,31,1,31,1,
32
+ 31,1,31,1,31,1,31,1,31,1,31,1,31,1,31,1,32,1,32,1,32,1,32,1,32,1,
33
+ 32,1,32,1,33,1,33,1,33,1,33,1,33,1,33,1,33,1,33,1,33,1,33,1,34,1,
34
+ 34,1,34,1,34,1,34,1,34,3,34,232,8,34,1,35,1,35,1,35,1,35,1,35,1,
35
+ 35,3,35,240,8,35,1,36,1,36,1,36,1,36,1,36,1,36,1,36,1,36,1,36,3,
36
+ 36,251,8,36,1,37,1,37,1,37,1,37,1,37,1,37,3,37,259,8,37,1,38,1,38,
37
+ 1,38,1,38,1,38,1,38,1,38,1,38,1,38,3,38,270,8,38,1,39,1,39,1,39,
38
+ 1,39,1,39,1,39,1,39,1,39,1,39,1,39,3,39,282,8,39,1,40,1,40,1,40,
39
+ 1,40,1,40,1,40,1,40,1,40,1,40,1,40,1,41,1,41,1,41,1,41,1,41,1,41,
40
+ 1,41,1,41,1,41,3,41,303,8,41,1,42,1,42,1,42,1,42,1,42,1,42,1,42,
41
+ 1,42,1,42,1,42,1,42,1,42,1,42,1,42,1,42,3,42,320,8,42,1,43,5,43,
42
+ 323,8,43,10,43,12,43,326,9,43,1,44,1,44,1,45,4,45,331,8,45,11,45,
43
+ 12,45,332,1,46,4,46,336,8,46,11,46,12,46,337,1,46,1,46,5,46,342,
44
+ 8,46,10,46,12,46,345,9,46,1,46,1,46,4,46,349,8,46,11,46,12,46,350,
45
+ 3,46,353,8,46,1,47,1,47,1,47,1,47,1,47,1,47,1,47,1,47,1,47,3,47,
46
+ 364,8,47,1,48,1,48,5,48,368,8,48,10,48,12,48,371,9,48,1,48,3,48,
47
+ 374,8,48,1,48,1,48,1,48,1,48,1,49,1,49,5,49,382,8,49,10,49,12,49,
48
+ 385,9,49,1,50,4,50,388,8,50,11,50,12,50,389,1,50,1,50,1,369,0,51,
49
+ 1,1,3,2,5,3,7,4,9,5,11,6,13,7,15,8,17,9,19,10,21,11,23,12,25,13,
50
+ 27,14,29,15,31,16,33,17,35,18,37,19,39,20,41,21,43,22,45,23,47,24,
51
+ 49,25,51,26,53,27,55,28,57,29,59,30,61,31,63,32,65,33,67,34,69,35,
52
+ 71,36,73,37,75,38,77,39,79,40,81,41,83,42,85,43,87,0,89,0,91,44,
53
+ 93,45,95,46,97,47,99,48,101,49,1,0,24,2,0,77,77,109,109,2,0,65,65,
54
+ 97,97,2,0,83,83,115,115,2,0,73,73,105,105,2,0,78,78,110,110,2,0,
55
+ 69,69,101,101,2,0,82,82,114,114,2,0,84,84,116,116,2,0,80,80,112,
56
+ 112,2,0,85,85,117,117,2,0,79,79,111,111,2,0,86,86,118,118,2,0,89,
57
+ 89,121,121,2,0,67,67,99,99,2,0,68,68,100,100,2,0,87,87,119,119,2,
58
+ 0,70,70,102,102,2,0,66,66,98,98,2,0,76,76,108,108,2,0,71,71,103,
59
+ 103,1,0,48,57,2,0,65,90,97,122,4,0,48,57,65,90,95,95,97,122,4,0,
60
+ 9,10,13,13,32,32,38,38,410,0,1,1,0,0,0,0,3,1,0,0,0,0,5,1,0,0,0,0,
61
+ 7,1,0,0,0,0,9,1,0,0,0,0,11,1,0,0,0,0,13,1,0,0,0,0,15,1,0,0,0,0,17,
62
+ 1,0,0,0,0,19,1,0,0,0,0,21,1,0,0,0,0,23,1,0,0,0,0,25,1,0,0,0,0,27,
63
+ 1,0,0,0,0,29,1,0,0,0,0,31,1,0,0,0,0,33,1,0,0,0,0,35,1,0,0,0,0,37,
64
+ 1,0,0,0,0,39,1,0,0,0,0,41,1,0,0,0,0,43,1,0,0,0,0,45,1,0,0,0,0,47,
65
+ 1,0,0,0,0,49,1,0,0,0,0,51,1,0,0,0,0,53,1,0,0,0,0,55,1,0,0,0,0,57,
66
+ 1,0,0,0,0,59,1,0,0,0,0,61,1,0,0,0,0,63,1,0,0,0,0,65,1,0,0,0,0,67,
67
+ 1,0,0,0,0,69,1,0,0,0,0,71,1,0,0,0,0,73,1,0,0,0,0,75,1,0,0,0,0,77,
68
+ 1,0,0,0,0,79,1,0,0,0,0,81,1,0,0,0,0,83,1,0,0,0,0,85,1,0,0,0,0,91,
69
+ 1,0,0,0,0,93,1,0,0,0,0,95,1,0,0,0,0,97,1,0,0,0,0,99,1,0,0,0,0,101,
70
+ 1,0,0,0,1,103,1,0,0,0,3,105,1,0,0,0,5,107,1,0,0,0,7,109,1,0,0,0,
71
+ 9,112,1,0,0,0,11,115,1,0,0,0,13,118,1,0,0,0,15,121,1,0,0,0,17,124,
72
+ 1,0,0,0,19,127,1,0,0,0,21,129,1,0,0,0,23,131,1,0,0,0,25,133,1,0,
73
+ 0,0,27,135,1,0,0,0,29,137,1,0,0,0,31,139,1,0,0,0,33,141,1,0,0,0,
74
+ 35,143,1,0,0,0,37,145,1,0,0,0,39,147,1,0,0,0,41,149,1,0,0,0,43,151,
75
+ 1,0,0,0,45,154,1,0,0,0,47,158,1,0,0,0,49,160,1,0,0,0,51,162,1,0,
76
+ 0,0,53,164,1,0,0,0,55,169,1,0,0,0,57,177,1,0,0,0,59,185,1,0,0,0,
77
+ 61,192,1,0,0,0,63,197,1,0,0,0,65,208,1,0,0,0,67,215,1,0,0,0,69,225,
78
+ 1,0,0,0,71,233,1,0,0,0,73,241,1,0,0,0,75,252,1,0,0,0,77,260,1,0,
79
+ 0,0,79,271,1,0,0,0,81,283,1,0,0,0,83,293,1,0,0,0,85,304,1,0,0,0,
80
+ 87,324,1,0,0,0,89,327,1,0,0,0,91,330,1,0,0,0,93,352,1,0,0,0,95,363,
81
+ 1,0,0,0,97,365,1,0,0,0,99,379,1,0,0,0,101,387,1,0,0,0,103,104,5,
82
+ 91,0,0,104,2,1,0,0,0,105,106,5,93,0,0,106,4,1,0,0,0,107,108,5,61,
83
+ 0,0,108,6,1,0,0,0,109,110,5,43,0,0,110,111,5,61,0,0,111,8,1,0,0,
84
+ 0,112,113,5,45,0,0,113,114,5,61,0,0,114,10,1,0,0,0,115,116,5,58,
85
+ 0,0,116,117,5,61,0,0,117,12,1,0,0,0,118,119,5,42,0,0,119,120,5,61,
86
+ 0,0,120,14,1,0,0,0,121,122,5,47,0,0,122,123,5,61,0,0,123,16,1,0,
87
+ 0,0,124,125,5,94,0,0,125,126,5,61,0,0,126,18,1,0,0,0,127,128,5,44,
88
+ 0,0,128,20,1,0,0,0,129,130,5,39,0,0,130,22,1,0,0,0,131,132,5,40,
89
+ 0,0,132,24,1,0,0,0,133,134,5,41,0,0,134,26,1,0,0,0,135,136,5,123,
90
+ 0,0,136,28,1,0,0,0,137,138,5,125,0,0,138,30,1,0,0,0,139,140,5,58,
91
+ 0,0,140,32,1,0,0,0,141,142,5,43,0,0,142,34,1,0,0,0,143,144,5,45,
92
+ 0,0,144,36,1,0,0,0,145,146,5,59,0,0,146,38,1,0,0,0,147,148,5,46,
93
+ 0,0,148,40,1,0,0,0,149,150,5,62,0,0,150,42,1,0,0,0,151,152,5,48,
94
+ 0,0,152,153,5,62,0,0,153,44,1,0,0,0,154,155,5,49,0,0,155,156,5,62,
95
+ 0,0,156,157,5,62,0,0,157,46,1,0,0,0,158,159,5,94,0,0,159,48,1,0,
96
+ 0,0,160,161,5,42,0,0,161,50,1,0,0,0,162,163,5,47,0,0,163,52,1,0,
97
+ 0,0,164,165,7,0,0,0,165,166,7,1,0,0,166,167,7,2,0,0,167,168,7,2,
98
+ 0,0,168,54,1,0,0,0,169,170,7,3,0,0,170,171,7,4,0,0,171,172,7,5,0,
99
+ 0,172,173,7,6,0,0,173,174,7,7,0,0,174,175,7,3,0,0,175,176,7,1,0,
100
+ 0,176,56,1,0,0,0,177,178,7,3,0,0,178,179,7,4,0,0,179,180,7,8,0,0,
101
+ 180,181,7,9,0,0,181,183,7,7,0,0,182,184,7,2,0,0,183,182,1,0,0,0,
102
+ 183,184,1,0,0,0,184,58,1,0,0,0,185,186,7,10,0,0,186,187,7,9,0,0,
103
+ 187,188,7,7,0,0,188,189,7,8,0,0,189,190,7,9,0,0,190,191,7,7,0,0,
104
+ 191,60,1,0,0,0,192,193,7,2,0,0,193,194,7,1,0,0,194,195,7,11,0,0,
105
+ 195,196,7,5,0,0,196,62,1,0,0,0,197,198,7,9,0,0,198,199,7,4,0,0,199,
106
+ 200,7,3,0,0,200,201,7,7,0,0,201,202,7,2,0,0,202,203,7,12,0,0,203,
107
+ 204,7,2,0,0,204,205,7,7,0,0,205,206,7,5,0,0,206,207,7,0,0,0,207,
108
+ 64,1,0,0,0,208,209,7,5,0,0,209,210,7,4,0,0,210,211,7,13,0,0,211,
109
+ 212,7,10,0,0,212,213,7,14,0,0,213,214,7,5,0,0,214,66,1,0,0,0,215,
110
+ 216,7,4,0,0,216,217,7,5,0,0,217,218,7,15,0,0,218,219,7,7,0,0,219,
111
+ 220,7,10,0,0,220,221,7,4,0,0,221,222,7,3,0,0,222,223,7,1,0,0,223,
112
+ 224,7,4,0,0,224,68,1,0,0,0,225,226,7,16,0,0,226,227,7,6,0,0,227,
113
+ 228,7,1,0,0,228,229,7,0,0,0,229,231,7,5,0,0,230,232,7,2,0,0,231,
114
+ 230,1,0,0,0,231,232,1,0,0,0,232,70,1,0,0,0,233,234,7,17,0,0,234,
115
+ 235,7,10,0,0,235,236,7,14,0,0,236,237,7,3,0,0,237,239,7,5,0,0,238,
116
+ 240,7,2,0,0,239,238,1,0,0,0,239,240,1,0,0,0,240,72,1,0,0,0,241,242,
117
+ 7,8,0,0,242,243,7,1,0,0,243,244,7,6,0,0,244,245,7,7,0,0,245,246,
118
+ 7,3,0,0,246,247,7,13,0,0,247,248,7,18,0,0,248,250,7,5,0,0,249,251,
119
+ 7,2,0,0,250,249,1,0,0,0,250,251,1,0,0,0,251,74,1,0,0,0,252,253,7,
120
+ 8,0,0,253,254,7,10,0,0,254,255,7,3,0,0,255,256,7,4,0,0,256,258,7,
121
+ 7,0,0,257,259,7,2,0,0,258,257,1,0,0,0,258,259,1,0,0,0,259,76,1,0,
122
+ 0,0,260,261,7,13,0,0,261,262,7,10,0,0,262,263,7,4,0,0,263,264,7,
123
+ 2,0,0,264,265,7,7,0,0,265,266,7,1,0,0,266,267,7,4,0,0,267,269,7,
124
+ 7,0,0,268,270,7,2,0,0,269,268,1,0,0,0,269,270,1,0,0,0,270,78,1,0,
125
+ 0,0,271,272,7,2,0,0,272,273,7,8,0,0,273,274,7,5,0,0,274,275,7,13,
126
+ 0,0,275,276,7,3,0,0,276,277,7,16,0,0,277,278,7,3,0,0,278,279,7,5,
127
+ 0,0,279,281,7,14,0,0,280,282,7,2,0,0,281,280,1,0,0,0,281,282,1,0,
128
+ 0,0,282,80,1,0,0,0,283,284,7,3,0,0,284,285,7,0,0,0,285,286,7,1,0,
129
+ 0,286,287,7,19,0,0,287,288,7,3,0,0,288,289,7,4,0,0,289,290,7,1,0,
130
+ 0,290,291,7,6,0,0,291,292,7,12,0,0,292,82,1,0,0,0,293,294,7,11,0,
131
+ 0,294,295,7,1,0,0,295,296,7,6,0,0,296,297,7,3,0,0,297,298,7,1,0,
132
+ 0,298,299,7,17,0,0,299,300,7,18,0,0,300,302,7,5,0,0,301,303,7,2,
133
+ 0,0,302,301,1,0,0,0,302,303,1,0,0,0,303,84,1,0,0,0,304,305,7,0,0,
134
+ 0,305,306,7,10,0,0,306,307,7,7,0,0,307,308,7,3,0,0,308,309,7,10,
135
+ 0,0,309,310,7,4,0,0,310,311,7,11,0,0,311,312,7,1,0,0,312,313,7,6,
136
+ 0,0,313,314,7,3,0,0,314,315,7,1,0,0,315,316,7,17,0,0,316,317,7,18,
137
+ 0,0,317,319,7,5,0,0,318,320,7,2,0,0,319,318,1,0,0,0,319,320,1,0,
138
+ 0,0,320,86,1,0,0,0,321,323,5,39,0,0,322,321,1,0,0,0,323,326,1,0,
139
+ 0,0,324,322,1,0,0,0,324,325,1,0,0,0,325,88,1,0,0,0,326,324,1,0,0,
140
+ 0,327,328,7,20,0,0,328,90,1,0,0,0,329,331,7,20,0,0,330,329,1,0,0,
141
+ 0,331,332,1,0,0,0,332,330,1,0,0,0,332,333,1,0,0,0,333,92,1,0,0,0,
142
+ 334,336,3,89,44,0,335,334,1,0,0,0,336,337,1,0,0,0,337,335,1,0,0,
143
+ 0,337,338,1,0,0,0,338,339,1,0,0,0,339,343,5,46,0,0,340,342,3,89,
144
+ 44,0,341,340,1,0,0,0,342,345,1,0,0,0,343,341,1,0,0,0,343,344,1,0,
145
+ 0,0,344,353,1,0,0,0,345,343,1,0,0,0,346,348,5,46,0,0,347,349,3,89,
146
+ 44,0,348,347,1,0,0,0,349,350,1,0,0,0,350,348,1,0,0,0,350,351,1,0,
147
+ 0,0,351,353,1,0,0,0,352,335,1,0,0,0,352,346,1,0,0,0,353,94,1,0,0,
148
+ 0,354,355,3,93,46,0,355,356,5,69,0,0,356,357,3,91,45,0,357,364,1,
149
+ 0,0,0,358,359,3,93,46,0,359,360,5,69,0,0,360,361,5,45,0,0,361,362,
150
+ 3,91,45,0,362,364,1,0,0,0,363,354,1,0,0,0,363,358,1,0,0,0,364,96,
151
+ 1,0,0,0,365,369,5,37,0,0,366,368,9,0,0,0,367,366,1,0,0,0,368,371,
152
+ 1,0,0,0,369,370,1,0,0,0,369,367,1,0,0,0,370,373,1,0,0,0,371,369,
153
+ 1,0,0,0,372,374,5,13,0,0,373,372,1,0,0,0,373,374,1,0,0,0,374,375,
154
+ 1,0,0,0,375,376,5,10,0,0,376,377,1,0,0,0,377,378,6,48,0,0,378,98,
155
+ 1,0,0,0,379,383,7,21,0,0,380,382,7,22,0,0,381,380,1,0,0,0,382,385,
156
+ 1,0,0,0,383,381,1,0,0,0,383,384,1,0,0,0,384,100,1,0,0,0,385,383,
157
+ 1,0,0,0,386,388,7,23,0,0,387,386,1,0,0,0,388,389,1,0,0,0,389,387,
158
+ 1,0,0,0,389,390,1,0,0,0,390,391,1,0,0,0,391,392,6,50,0,0,392,102,
159
+ 1,0,0,0,21,0,183,231,239,250,258,269,281,302,319,324,332,337,343,
160
+ 350,352,363,369,373,383,389,1,6,0,0
161
+ ]
162
+
163
+ class AutolevLexer(Lexer):
164
+
165
+ atn = ATNDeserializer().deserialize(serializedATN())
166
+
167
+ decisionsToDFA = [ DFA(ds, i) for i, ds in enumerate(atn.decisionToState) ]
168
+
169
+ T__0 = 1
170
+ T__1 = 2
171
+ T__2 = 3
172
+ T__3 = 4
173
+ T__4 = 5
174
+ T__5 = 6
175
+ T__6 = 7
176
+ T__7 = 8
177
+ T__8 = 9
178
+ T__9 = 10
179
+ T__10 = 11
180
+ T__11 = 12
181
+ T__12 = 13
182
+ T__13 = 14
183
+ T__14 = 15
184
+ T__15 = 16
185
+ T__16 = 17
186
+ T__17 = 18
187
+ T__18 = 19
188
+ T__19 = 20
189
+ T__20 = 21
190
+ T__21 = 22
191
+ T__22 = 23
192
+ T__23 = 24
193
+ T__24 = 25
194
+ T__25 = 26
195
+ Mass = 27
196
+ Inertia = 28
197
+ Input = 29
198
+ Output = 30
199
+ Save = 31
200
+ UnitSystem = 32
201
+ Encode = 33
202
+ Newtonian = 34
203
+ Frames = 35
204
+ Bodies = 36
205
+ Particles = 37
206
+ Points = 38
207
+ Constants = 39
208
+ Specifieds = 40
209
+ Imaginary = 41
210
+ Variables = 42
211
+ MotionVariables = 43
212
+ INT = 44
213
+ FLOAT = 45
214
+ EXP = 46
215
+ LINE_COMMENT = 47
216
+ ID = 48
217
+ WS = 49
218
+
219
+ channelNames = [ u"DEFAULT_TOKEN_CHANNEL", u"HIDDEN" ]
220
+
221
+ modeNames = [ "DEFAULT_MODE" ]
222
+
223
+ literalNames = [ "<INVALID>",
224
+ "'['", "']'", "'='", "'+='", "'-='", "':='", "'*='", "'/='",
225
+ "'^='", "','", "'''", "'('", "')'", "'{'", "'}'", "':'", "'+'",
226
+ "'-'", "';'", "'.'", "'>'", "'0>'", "'1>>'", "'^'", "'*'", "'/'" ]
227
+
228
+ symbolicNames = [ "<INVALID>",
229
+ "Mass", "Inertia", "Input", "Output", "Save", "UnitSystem",
230
+ "Encode", "Newtonian", "Frames", "Bodies", "Particles", "Points",
231
+ "Constants", "Specifieds", "Imaginary", "Variables", "MotionVariables",
232
+ "INT", "FLOAT", "EXP", "LINE_COMMENT", "ID", "WS" ]
233
+
234
+ ruleNames = [ "T__0", "T__1", "T__2", "T__3", "T__4", "T__5", "T__6",
235
+ "T__7", "T__8", "T__9", "T__10", "T__11", "T__12", "T__13",
236
+ "T__14", "T__15", "T__16", "T__17", "T__18", "T__19",
237
+ "T__20", "T__21", "T__22", "T__23", "T__24", "T__25",
238
+ "Mass", "Inertia", "Input", "Output", "Save", "UnitSystem",
239
+ "Encode", "Newtonian", "Frames", "Bodies", "Particles",
240
+ "Points", "Constants", "Specifieds", "Imaginary", "Variables",
241
+ "MotionVariables", "DIFF", "DIGIT", "INT", "FLOAT", "EXP",
242
+ "LINE_COMMENT", "ID", "WS" ]
243
+
244
+ grammarFileName = "Autolev.g4"
245
+
246
+ def __init__(self, input=None, output:TextIO = sys.stdout):
247
+ super().__init__(input, output)
248
+ self.checkVersion("4.11.1")
249
+ self._interp = LexerATNSimulator(self, self.atn, self.decisionsToDFA, PredictionContextCache())
250
+ self._actions = None
251
+ self._predicates = None
252
+
253
+
evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/autolev/_antlr/autolevlistener.py ADDED
@@ -0,0 +1,421 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # *** GENERATED BY `setup.py antlr`, DO NOT EDIT BY HAND ***
2
+ #
3
+ # Generated with antlr4
4
+ # antlr4 is licensed under the BSD-3-Clause License
5
+ # https://github.com/antlr/antlr4/blob/master/LICENSE.txt
6
+ from antlr4 import *
7
+ if __name__ is not None and "." in __name__:
8
+ from .autolevparser import AutolevParser
9
+ else:
10
+ from autolevparser import AutolevParser
11
+
12
+ # This class defines a complete listener for a parse tree produced by AutolevParser.
13
+ class AutolevListener(ParseTreeListener):
14
+
15
+ # Enter a parse tree produced by AutolevParser#prog.
16
+ def enterProg(self, ctx:AutolevParser.ProgContext):
17
+ pass
18
+
19
+ # Exit a parse tree produced by AutolevParser#prog.
20
+ def exitProg(self, ctx:AutolevParser.ProgContext):
21
+ pass
22
+
23
+
24
+ # Enter a parse tree produced by AutolevParser#stat.
25
+ def enterStat(self, ctx:AutolevParser.StatContext):
26
+ pass
27
+
28
+ # Exit a parse tree produced by AutolevParser#stat.
29
+ def exitStat(self, ctx:AutolevParser.StatContext):
30
+ pass
31
+
32
+
33
+ # Enter a parse tree produced by AutolevParser#vecAssign.
34
+ def enterVecAssign(self, ctx:AutolevParser.VecAssignContext):
35
+ pass
36
+
37
+ # Exit a parse tree produced by AutolevParser#vecAssign.
38
+ def exitVecAssign(self, ctx:AutolevParser.VecAssignContext):
39
+ pass
40
+
41
+
42
+ # Enter a parse tree produced by AutolevParser#indexAssign.
43
+ def enterIndexAssign(self, ctx:AutolevParser.IndexAssignContext):
44
+ pass
45
+
46
+ # Exit a parse tree produced by AutolevParser#indexAssign.
47
+ def exitIndexAssign(self, ctx:AutolevParser.IndexAssignContext):
48
+ pass
49
+
50
+
51
+ # Enter a parse tree produced by AutolevParser#regularAssign.
52
+ def enterRegularAssign(self, ctx:AutolevParser.RegularAssignContext):
53
+ pass
54
+
55
+ # Exit a parse tree produced by AutolevParser#regularAssign.
56
+ def exitRegularAssign(self, ctx:AutolevParser.RegularAssignContext):
57
+ pass
58
+
59
+
60
+ # Enter a parse tree produced by AutolevParser#equals.
61
+ def enterEquals(self, ctx:AutolevParser.EqualsContext):
62
+ pass
63
+
64
+ # Exit a parse tree produced by AutolevParser#equals.
65
+ def exitEquals(self, ctx:AutolevParser.EqualsContext):
66
+ pass
67
+
68
+
69
+ # Enter a parse tree produced by AutolevParser#index.
70
+ def enterIndex(self, ctx:AutolevParser.IndexContext):
71
+ pass
72
+
73
+ # Exit a parse tree produced by AutolevParser#index.
74
+ def exitIndex(self, ctx:AutolevParser.IndexContext):
75
+ pass
76
+
77
+
78
+ # Enter a parse tree produced by AutolevParser#diff.
79
+ def enterDiff(self, ctx:AutolevParser.DiffContext):
80
+ pass
81
+
82
+ # Exit a parse tree produced by AutolevParser#diff.
83
+ def exitDiff(self, ctx:AutolevParser.DiffContext):
84
+ pass
85
+
86
+
87
+ # Enter a parse tree produced by AutolevParser#functionCall.
88
+ def enterFunctionCall(self, ctx:AutolevParser.FunctionCallContext):
89
+ pass
90
+
91
+ # Exit a parse tree produced by AutolevParser#functionCall.
92
+ def exitFunctionCall(self, ctx:AutolevParser.FunctionCallContext):
93
+ pass
94
+
95
+
96
+ # Enter a parse tree produced by AutolevParser#varDecl.
97
+ def enterVarDecl(self, ctx:AutolevParser.VarDeclContext):
98
+ pass
99
+
100
+ # Exit a parse tree produced by AutolevParser#varDecl.
101
+ def exitVarDecl(self, ctx:AutolevParser.VarDeclContext):
102
+ pass
103
+
104
+
105
+ # Enter a parse tree produced by AutolevParser#varType.
106
+ def enterVarType(self, ctx:AutolevParser.VarTypeContext):
107
+ pass
108
+
109
+ # Exit a parse tree produced by AutolevParser#varType.
110
+ def exitVarType(self, ctx:AutolevParser.VarTypeContext):
111
+ pass
112
+
113
+
114
+ # Enter a parse tree produced by AutolevParser#varDecl2.
115
+ def enterVarDecl2(self, ctx:AutolevParser.VarDecl2Context):
116
+ pass
117
+
118
+ # Exit a parse tree produced by AutolevParser#varDecl2.
119
+ def exitVarDecl2(self, ctx:AutolevParser.VarDecl2Context):
120
+ pass
121
+
122
+
123
+ # Enter a parse tree produced by AutolevParser#ranges.
124
+ def enterRanges(self, ctx:AutolevParser.RangesContext):
125
+ pass
126
+
127
+ # Exit a parse tree produced by AutolevParser#ranges.
128
+ def exitRanges(self, ctx:AutolevParser.RangesContext):
129
+ pass
130
+
131
+
132
+ # Enter a parse tree produced by AutolevParser#massDecl.
133
+ def enterMassDecl(self, ctx:AutolevParser.MassDeclContext):
134
+ pass
135
+
136
+ # Exit a parse tree produced by AutolevParser#massDecl.
137
+ def exitMassDecl(self, ctx:AutolevParser.MassDeclContext):
138
+ pass
139
+
140
+
141
+ # Enter a parse tree produced by AutolevParser#massDecl2.
142
+ def enterMassDecl2(self, ctx:AutolevParser.MassDecl2Context):
143
+ pass
144
+
145
+ # Exit a parse tree produced by AutolevParser#massDecl2.
146
+ def exitMassDecl2(self, ctx:AutolevParser.MassDecl2Context):
147
+ pass
148
+
149
+
150
+ # Enter a parse tree produced by AutolevParser#inertiaDecl.
151
+ def enterInertiaDecl(self, ctx:AutolevParser.InertiaDeclContext):
152
+ pass
153
+
154
+ # Exit a parse tree produced by AutolevParser#inertiaDecl.
155
+ def exitInertiaDecl(self, ctx:AutolevParser.InertiaDeclContext):
156
+ pass
157
+
158
+
159
+ # Enter a parse tree produced by AutolevParser#matrix.
160
+ def enterMatrix(self, ctx:AutolevParser.MatrixContext):
161
+ pass
162
+
163
+ # Exit a parse tree produced by AutolevParser#matrix.
164
+ def exitMatrix(self, ctx:AutolevParser.MatrixContext):
165
+ pass
166
+
167
+
168
+ # Enter a parse tree produced by AutolevParser#matrixInOutput.
169
+ def enterMatrixInOutput(self, ctx:AutolevParser.MatrixInOutputContext):
170
+ pass
171
+
172
+ # Exit a parse tree produced by AutolevParser#matrixInOutput.
173
+ def exitMatrixInOutput(self, ctx:AutolevParser.MatrixInOutputContext):
174
+ pass
175
+
176
+
177
+ # Enter a parse tree produced by AutolevParser#codeCommands.
178
+ def enterCodeCommands(self, ctx:AutolevParser.CodeCommandsContext):
179
+ pass
180
+
181
+ # Exit a parse tree produced by AutolevParser#codeCommands.
182
+ def exitCodeCommands(self, ctx:AutolevParser.CodeCommandsContext):
183
+ pass
184
+
185
+
186
+ # Enter a parse tree produced by AutolevParser#settings.
187
+ def enterSettings(self, ctx:AutolevParser.SettingsContext):
188
+ pass
189
+
190
+ # Exit a parse tree produced by AutolevParser#settings.
191
+ def exitSettings(self, ctx:AutolevParser.SettingsContext):
192
+ pass
193
+
194
+
195
+ # Enter a parse tree produced by AutolevParser#units.
196
+ def enterUnits(self, ctx:AutolevParser.UnitsContext):
197
+ pass
198
+
199
+ # Exit a parse tree produced by AutolevParser#units.
200
+ def exitUnits(self, ctx:AutolevParser.UnitsContext):
201
+ pass
202
+
203
+
204
+ # Enter a parse tree produced by AutolevParser#inputs.
205
+ def enterInputs(self, ctx:AutolevParser.InputsContext):
206
+ pass
207
+
208
+ # Exit a parse tree produced by AutolevParser#inputs.
209
+ def exitInputs(self, ctx:AutolevParser.InputsContext):
210
+ pass
211
+
212
+
213
+ # Enter a parse tree produced by AutolevParser#id_diff.
214
+ def enterId_diff(self, ctx:AutolevParser.Id_diffContext):
215
+ pass
216
+
217
+ # Exit a parse tree produced by AutolevParser#id_diff.
218
+ def exitId_diff(self, ctx:AutolevParser.Id_diffContext):
219
+ pass
220
+
221
+
222
+ # Enter a parse tree produced by AutolevParser#inputs2.
223
+ def enterInputs2(self, ctx:AutolevParser.Inputs2Context):
224
+ pass
225
+
226
+ # Exit a parse tree produced by AutolevParser#inputs2.
227
+ def exitInputs2(self, ctx:AutolevParser.Inputs2Context):
228
+ pass
229
+
230
+
231
+ # Enter a parse tree produced by AutolevParser#outputs.
232
+ def enterOutputs(self, ctx:AutolevParser.OutputsContext):
233
+ pass
234
+
235
+ # Exit a parse tree produced by AutolevParser#outputs.
236
+ def exitOutputs(self, ctx:AutolevParser.OutputsContext):
237
+ pass
238
+
239
+
240
+ # Enter a parse tree produced by AutolevParser#outputs2.
241
+ def enterOutputs2(self, ctx:AutolevParser.Outputs2Context):
242
+ pass
243
+
244
+ # Exit a parse tree produced by AutolevParser#outputs2.
245
+ def exitOutputs2(self, ctx:AutolevParser.Outputs2Context):
246
+ pass
247
+
248
+
249
+ # Enter a parse tree produced by AutolevParser#codegen.
250
+ def enterCodegen(self, ctx:AutolevParser.CodegenContext):
251
+ pass
252
+
253
+ # Exit a parse tree produced by AutolevParser#codegen.
254
+ def exitCodegen(self, ctx:AutolevParser.CodegenContext):
255
+ pass
256
+
257
+
258
+ # Enter a parse tree produced by AutolevParser#commands.
259
+ def enterCommands(self, ctx:AutolevParser.CommandsContext):
260
+ pass
261
+
262
+ # Exit a parse tree produced by AutolevParser#commands.
263
+ def exitCommands(self, ctx:AutolevParser.CommandsContext):
264
+ pass
265
+
266
+
267
+ # Enter a parse tree produced by AutolevParser#vec.
268
+ def enterVec(self, ctx:AutolevParser.VecContext):
269
+ pass
270
+
271
+ # Exit a parse tree produced by AutolevParser#vec.
272
+ def exitVec(self, ctx:AutolevParser.VecContext):
273
+ pass
274
+
275
+
276
+ # Enter a parse tree produced by AutolevParser#parens.
277
+ def enterParens(self, ctx:AutolevParser.ParensContext):
278
+ pass
279
+
280
+ # Exit a parse tree produced by AutolevParser#parens.
281
+ def exitParens(self, ctx:AutolevParser.ParensContext):
282
+ pass
283
+
284
+
285
+ # Enter a parse tree produced by AutolevParser#VectorOrDyadic.
286
+ def enterVectorOrDyadic(self, ctx:AutolevParser.VectorOrDyadicContext):
287
+ pass
288
+
289
+ # Exit a parse tree produced by AutolevParser#VectorOrDyadic.
290
+ def exitVectorOrDyadic(self, ctx:AutolevParser.VectorOrDyadicContext):
291
+ pass
292
+
293
+
294
+ # Enter a parse tree produced by AutolevParser#Exponent.
295
+ def enterExponent(self, ctx:AutolevParser.ExponentContext):
296
+ pass
297
+
298
+ # Exit a parse tree produced by AutolevParser#Exponent.
299
+ def exitExponent(self, ctx:AutolevParser.ExponentContext):
300
+ pass
301
+
302
+
303
+ # Enter a parse tree produced by AutolevParser#MulDiv.
304
+ def enterMulDiv(self, ctx:AutolevParser.MulDivContext):
305
+ pass
306
+
307
+ # Exit a parse tree produced by AutolevParser#MulDiv.
308
+ def exitMulDiv(self, ctx:AutolevParser.MulDivContext):
309
+ pass
310
+
311
+
312
+ # Enter a parse tree produced by AutolevParser#AddSub.
313
+ def enterAddSub(self, ctx:AutolevParser.AddSubContext):
314
+ pass
315
+
316
+ # Exit a parse tree produced by AutolevParser#AddSub.
317
+ def exitAddSub(self, ctx:AutolevParser.AddSubContext):
318
+ pass
319
+
320
+
321
+ # Enter a parse tree produced by AutolevParser#float.
322
+ def enterFloat(self, ctx:AutolevParser.FloatContext):
323
+ pass
324
+
325
+ # Exit a parse tree produced by AutolevParser#float.
326
+ def exitFloat(self, ctx:AutolevParser.FloatContext):
327
+ pass
328
+
329
+
330
+ # Enter a parse tree produced by AutolevParser#int.
331
+ def enterInt(self, ctx:AutolevParser.IntContext):
332
+ pass
333
+
334
+ # Exit a parse tree produced by AutolevParser#int.
335
+ def exitInt(self, ctx:AutolevParser.IntContext):
336
+ pass
337
+
338
+
339
+ # Enter a parse tree produced by AutolevParser#idEqualsExpr.
340
+ def enterIdEqualsExpr(self, ctx:AutolevParser.IdEqualsExprContext):
341
+ pass
342
+
343
+ # Exit a parse tree produced by AutolevParser#idEqualsExpr.
344
+ def exitIdEqualsExpr(self, ctx:AutolevParser.IdEqualsExprContext):
345
+ pass
346
+
347
+
348
+ # Enter a parse tree produced by AutolevParser#negativeOne.
349
+ def enterNegativeOne(self, ctx:AutolevParser.NegativeOneContext):
350
+ pass
351
+
352
+ # Exit a parse tree produced by AutolevParser#negativeOne.
353
+ def exitNegativeOne(self, ctx:AutolevParser.NegativeOneContext):
354
+ pass
355
+
356
+
357
+ # Enter a parse tree produced by AutolevParser#function.
358
+ def enterFunction(self, ctx:AutolevParser.FunctionContext):
359
+ pass
360
+
361
+ # Exit a parse tree produced by AutolevParser#function.
362
+ def exitFunction(self, ctx:AutolevParser.FunctionContext):
363
+ pass
364
+
365
+
366
+ # Enter a parse tree produced by AutolevParser#rangess.
367
+ def enterRangess(self, ctx:AutolevParser.RangessContext):
368
+ pass
369
+
370
+ # Exit a parse tree produced by AutolevParser#rangess.
371
+ def exitRangess(self, ctx:AutolevParser.RangessContext):
372
+ pass
373
+
374
+
375
+ # Enter a parse tree produced by AutolevParser#colon.
376
+ def enterColon(self, ctx:AutolevParser.ColonContext):
377
+ pass
378
+
379
+ # Exit a parse tree produced by AutolevParser#colon.
380
+ def exitColon(self, ctx:AutolevParser.ColonContext):
381
+ pass
382
+
383
+
384
+ # Enter a parse tree produced by AutolevParser#id.
385
+ def enterId(self, ctx:AutolevParser.IdContext):
386
+ pass
387
+
388
+ # Exit a parse tree produced by AutolevParser#id.
389
+ def exitId(self, ctx:AutolevParser.IdContext):
390
+ pass
391
+
392
+
393
+ # Enter a parse tree produced by AutolevParser#exp.
394
+ def enterExp(self, ctx:AutolevParser.ExpContext):
395
+ pass
396
+
397
+ # Exit a parse tree produced by AutolevParser#exp.
398
+ def exitExp(self, ctx:AutolevParser.ExpContext):
399
+ pass
400
+
401
+
402
+ # Enter a parse tree produced by AutolevParser#matrices.
403
+ def enterMatrices(self, ctx:AutolevParser.MatricesContext):
404
+ pass
405
+
406
+ # Exit a parse tree produced by AutolevParser#matrices.
407
+ def exitMatrices(self, ctx:AutolevParser.MatricesContext):
408
+ pass
409
+
410
+
411
+ # Enter a parse tree produced by AutolevParser#Indexing.
412
+ def enterIndexing(self, ctx:AutolevParser.IndexingContext):
413
+ pass
414
+
415
+ # Exit a parse tree produced by AutolevParser#Indexing.
416
+ def exitIndexing(self, ctx:AutolevParser.IndexingContext):
417
+ pass
418
+
419
+
420
+
421
+ del AutolevParser
evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/autolev/_antlr/autolevparser.py ADDED
The diff for this file is too large to render. See raw diff
 
evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/autolev/_build_autolev_antlr.py ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import subprocess
3
+ import glob
4
+
5
+ from sympy.utilities.misc import debug
6
+
7
+ here = os.path.dirname(__file__)
8
+ grammar_file = os.path.abspath(os.path.join(here, "Autolev.g4"))
9
+ dir_autolev_antlr = os.path.join(here, "_antlr")
10
+
11
+ header = '''\
12
+ # *** GENERATED BY `setup.py antlr`, DO NOT EDIT BY HAND ***
13
+ #
14
+ # Generated with antlr4
15
+ # antlr4 is licensed under the BSD-3-Clause License
16
+ # https://github.com/antlr/antlr4/blob/master/LICENSE.txt
17
+ '''
18
+
19
+
20
+ def check_antlr_version():
21
+ debug("Checking antlr4 version...")
22
+
23
+ try:
24
+ debug(subprocess.check_output(["antlr4"])
25
+ .decode('utf-8').split("\n")[0])
26
+ return True
27
+ except (subprocess.CalledProcessError, FileNotFoundError):
28
+ debug("The 'antlr4' command line tool is not installed, "
29
+ "or not on your PATH.\n"
30
+ "> Please refer to the README.md file for more information.")
31
+ return False
32
+
33
+
34
+ def build_parser(output_dir=dir_autolev_antlr):
35
+ check_antlr_version()
36
+
37
+ debug("Updating ANTLR-generated code in {}".format(output_dir))
38
+
39
+ if not os.path.exists(output_dir):
40
+ os.makedirs(output_dir)
41
+
42
+ with open(os.path.join(output_dir, "__init__.py"), "w+") as fp:
43
+ fp.write(header)
44
+
45
+ args = [
46
+ "antlr4",
47
+ grammar_file,
48
+ "-o", output_dir,
49
+ "-no-visitor",
50
+ ]
51
+
52
+ debug("Running code generation...\n\t$ {}".format(" ".join(args)))
53
+ subprocess.check_output(args, cwd=output_dir)
54
+
55
+ debug("Applying headers, removing unnecessary files and renaming...")
56
+ # Handle case insensitive file systems. If the files are already
57
+ # generated, they will be written to autolev* but Autolev*.* won't match them.
58
+ for path in (glob.glob(os.path.join(output_dir, "Autolev*.*")) or
59
+ glob.glob(os.path.join(output_dir, "autolev*.*"))):
60
+
61
+ # Remove files ending in .interp or .tokens as they are not needed.
62
+ if not path.endswith(".py"):
63
+ os.unlink(path)
64
+ continue
65
+
66
+ new_path = os.path.join(output_dir, os.path.basename(path).lower())
67
+ with open(path, 'r') as f:
68
+ lines = [line.rstrip().replace('AutolevParser import', 'autolevparser import') +'\n'
69
+ for line in f.readlines()]
70
+
71
+ os.unlink(path)
72
+
73
+ with open(new_path, "w") as out_file:
74
+ offset = 0
75
+ while lines[offset].startswith('#'):
76
+ offset += 1
77
+ out_file.write(header)
78
+ out_file.writelines(lines[offset:])
79
+
80
+ debug("\t{}".format(new_path))
81
+
82
+ return True
83
+
84
+
85
+ if __name__ == "__main__":
86
+ build_parser()
evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/autolev/_parse_autolev_antlr.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from importlib.metadata import version
2
+ from sympy.external import import_module
3
+
4
+
5
+ autolevparser = import_module('sympy.parsing.autolev._antlr.autolevparser',
6
+ import_kwargs={'fromlist': ['AutolevParser']})
7
+ autolevlexer = import_module('sympy.parsing.autolev._antlr.autolevlexer',
8
+ import_kwargs={'fromlist': ['AutolevLexer']})
9
+ autolevlistener = import_module('sympy.parsing.autolev._antlr.autolevlistener',
10
+ import_kwargs={'fromlist': ['AutolevListener']})
11
+
12
+ AutolevParser = getattr(autolevparser, 'AutolevParser', None)
13
+ AutolevLexer = getattr(autolevlexer, 'AutolevLexer', None)
14
+ AutolevListener = getattr(autolevlistener, 'AutolevListener', None)
15
+
16
+
17
+ def parse_autolev(autolev_code, include_numeric):
18
+ antlr4 = import_module('antlr4')
19
+ if not antlr4 or not version('antlr4-python3-runtime').startswith('4.11'):
20
+ raise ImportError("Autolev parsing requires the antlr4 Python package,"
21
+ " provided by pip (antlr4-python3-runtime)"
22
+ " conda (antlr-python-runtime), version 4.11")
23
+ try:
24
+ l = autolev_code.readlines()
25
+ input_stream = antlr4.InputStream("".join(l))
26
+ except Exception:
27
+ input_stream = antlr4.InputStream(autolev_code)
28
+
29
+ if AutolevListener:
30
+ from ._listener_autolev_antlr import MyListener
31
+ lexer = AutolevLexer(input_stream)
32
+ token_stream = antlr4.CommonTokenStream(lexer)
33
+ parser = AutolevParser(token_stream)
34
+ tree = parser.prog()
35
+ my_listener = MyListener(include_numeric)
36
+ walker = antlr4.ParseTreeWalker()
37
+ walker.walk(my_listener, tree)
38
+ return "".join(my_listener.output_code)
evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/ruletest9.al ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ % ruletest9.al
2
+ NEWTONIAN N
3
+ FRAMES A
4
+ A> = 0>
5
+ D>> = EXPRESS(1>>, A)
6
+
7
+ POINTS PO{2}
8
+ PARTICLES P{2}
9
+ MOTIONVARIABLES' C{3}'
10
+ BODIES R
11
+ P_P1_PO2> = C1*A1>
12
+ V> = 2*P_P1_PO2> + C2*A2>
13
+
14
+ W_A_N> = C3*A3>
15
+ V> = 2*W_A_N> + C2*A2>
16
+ W_R_N> = C3*A3>
17
+ V> = 2*W_R_N> + C2*A2>
18
+
19
+ ALF_A_N> = DT(W_A_N>, A)
20
+ V> = 2*ALF_A_N> + C2*A2>
21
+
22
+ V_P1_A> = C1*A1> + C3*A2>
23
+ A_RO_N> = C2*A2>
24
+ V_A> = CROSS(A_RO_N>, V_P1_A>)
25
+
26
+ X_B_C> = V_A>
27
+ X_B_D> = 2*X_B_C>
28
+ A_B_C_D_E> = X_B_D>*2
29
+
30
+ A_B_C = 2*C1*C2*C3
31
+ A_B_C += 2*C1
32
+ A_B_C := 3*C1
33
+
34
+ MOTIONVARIABLES' Q{2}', U{2}'
35
+ Q1' = U1
36
+ Q2' = U2
37
+
38
+ VARIABLES X'', Y''
39
+ SPECIFIED YY
40
+ Y'' = X*X'^2 + 1
41
+ YY = X*X'^2 + 1
42
+
43
+ M[1] = 2*X
44
+ M[2] = 2*Y
45
+ A = 2*M[1]
46
+
47
+ M = [1,2,3;4,5,6;7,8,9]
48
+ M[1, 2] = 5
49
+ A = M[1, 2]*2
50
+
51
+ FORCE_RO> = Q1*N1>
52
+ TORQUE_A> = Q2*N3>
53
+ FORCE_RO> = Q2*N2>
54
+ F> = FORCE_RO>*2
evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/c/__init__.py ADDED
@@ -0,0 +1 @@
 
 
1
+ """Used for translating C source code into a SymPy expression"""
evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/c/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (244 Bytes). View file
 
evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/c/__pycache__/c_parser.cpython-310.pyc ADDED
Binary file (25.8 kB). View file
 
evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/c/c_parser.py ADDED
@@ -0,0 +1,1058 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sympy.external import import_module
2
+ import os
3
+
4
+ cin = import_module('clang.cindex', import_kwargs = {'fromlist': ['cindex']})
5
+
6
+ """
7
+ This module contains all the necessary Classes and Function used to Parse C and
8
+ C++ code into SymPy expression
9
+ The module serves as a backend for SymPyExpression to parse C code
10
+ It is also dependent on Clang's AST and SymPy's Codegen AST.
11
+ The module only supports the features currently supported by the Clang and
12
+ codegen AST which will be updated as the development of codegen AST and this
13
+ module progresses.
14
+ You might find unexpected bugs and exceptions while using the module, feel free
15
+ to report them to the SymPy Issue Tracker
16
+
17
+ Features Supported
18
+ ==================
19
+
20
+ - Variable Declarations (integers and reals)
21
+ - Assignment (using integer & floating literal and function calls)
22
+ - Function Definitions and Declaration
23
+ - Function Calls
24
+ - Compound statements, Return statements
25
+
26
+ Notes
27
+ =====
28
+
29
+ The module is dependent on an external dependency which needs to be installed
30
+ to use the features of this module.
31
+
32
+ Clang: The C and C++ compiler which is used to extract an AST from the provided
33
+ C source code.
34
+
35
+ References
36
+ ==========
37
+
38
+ .. [1] https://github.com/sympy/sympy/issues
39
+ .. [2] https://clang.llvm.org/docs/
40
+ .. [3] https://clang.llvm.org/docs/IntroductionToTheClangAST.html
41
+
42
+ """
43
+
44
+ if cin:
45
+ from sympy.codegen.ast import (Variable, Integer, Float,
46
+ FunctionPrototype, FunctionDefinition, FunctionCall,
47
+ none, Return, Assignment, intc, int8, int16, int64,
48
+ uint8, uint16, uint32, uint64, float32, float64, float80,
49
+ aug_assign, bool_, While, CodeBlock)
50
+ from sympy.codegen.cnodes import (PreDecrement, PostDecrement,
51
+ PreIncrement, PostIncrement)
52
+ from sympy.core import Add, Mod, Mul, Pow, Rel
53
+ from sympy.logic.boolalg import And, as_Boolean, Not, Or
54
+ from sympy.core.symbol import Symbol
55
+ from sympy.core.sympify import sympify
56
+ from sympy.logic.boolalg import (false, true)
57
+ import sys
58
+ import tempfile
59
+
60
+ class BaseParser:
61
+ """Base Class for the C parser"""
62
+
63
+ def __init__(self):
64
+ """Initializes the Base parser creating a Clang AST index"""
65
+ self.index = cin.Index.create()
66
+
67
+ def diagnostics(self, out):
68
+ """Diagostics function for the Clang AST"""
69
+ for diag in self.tu.diagnostics:
70
+ # tu = translation unit
71
+ print('%s %s (line %s, col %s) %s' % (
72
+ {
73
+ 4: 'FATAL',
74
+ 3: 'ERROR',
75
+ 2: 'WARNING',
76
+ 1: 'NOTE',
77
+ 0: 'IGNORED',
78
+ }[diag.severity],
79
+ diag.location.file,
80
+ diag.location.line,
81
+ diag.location.column,
82
+ diag.spelling
83
+ ), file=out)
84
+
85
+ class CCodeConverter(BaseParser):
86
+ """The Code Convereter for Clang AST
87
+
88
+ The converter object takes the C source code or file as input and
89
+ converts them to SymPy Expressions.
90
+ """
91
+
92
+ def __init__(self):
93
+ """Initializes the code converter"""
94
+ super().__init__()
95
+ self._py_nodes = []
96
+ self._data_types = {
97
+ "void": {
98
+ cin.TypeKind.VOID: none
99
+ },
100
+ "bool": {
101
+ cin.TypeKind.BOOL: bool_
102
+ },
103
+ "int": {
104
+ cin.TypeKind.SCHAR: int8,
105
+ cin.TypeKind.SHORT: int16,
106
+ cin.TypeKind.INT: intc,
107
+ cin.TypeKind.LONG: int64,
108
+ cin.TypeKind.UCHAR: uint8,
109
+ cin.TypeKind.USHORT: uint16,
110
+ cin.TypeKind.UINT: uint32,
111
+ cin.TypeKind.ULONG: uint64
112
+ },
113
+ "float": {
114
+ cin.TypeKind.FLOAT: float32,
115
+ cin.TypeKind.DOUBLE: float64,
116
+ cin.TypeKind.LONGDOUBLE: float80
117
+ }
118
+ }
119
+
120
+ def parse(self, filename, flags):
121
+ """Function to parse a file with C source code
122
+
123
+ It takes the filename as an attribute and creates a Clang AST
124
+ Translation Unit parsing the file.
125
+ Then the transformation function is called on the translation unit,
126
+ whose reults are collected into a list which is returned by the
127
+ function.
128
+
129
+ Parameters
130
+ ==========
131
+
132
+ filename : string
133
+ Path to the C file to be parsed
134
+
135
+ flags: list
136
+ Arguments to be passed to Clang while parsing the C code
137
+
138
+ Returns
139
+ =======
140
+
141
+ py_nodes: list
142
+ A list of SymPy AST nodes
143
+
144
+ """
145
+ filepath = os.path.abspath(filename)
146
+ self.tu = self.index.parse(
147
+ filepath,
148
+ args=flags,
149
+ options=cin.TranslationUnit.PARSE_DETAILED_PROCESSING_RECORD
150
+ )
151
+ for child in self.tu.cursor.get_children():
152
+ if child.kind == cin.CursorKind.VAR_DECL or child.kind == cin.CursorKind.FUNCTION_DECL:
153
+ self._py_nodes.append(self.transform(child))
154
+ return self._py_nodes
155
+
156
+ def parse_str(self, source, flags):
157
+ """Function to parse a string with C source code
158
+
159
+ It takes the source code as an attribute, stores it in a temporary
160
+ file and creates a Clang AST Translation Unit parsing the file.
161
+ Then the transformation function is called on the translation unit,
162
+ whose reults are collected into a list which is returned by the
163
+ function.
164
+
165
+ Parameters
166
+ ==========
167
+
168
+ source : string
169
+ A string containing the C source code to be parsed
170
+
171
+ flags: list
172
+ Arguments to be passed to Clang while parsing the C code
173
+
174
+ Returns
175
+ =======
176
+
177
+ py_nodes: list
178
+ A list of SymPy AST nodes
179
+
180
+ """
181
+ file = tempfile.NamedTemporaryFile(mode = 'w+', suffix = '.cpp')
182
+ file.write(source)
183
+ file.seek(0)
184
+ self.tu = self.index.parse(
185
+ file.name,
186
+ args=flags,
187
+ options=cin.TranslationUnit.PARSE_DETAILED_PROCESSING_RECORD
188
+ )
189
+ file.close()
190
+ for child in self.tu.cursor.get_children():
191
+ if child.kind == cin.CursorKind.VAR_DECL or child.kind == cin.CursorKind.FUNCTION_DECL:
192
+ self._py_nodes.append(self.transform(child))
193
+ return self._py_nodes
194
+
195
+ def transform(self, node):
196
+ """Transformation Function for Clang AST nodes
197
+
198
+ It determines the kind of node and calls the respective
199
+ transformation function for that node.
200
+
201
+ Raises
202
+ ======
203
+
204
+ NotImplementedError : if the transformation for the provided node
205
+ is not implemented
206
+
207
+ """
208
+ handler = getattr(self, 'transform_%s' % node.kind.name.lower(), None)
209
+
210
+ if handler is None:
211
+ print(
212
+ "Ignoring node of type %s (%s)" % (
213
+ node.kind,
214
+ ' '.join(
215
+ t.spelling for t in node.get_tokens())
216
+ ),
217
+ file=sys.stderr
218
+ )
219
+
220
+ return handler(node)
221
+
222
+ def transform_var_decl(self, node):
223
+ """Transformation Function for Variable Declaration
224
+
225
+ Used to create nodes for variable declarations and assignments with
226
+ values or function call for the respective nodes in the clang AST
227
+
228
+ Returns
229
+ =======
230
+
231
+ A variable node as Declaration, with the initial value if given
232
+
233
+ Raises
234
+ ======
235
+
236
+ NotImplementedError : if called for data types not currently
237
+ implemented
238
+
239
+ Notes
240
+ =====
241
+
242
+ The function currently supports following data types:
243
+
244
+ Boolean:
245
+ bool, _Bool
246
+
247
+ Integer:
248
+ 8-bit: signed char and unsigned char
249
+ 16-bit: short, short int, signed short,
250
+ signed short int, unsigned short, unsigned short int
251
+ 32-bit: int, signed int, unsigned int
252
+ 64-bit: long, long int, signed long,
253
+ signed long int, unsigned long, unsigned long int
254
+
255
+ Floating point:
256
+ Single Precision: float
257
+ Double Precision: double
258
+ Extended Precision: long double
259
+
260
+ """
261
+ if node.type.kind in self._data_types["int"]:
262
+ type = self._data_types["int"][node.type.kind]
263
+ elif node.type.kind in self._data_types["float"]:
264
+ type = self._data_types["float"][node.type.kind]
265
+ elif node.type.kind in self._data_types["bool"]:
266
+ type = self._data_types["bool"][node.type.kind]
267
+ else:
268
+ raise NotImplementedError("Only bool, int "
269
+ "and float are supported")
270
+ try:
271
+ children = node.get_children()
272
+ child = next(children)
273
+
274
+ #ignoring namespace and type details for the variable
275
+ while child.kind == cin.CursorKind.NAMESPACE_REF or child.kind == cin.CursorKind.TYPE_REF:
276
+ child = next(children)
277
+
278
+ val = self.transform(child)
279
+
280
+ supported_rhs = [
281
+ cin.CursorKind.INTEGER_LITERAL,
282
+ cin.CursorKind.FLOATING_LITERAL,
283
+ cin.CursorKind.UNEXPOSED_EXPR,
284
+ cin.CursorKind.BINARY_OPERATOR,
285
+ cin.CursorKind.PAREN_EXPR,
286
+ cin.CursorKind.UNARY_OPERATOR,
287
+ cin.CursorKind.CXX_BOOL_LITERAL_EXPR
288
+ ]
289
+
290
+ if child.kind in supported_rhs:
291
+ if isinstance(val, str):
292
+ value = Symbol(val)
293
+ elif isinstance(val, bool):
294
+ if node.type.kind in self._data_types["int"]:
295
+ value = Integer(0) if val == False else Integer(1)
296
+ elif node.type.kind in self._data_types["float"]:
297
+ value = Float(0.0) if val == False else Float(1.0)
298
+ elif node.type.kind in self._data_types["bool"]:
299
+ value = sympify(val)
300
+ elif isinstance(val, (Integer, int, Float, float)):
301
+ if node.type.kind in self._data_types["int"]:
302
+ value = Integer(val)
303
+ elif node.type.kind in self._data_types["float"]:
304
+ value = Float(val)
305
+ elif node.type.kind in self._data_types["bool"]:
306
+ value = sympify(bool(val))
307
+ else:
308
+ value = val
309
+
310
+ return Variable(
311
+ node.spelling
312
+ ).as_Declaration(
313
+ type = type,
314
+ value = value
315
+ )
316
+
317
+ elif child.kind == cin.CursorKind.CALL_EXPR:
318
+ return Variable(
319
+ node.spelling
320
+ ).as_Declaration(
321
+ value = val
322
+ )
323
+
324
+ else:
325
+ raise NotImplementedError("Given "
326
+ "variable declaration \"{}\" "
327
+ "is not possible to parse yet!"
328
+ .format(" ".join(
329
+ t.spelling for t in node.get_tokens()
330
+ )
331
+ ))
332
+
333
+ except StopIteration:
334
+ return Variable(
335
+ node.spelling
336
+ ).as_Declaration(
337
+ type = type
338
+ )
339
+
340
+ def transform_function_decl(self, node):
341
+ """Transformation Function For Function Declaration
342
+
343
+ Used to create nodes for function declarations and definitions for
344
+ the respective nodes in the clang AST
345
+
346
+ Returns
347
+ =======
348
+
349
+ function : Codegen AST node
350
+ - FunctionPrototype node if function body is not present
351
+ - FunctionDefinition node if the function body is present
352
+
353
+
354
+ """
355
+
356
+ if node.result_type.kind in self._data_types["int"]:
357
+ ret_type = self._data_types["int"][node.result_type.kind]
358
+ elif node.result_type.kind in self._data_types["float"]:
359
+ ret_type = self._data_types["float"][node.result_type.kind]
360
+ elif node.result_type.kind in self._data_types["bool"]:
361
+ ret_type = self._data_types["bool"][node.result_type.kind]
362
+ elif node.result_type.kind in self._data_types["void"]:
363
+ ret_type = self._data_types["void"][node.result_type.kind]
364
+ else:
365
+ raise NotImplementedError("Only void, bool, int "
366
+ "and float are supported")
367
+ body = []
368
+ param = []
369
+
370
+ # Subsequent nodes will be the parameters for the function.
371
+ for child in node.get_children():
372
+ decl = self.transform(child)
373
+ if child.kind == cin.CursorKind.PARM_DECL:
374
+ param.append(decl)
375
+ elif child.kind == cin.CursorKind.COMPOUND_STMT:
376
+ for val in decl:
377
+ body.append(val)
378
+ else:
379
+ body.append(decl)
380
+
381
+ if body == []:
382
+ function = FunctionPrototype(
383
+ return_type = ret_type,
384
+ name = node.spelling,
385
+ parameters = param
386
+ )
387
+ else:
388
+ function = FunctionDefinition(
389
+ return_type = ret_type,
390
+ name = node.spelling,
391
+ parameters = param,
392
+ body = body
393
+ )
394
+ return function
395
+
396
+ def transform_parm_decl(self, node):
397
+ """Transformation function for Parameter Declaration
398
+
399
+ Used to create parameter nodes for the required functions for the
400
+ respective nodes in the clang AST
401
+
402
+ Returns
403
+ =======
404
+
405
+ param : Codegen AST Node
406
+ Variable node with the value and type of the variable
407
+
408
+ Raises
409
+ ======
410
+
411
+ ValueError if multiple children encountered in the parameter node
412
+
413
+ """
414
+ if node.type.kind in self._data_types["int"]:
415
+ type = self._data_types["int"][node.type.kind]
416
+ elif node.type.kind in self._data_types["float"]:
417
+ type = self._data_types["float"][node.type.kind]
418
+ elif node.type.kind in self._data_types["bool"]:
419
+ type = self._data_types["bool"][node.type.kind]
420
+ else:
421
+ raise NotImplementedError("Only bool, int "
422
+ "and float are supported")
423
+ try:
424
+ children = node.get_children()
425
+ child = next(children)
426
+
427
+ # Any namespace nodes can be ignored
428
+ while child.kind in [cin.CursorKind.NAMESPACE_REF,
429
+ cin.CursorKind.TYPE_REF,
430
+ cin.CursorKind.TEMPLATE_REF]:
431
+ child = next(children)
432
+
433
+ # If there is a child, it is the default value of the parameter.
434
+ lit = self.transform(child)
435
+ if node.type.kind in self._data_types["int"]:
436
+ val = Integer(lit)
437
+ elif node.type.kind in self._data_types["float"]:
438
+ val = Float(lit)
439
+ elif node.type.kind in self._data_types["bool"]:
440
+ val = sympify(bool(lit))
441
+ else:
442
+ raise NotImplementedError("Only bool, int "
443
+ "and float are supported")
444
+
445
+ param = Variable(
446
+ node.spelling
447
+ ).as_Declaration(
448
+ type = type,
449
+ value = val
450
+ )
451
+ except StopIteration:
452
+ param = Variable(
453
+ node.spelling
454
+ ).as_Declaration(
455
+ type = type
456
+ )
457
+
458
+ try:
459
+ self.transform(next(children))
460
+ raise ValueError("Can't handle multiple children on parameter")
461
+ except StopIteration:
462
+ pass
463
+
464
+ return param
465
+
466
+ def transform_integer_literal(self, node):
467
+ """Transformation function for integer literal
468
+
469
+ Used to get the value and type of the given integer literal.
470
+
471
+ Returns
472
+ =======
473
+
474
+ val : list
475
+ List with two arguments type and Value
476
+ type contains the type of the integer
477
+ value contains the value stored in the variable
478
+
479
+ Notes
480
+ =====
481
+
482
+ Only Base Integer type supported for now
483
+
484
+ """
485
+ try:
486
+ value = next(node.get_tokens()).spelling
487
+ except StopIteration:
488
+ # No tokens
489
+ value = node.literal
490
+ return int(value)
491
+
492
+ def transform_floating_literal(self, node):
493
+ """Transformation function for floating literal
494
+
495
+ Used to get the value and type of the given floating literal.
496
+
497
+ Returns
498
+ =======
499
+
500
+ val : list
501
+ List with two arguments type and Value
502
+ type contains the type of float
503
+ value contains the value stored in the variable
504
+
505
+ Notes
506
+ =====
507
+
508
+ Only Base Float type supported for now
509
+
510
+ """
511
+ try:
512
+ value = next(node.get_tokens()).spelling
513
+ except (StopIteration, ValueError):
514
+ # No tokens
515
+ value = node.literal
516
+ return float(value)
517
+
518
+ def transform_string_literal(self, node):
519
+ #TODO: No string type in AST
520
+ #type =
521
+ #try:
522
+ # value = next(node.get_tokens()).spelling
523
+ #except (StopIteration, ValueError):
524
+ # No tokens
525
+ # value = node.literal
526
+ #val = [type, value]
527
+ #return val
528
+ pass
529
+
530
+ def transform_character_literal(self, node):
531
+ """Transformation function for character literal
532
+
533
+ Used to get the value of the given character literal.
534
+
535
+ Returns
536
+ =======
537
+
538
+ val : int
539
+ val contains the ascii value of the character literal
540
+
541
+ Notes
542
+ =====
543
+
544
+ Only for cases where character is assigned to a integer value,
545
+ since character literal is not in SymPy AST
546
+
547
+ """
548
+ try:
549
+ value = next(node.get_tokens()).spelling
550
+ except (StopIteration, ValueError):
551
+ # No tokens
552
+ value = node.literal
553
+ return ord(str(value[1]))
554
+
555
+ def transform_cxx_bool_literal_expr(self, node):
556
+ """Transformation function for boolean literal
557
+
558
+ Used to get the value of the given boolean literal.
559
+
560
+ Returns
561
+ =======
562
+
563
+ value : bool
564
+ value contains the boolean value of the variable
565
+
566
+ """
567
+ try:
568
+ value = next(node.get_tokens()).spelling
569
+ except (StopIteration, ValueError):
570
+ value = node.literal
571
+ return True if value == 'true' else False
572
+
573
+ def transform_unexposed_decl(self,node):
574
+ """Transformation function for unexposed declarations"""
575
+ pass
576
+
577
+ def transform_unexposed_expr(self, node):
578
+ """Transformation function for unexposed expression
579
+
580
+ Unexposed expressions are used to wrap float, double literals and
581
+ expressions
582
+
583
+ Returns
584
+ =======
585
+
586
+ expr : Codegen AST Node
587
+ the result from the wrapped expression
588
+
589
+ None : NoneType
590
+ No childs are found for the node
591
+
592
+ Raises
593
+ ======
594
+
595
+ ValueError if the expression contains multiple children
596
+
597
+ """
598
+ # Ignore unexposed nodes; pass whatever is the first
599
+ # (and should be only) child unaltered.
600
+ try:
601
+ children = node.get_children()
602
+ expr = self.transform(next(children))
603
+ except StopIteration:
604
+ return None
605
+
606
+ try:
607
+ next(children)
608
+ raise ValueError("Unexposed expression has > 1 children.")
609
+ except StopIteration:
610
+ pass
611
+
612
+ return expr
613
+
614
+ def transform_decl_ref_expr(self, node):
615
+ """Returns the name of the declaration reference"""
616
+ return node.spelling
617
+
618
+ def transform_call_expr(self, node):
619
+ """Transformation function for a call expression
620
+
621
+ Used to create function call nodes for the function calls present
622
+ in the C code
623
+
624
+ Returns
625
+ =======
626
+
627
+ FunctionCall : Codegen AST Node
628
+ FunctionCall node with parameters if any parameters are present
629
+
630
+ """
631
+ param = []
632
+ children = node.get_children()
633
+ child = next(children)
634
+
635
+ while child.kind == cin.CursorKind.NAMESPACE_REF:
636
+ child = next(children)
637
+ while child.kind == cin.CursorKind.TYPE_REF:
638
+ child = next(children)
639
+
640
+ first_child = self.transform(child)
641
+ try:
642
+ for child in children:
643
+ arg = self.transform(child)
644
+ if child.kind == cin.CursorKind.INTEGER_LITERAL:
645
+ param.append(Integer(arg))
646
+ elif child.kind == cin.CursorKind.FLOATING_LITERAL:
647
+ param.append(Float(arg))
648
+ else:
649
+ param.append(arg)
650
+ return FunctionCall(first_child, param)
651
+
652
+ except StopIteration:
653
+ return FunctionCall(first_child)
654
+
655
+ def transform_return_stmt(self, node):
656
+ """Returns the Return Node for a return statement"""
657
+ return Return(next(node.get_children()).spelling)
658
+
659
+ def transform_compound_stmt(self, node):
660
+ """Transformation function for compond statemets
661
+
662
+ Returns
663
+ =======
664
+
665
+ expr : list
666
+ list of Nodes for the expressions present in the statement
667
+
668
+ None : NoneType
669
+ if the compound statement is empty
670
+
671
+ """
672
+ expr = []
673
+ children = node.get_children()
674
+
675
+ for child in children:
676
+ expr.append(self.transform(child))
677
+ return expr
678
+
679
+ def transform_decl_stmt(self, node):
680
+ """Transformation function for declaration statements
681
+
682
+ These statements are used to wrap different kinds of declararions
683
+ like variable or function declaration
684
+ The function calls the transformer function for the child of the
685
+ given node
686
+
687
+ Returns
688
+ =======
689
+
690
+ statement : Codegen AST Node
691
+ contains the node returned by the children node for the type of
692
+ declaration
693
+
694
+ Raises
695
+ ======
696
+
697
+ ValueError if multiple children present
698
+
699
+ """
700
+ try:
701
+ children = node.get_children()
702
+ statement = self.transform(next(children))
703
+ except StopIteration:
704
+ pass
705
+
706
+ try:
707
+ self.transform(next(children))
708
+ raise ValueError("Don't know how to handle multiple statements")
709
+ except StopIteration:
710
+ pass
711
+
712
+ return statement
713
+
714
+ def transform_paren_expr(self, node):
715
+ """Transformation function for Parenthesized expressions
716
+
717
+ Returns the result from its children nodes
718
+
719
+ """
720
+ return self.transform(next(node.get_children()))
721
+
722
+ def transform_compound_assignment_operator(self, node):
723
+ """Transformation function for handling shorthand operators
724
+
725
+ Returns
726
+ =======
727
+
728
+ augmented_assignment_expression: Codegen AST node
729
+ shorthand assignment expression represented as Codegen AST
730
+
731
+ Raises
732
+ ======
733
+
734
+ NotImplementedError
735
+ If the shorthand operator for bitwise operators
736
+ (~=, ^=, &=, |=, <<=, >>=) is encountered
737
+
738
+ """
739
+ return self.transform_binary_operator(node)
740
+
741
+ def transform_unary_operator(self, node):
742
+ """Transformation function for handling unary operators
743
+
744
+ Returns
745
+ =======
746
+
747
+ unary_expression: Codegen AST node
748
+ simplified unary expression represented as Codegen AST
749
+
750
+ Raises
751
+ ======
752
+
753
+ NotImplementedError
754
+ If dereferencing operator(*), address operator(&) or
755
+ bitwise NOT operator(~) is encountered
756
+
757
+ """
758
+ # supported operators list
759
+ operators_list = ['+', '-', '++', '--', '!']
760
+ tokens = list(node.get_tokens())
761
+
762
+ # it can be either pre increment/decrement or any other operator from the list
763
+ if tokens[0].spelling in operators_list:
764
+ child = self.transform(next(node.get_children()))
765
+ # (decl_ref) e.g.; int a = ++b; or simply ++b;
766
+ if isinstance(child, str):
767
+ if tokens[0].spelling == '+':
768
+ return Symbol(child)
769
+ if tokens[0].spelling == '-':
770
+ return Mul(Symbol(child), -1)
771
+ if tokens[0].spelling == '++':
772
+ return PreIncrement(Symbol(child))
773
+ if tokens[0].spelling == '--':
774
+ return PreDecrement(Symbol(child))
775
+ if tokens[0].spelling == '!':
776
+ return Not(Symbol(child))
777
+ # e.g.; int a = -1; or int b = -(1 + 2);
778
+ else:
779
+ if tokens[0].spelling == '+':
780
+ return child
781
+ if tokens[0].spelling == '-':
782
+ return Mul(child, -1)
783
+ if tokens[0].spelling == '!':
784
+ return Not(sympify(bool(child)))
785
+
786
+ # it can be either post increment/decrement
787
+ # since variable name is obtained in token[0].spelling
788
+ elif tokens[1].spelling in ['++', '--']:
789
+ child = self.transform(next(node.get_children()))
790
+ if tokens[1].spelling == '++':
791
+ return PostIncrement(Symbol(child))
792
+ if tokens[1].spelling == '--':
793
+ return PostDecrement(Symbol(child))
794
+ else:
795
+ raise NotImplementedError("Dereferencing operator, "
796
+ "Address operator and bitwise NOT operator "
797
+ "have not been implemented yet!")
798
+
799
+ def transform_binary_operator(self, node):
800
+ """Transformation function for handling binary operators
801
+
802
+ Returns
803
+ =======
804
+
805
+ binary_expression: Codegen AST node
806
+ simplified binary expression represented as Codegen AST
807
+
808
+ Raises
809
+ ======
810
+
811
+ NotImplementedError
812
+ If a bitwise operator or
813
+ unary operator(which is a child of any binary
814
+ operator in Clang AST) is encountered
815
+
816
+ """
817
+ # get all the tokens of assignment
818
+ # and store it in the tokens list
819
+ tokens = list(node.get_tokens())
820
+
821
+ # supported operators list
822
+ operators_list = ['+', '-', '*', '/', '%','=',
823
+ '>', '>=', '<', '<=', '==', '!=', '&&', '||', '+=', '-=',
824
+ '*=', '/=', '%=']
825
+
826
+ # this stack will contain variable content
827
+ # and type of variable in the rhs
828
+ combined_variables_stack = []
829
+
830
+ # this stack will contain operators
831
+ # to be processed in the rhs
832
+ operators_stack = []
833
+
834
+ # iterate through every token
835
+ for token in tokens:
836
+ # token is either '(', ')' or
837
+ # any of the supported operators from the operator list
838
+ if token.kind == cin.TokenKind.PUNCTUATION:
839
+
840
+ # push '(' to the operators stack
841
+ if token.spelling == '(':
842
+ operators_stack.append('(')
843
+
844
+ elif token.spelling == ')':
845
+ # keep adding the expression to the
846
+ # combined variables stack unless
847
+ # '(' is found
848
+ while (operators_stack
849
+ and operators_stack[-1] != '('):
850
+ if len(combined_variables_stack) < 2:
851
+ raise NotImplementedError(
852
+ "Unary operators as a part of "
853
+ "binary operators is not "
854
+ "supported yet!")
855
+ rhs = combined_variables_stack.pop()
856
+ lhs = combined_variables_stack.pop()
857
+ operator = operators_stack.pop()
858
+ combined_variables_stack.append(
859
+ self.perform_operation(
860
+ lhs, rhs, operator))
861
+
862
+ # pop '('
863
+ operators_stack.pop()
864
+
865
+ # token is an operator (supported)
866
+ elif token.spelling in operators_list:
867
+ while (operators_stack
868
+ and self.priority_of(token.spelling)
869
+ <= self.priority_of(
870
+ operators_stack[-1])):
871
+ if len(combined_variables_stack) < 2:
872
+ raise NotImplementedError(
873
+ "Unary operators as a part of "
874
+ "binary operators is not "
875
+ "supported yet!")
876
+ rhs = combined_variables_stack.pop()
877
+ lhs = combined_variables_stack.pop()
878
+ operator = operators_stack.pop()
879
+ combined_variables_stack.append(
880
+ self.perform_operation(
881
+ lhs, rhs, operator))
882
+
883
+ # push current operator
884
+ operators_stack.append(token.spelling)
885
+
886
+ # token is a bitwise operator
887
+ elif token.spelling in ['&', '|', '^', '<<', '>>']:
888
+ raise NotImplementedError(
889
+ "Bitwise operator has not been "
890
+ "implemented yet!")
891
+
892
+ # token is a shorthand bitwise operator
893
+ elif token.spelling in ['&=', '|=', '^=', '<<=',
894
+ '>>=']:
895
+ raise NotImplementedError(
896
+ "Shorthand bitwise operator has not been "
897
+ "implemented yet!")
898
+ else:
899
+ raise NotImplementedError(
900
+ "Given token {} is not implemented yet!"
901
+ .format(token.spelling))
902
+
903
+ # token is an identifier(variable)
904
+ elif token.kind == cin.TokenKind.IDENTIFIER:
905
+ combined_variables_stack.append(
906
+ [token.spelling, 'identifier'])
907
+
908
+ # token is a literal
909
+ elif token.kind == cin.TokenKind.LITERAL:
910
+ combined_variables_stack.append(
911
+ [token.spelling, 'literal'])
912
+
913
+ # token is a keyword, either true or false
914
+ elif (token.kind == cin.TokenKind.KEYWORD
915
+ and token.spelling in ['true', 'false']):
916
+ combined_variables_stack.append(
917
+ [token.spelling, 'boolean'])
918
+ else:
919
+ raise NotImplementedError(
920
+ "Given token {} is not implemented yet!"
921
+ .format(token.spelling))
922
+
923
+ # process remaining operators
924
+ while operators_stack:
925
+ if len(combined_variables_stack) < 2:
926
+ raise NotImplementedError(
927
+ "Unary operators as a part of "
928
+ "binary operators is not "
929
+ "supported yet!")
930
+ rhs = combined_variables_stack.pop()
931
+ lhs = combined_variables_stack.pop()
932
+ operator = operators_stack.pop()
933
+ combined_variables_stack.append(
934
+ self.perform_operation(lhs, rhs, operator))
935
+
936
+ return combined_variables_stack[-1][0]
937
+
938
+ def priority_of(self, op):
939
+ """To get the priority of given operator"""
940
+ if op in ['=', '+=', '-=', '*=', '/=', '%=']:
941
+ return 1
942
+ if op in ['&&', '||']:
943
+ return 2
944
+ if op in ['<', '<=', '>', '>=', '==', '!=']:
945
+ return 3
946
+ if op in ['+', '-']:
947
+ return 4
948
+ if op in ['*', '/', '%']:
949
+ return 5
950
+ return 0
951
+
952
+ def perform_operation(self, lhs, rhs, op):
953
+ """Performs operation supported by the SymPy core
954
+
955
+ Returns
956
+ =======
957
+
958
+ combined_variable: list
959
+ contains variable content and type of variable
960
+
961
+ """
962
+ lhs_value = self.get_expr_for_operand(lhs)
963
+ rhs_value = self.get_expr_for_operand(rhs)
964
+ if op == '+':
965
+ return [Add(lhs_value, rhs_value), 'expr']
966
+ if op == '-':
967
+ return [Add(lhs_value, -rhs_value), 'expr']
968
+ if op == '*':
969
+ return [Mul(lhs_value, rhs_value), 'expr']
970
+ if op == '/':
971
+ return [Mul(lhs_value, Pow(rhs_value, Integer(-1))), 'expr']
972
+ if op == '%':
973
+ return [Mod(lhs_value, rhs_value), 'expr']
974
+ if op in ['<', '<=', '>', '>=', '==', '!=']:
975
+ return [Rel(lhs_value, rhs_value, op), 'expr']
976
+ if op == '&&':
977
+ return [And(as_Boolean(lhs_value), as_Boolean(rhs_value)), 'expr']
978
+ if op == '||':
979
+ return [Or(as_Boolean(lhs_value), as_Boolean(rhs_value)), 'expr']
980
+ if op == '=':
981
+ return [Assignment(Variable(lhs_value), rhs_value), 'expr']
982
+ if op in ['+=', '-=', '*=', '/=', '%=']:
983
+ return [aug_assign(Variable(lhs_value), op[0], rhs_value), 'expr']
984
+
985
+ def get_expr_for_operand(self, combined_variable):
986
+ """Gives out SymPy Codegen AST node
987
+
988
+ AST node returned is corresponding to
989
+ combined variable passed.Combined variable contains
990
+ variable content and type of variable
991
+
992
+ """
993
+ if combined_variable[1] == 'identifier':
994
+ return Symbol(combined_variable[0])
995
+ if combined_variable[1] == 'literal':
996
+ if '.' in combined_variable[0]:
997
+ return Float(float(combined_variable[0]))
998
+ else:
999
+ return Integer(int(combined_variable[0]))
1000
+ if combined_variable[1] == 'expr':
1001
+ return combined_variable[0]
1002
+ if combined_variable[1] == 'boolean':
1003
+ return true if combined_variable[0] == 'true' else false
1004
+
1005
+ def transform_null_stmt(self, node):
1006
+ """Handles Null Statement and returns None"""
1007
+ return none
1008
+
1009
+ def transform_while_stmt(self, node):
1010
+ """Transformation function for handling while statement
1011
+
1012
+ Returns
1013
+ =======
1014
+
1015
+ while statement : Codegen AST Node
1016
+ contains the while statement node having condition and
1017
+ statement block
1018
+
1019
+ """
1020
+ children = node.get_children()
1021
+
1022
+ condition = self.transform(next(children))
1023
+ statements = self.transform(next(children))
1024
+
1025
+ if isinstance(statements, list):
1026
+ statement_block = CodeBlock(*statements)
1027
+ else:
1028
+ statement_block = CodeBlock(statements)
1029
+
1030
+ return While(condition, statement_block)
1031
+
1032
+
1033
+
1034
+ else:
1035
+ class CCodeConverter(): # type: ignore
1036
+ def __init__(self, *args, **kwargs):
1037
+ raise ImportError("Module not Installed")
1038
+
1039
+
1040
+ def parse_c(source):
1041
+ """Function for converting a C source code
1042
+
1043
+ The function reads the source code present in the given file and parses it
1044
+ to give out SymPy Expressions
1045
+
1046
+ Returns
1047
+ =======
1048
+
1049
+ src : list
1050
+ List of Python expression strings
1051
+
1052
+ """
1053
+ converter = CCodeConverter()
1054
+ if os.path.exists(source):
1055
+ src = converter.parse(source, flags = [])
1056
+ else:
1057
+ src = converter.parse_str(source, flags = [])
1058
+ return src
evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/latex/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ The MIT License (MIT)
2
+
3
+ Copyright 2016, latex2sympy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/latex/LaTeX.g4 ADDED
@@ -0,0 +1,312 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ ANTLR4 LaTeX Math Grammar
3
+
4
+ Ported from latex2sympy by @augustt198 https://github.com/augustt198/latex2sympy See license in
5
+ LICENSE.txt
6
+ */
7
+
8
+ /*
9
+ After changing this file, it is necessary to run `python setup.py antlr` in the root directory of
10
+ the repository. This will regenerate the code in `sympy/parsing/latex/_antlr/*.py`.
11
+ */
12
+
13
+ grammar LaTeX;
14
+
15
+ options {
16
+ language = Python3;
17
+ }
18
+
19
+ WS: [ \t\r\n]+ -> skip;
20
+ THINSPACE: ('\\,' | '\\thinspace') -> skip;
21
+ MEDSPACE: ('\\:' | '\\medspace') -> skip;
22
+ THICKSPACE: ('\\;' | '\\thickspace') -> skip;
23
+ QUAD: '\\quad' -> skip;
24
+ QQUAD: '\\qquad' -> skip;
25
+ NEGTHINSPACE: ('\\!' | '\\negthinspace') -> skip;
26
+ NEGMEDSPACE: '\\negmedspace' -> skip;
27
+ NEGTHICKSPACE: '\\negthickspace' -> skip;
28
+ CMD_LEFT: '\\left' -> skip;
29
+ CMD_RIGHT: '\\right' -> skip;
30
+
31
+ IGNORE:
32
+ (
33
+ '\\vrule'
34
+ | '\\vcenter'
35
+ | '\\vbox'
36
+ | '\\vskip'
37
+ | '\\vspace'
38
+ | '\\hfil'
39
+ | '\\*'
40
+ | '\\-'
41
+ | '\\.'
42
+ | '\\/'
43
+ | '\\"'
44
+ | '\\('
45
+ | '\\='
46
+ ) -> skip;
47
+
48
+ ADD: '+';
49
+ SUB: '-';
50
+ MUL: '*';
51
+ DIV: '/';
52
+
53
+ L_PAREN: '(';
54
+ R_PAREN: ')';
55
+ L_BRACE: '{';
56
+ R_BRACE: '}';
57
+ L_BRACE_LITERAL: '\\{';
58
+ R_BRACE_LITERAL: '\\}';
59
+ L_BRACKET: '[';
60
+ R_BRACKET: ']';
61
+
62
+ BAR: '|';
63
+
64
+ R_BAR: '\\right|';
65
+ L_BAR: '\\left|';
66
+
67
+ L_ANGLE: '\\langle';
68
+ R_ANGLE: '\\rangle';
69
+ FUNC_LIM: '\\lim';
70
+ LIM_APPROACH_SYM:
71
+ '\\to'
72
+ | '\\rightarrow'
73
+ | '\\Rightarrow'
74
+ | '\\longrightarrow'
75
+ | '\\Longrightarrow';
76
+ FUNC_INT:
77
+ '\\int'
78
+ | '\\int\\limits';
79
+ FUNC_SUM: '\\sum';
80
+ FUNC_PROD: '\\prod';
81
+
82
+ FUNC_EXP: '\\exp';
83
+ FUNC_LOG: '\\log';
84
+ FUNC_LG: '\\lg';
85
+ FUNC_LN: '\\ln';
86
+ FUNC_SIN: '\\sin';
87
+ FUNC_COS: '\\cos';
88
+ FUNC_TAN: '\\tan';
89
+ FUNC_CSC: '\\csc';
90
+ FUNC_SEC: '\\sec';
91
+ FUNC_COT: '\\cot';
92
+
93
+ FUNC_ARCSIN: '\\arcsin';
94
+ FUNC_ARCCOS: '\\arccos';
95
+ FUNC_ARCTAN: '\\arctan';
96
+ FUNC_ARCCSC: '\\arccsc';
97
+ FUNC_ARCSEC: '\\arcsec';
98
+ FUNC_ARCCOT: '\\arccot';
99
+
100
+ FUNC_SINH: '\\sinh';
101
+ FUNC_COSH: '\\cosh';
102
+ FUNC_TANH: '\\tanh';
103
+ FUNC_ARSINH: '\\arsinh';
104
+ FUNC_ARCOSH: '\\arcosh';
105
+ FUNC_ARTANH: '\\artanh';
106
+
107
+ L_FLOOR: '\\lfloor';
108
+ R_FLOOR: '\\rfloor';
109
+ L_CEIL: '\\lceil';
110
+ R_CEIL: '\\rceil';
111
+
112
+ FUNC_SQRT: '\\sqrt';
113
+ FUNC_OVERLINE: '\\overline';
114
+
115
+ CMD_TIMES: '\\times';
116
+ CMD_CDOT: '\\cdot';
117
+ CMD_DIV: '\\div';
118
+ CMD_FRAC:
119
+ '\\frac'
120
+ | '\\dfrac'
121
+ | '\\tfrac';
122
+ CMD_BINOM: '\\binom';
123
+ CMD_DBINOM: '\\dbinom';
124
+ CMD_TBINOM: '\\tbinom';
125
+
126
+ CMD_MATHIT: '\\mathit';
127
+
128
+ UNDERSCORE: '_';
129
+ CARET: '^';
130
+ COLON: ':';
131
+
132
+ fragment WS_CHAR: [ \t\r\n];
133
+ DIFFERENTIAL: 'd' WS_CHAR*? ([a-zA-Z] | '\\' [a-zA-Z]+);
134
+
135
+ LETTER: [a-zA-Z];
136
+ DIGIT: [0-9];
137
+
138
+ EQUAL: (('&' WS_CHAR*?)? '=') | ('=' (WS_CHAR*? '&')?);
139
+ NEQ: '\\neq';
140
+
141
+ LT: '<';
142
+ LTE: ('\\leq' | '\\le' | LTE_Q | LTE_S);
143
+ LTE_Q: '\\leqq';
144
+ LTE_S: '\\leqslant';
145
+
146
+ GT: '>';
147
+ GTE: ('\\geq' | '\\ge' | GTE_Q | GTE_S);
148
+ GTE_Q: '\\geqq';
149
+ GTE_S: '\\geqslant';
150
+
151
+ BANG: '!';
152
+
153
+ SINGLE_QUOTES: '\''+;
154
+
155
+ SYMBOL: '\\' [a-zA-Z]+;
156
+
157
+ math: relation;
158
+
159
+ relation:
160
+ relation (EQUAL | LT | LTE | GT | GTE | NEQ) relation
161
+ | expr;
162
+
163
+ equality: expr EQUAL expr;
164
+
165
+ expr: additive;
166
+
167
+ additive: additive (ADD | SUB) additive | mp;
168
+
169
+ // mult part
170
+ mp:
171
+ mp (MUL | CMD_TIMES | CMD_CDOT | DIV | CMD_DIV | COLON) mp
172
+ | unary;
173
+
174
+ mp_nofunc:
175
+ mp_nofunc (
176
+ MUL
177
+ | CMD_TIMES
178
+ | CMD_CDOT
179
+ | DIV
180
+ | CMD_DIV
181
+ | COLON
182
+ ) mp_nofunc
183
+ | unary_nofunc;
184
+
185
+ unary: (ADD | SUB) unary | postfix+;
186
+
187
+ unary_nofunc:
188
+ (ADD | SUB) unary_nofunc
189
+ | postfix postfix_nofunc*;
190
+
191
+ postfix: exp postfix_op*;
192
+ postfix_nofunc: exp_nofunc postfix_op*;
193
+ postfix_op: BANG | eval_at;
194
+
195
+ eval_at:
196
+ BAR (eval_at_sup | eval_at_sub | eval_at_sup eval_at_sub);
197
+
198
+ eval_at_sub: UNDERSCORE L_BRACE (expr | equality) R_BRACE;
199
+
200
+ eval_at_sup: CARET L_BRACE (expr | equality) R_BRACE;
201
+
202
+ exp: exp CARET (atom | L_BRACE expr R_BRACE) subexpr? | comp;
203
+
204
+ exp_nofunc:
205
+ exp_nofunc CARET (atom | L_BRACE expr R_BRACE) subexpr?
206
+ | comp_nofunc;
207
+
208
+ comp:
209
+ group
210
+ | abs_group
211
+ | func
212
+ | atom
213
+ | floor
214
+ | ceil;
215
+
216
+ comp_nofunc:
217
+ group
218
+ | abs_group
219
+ | atom
220
+ | floor
221
+ | ceil;
222
+
223
+ group:
224
+ L_PAREN expr R_PAREN
225
+ | L_BRACKET expr R_BRACKET
226
+ | L_BRACE expr R_BRACE
227
+ | L_BRACE_LITERAL expr R_BRACE_LITERAL;
228
+
229
+ abs_group: BAR expr BAR;
230
+
231
+ number: DIGIT+ (',' DIGIT DIGIT DIGIT)* ('.' DIGIT+)?;
232
+
233
+ atom: (LETTER | SYMBOL) (subexpr? SINGLE_QUOTES? | SINGLE_QUOTES? subexpr?)
234
+ | number
235
+ | DIFFERENTIAL
236
+ | mathit
237
+ | frac
238
+ | binom
239
+ | bra
240
+ | ket;
241
+
242
+ bra: L_ANGLE expr (R_BAR | BAR);
243
+ ket: (L_BAR | BAR) expr R_ANGLE;
244
+
245
+ mathit: CMD_MATHIT L_BRACE mathit_text R_BRACE;
246
+ mathit_text: LETTER*;
247
+
248
+ frac: CMD_FRAC (upperd = DIGIT | L_BRACE upper = expr R_BRACE)
249
+ (lowerd = DIGIT | L_BRACE lower = expr R_BRACE);
250
+
251
+ binom:
252
+ (CMD_BINOM | CMD_DBINOM | CMD_TBINOM) L_BRACE n = expr R_BRACE L_BRACE k = expr R_BRACE;
253
+
254
+ floor: L_FLOOR val = expr R_FLOOR;
255
+ ceil: L_CEIL val = expr R_CEIL;
256
+
257
+ func_normal:
258
+ FUNC_EXP
259
+ | FUNC_LOG
260
+ | FUNC_LG
261
+ | FUNC_LN
262
+ | FUNC_SIN
263
+ | FUNC_COS
264
+ | FUNC_TAN
265
+ | FUNC_CSC
266
+ | FUNC_SEC
267
+ | FUNC_COT
268
+ | FUNC_ARCSIN
269
+ | FUNC_ARCCOS
270
+ | FUNC_ARCTAN
271
+ | FUNC_ARCCSC
272
+ | FUNC_ARCSEC
273
+ | FUNC_ARCCOT
274
+ | FUNC_SINH
275
+ | FUNC_COSH
276
+ | FUNC_TANH
277
+ | FUNC_ARSINH
278
+ | FUNC_ARCOSH
279
+ | FUNC_ARTANH;
280
+
281
+ func:
282
+ func_normal (subexpr? supexpr? | supexpr? subexpr?) (
283
+ L_PAREN func_arg R_PAREN
284
+ | func_arg_noparens
285
+ )
286
+ | (LETTER | SYMBOL) (subexpr? SINGLE_QUOTES? | SINGLE_QUOTES? subexpr?) // e.g. f(x), f_1'(x)
287
+ L_PAREN args R_PAREN
288
+ | FUNC_INT (subexpr supexpr | supexpr subexpr)? (
289
+ additive? DIFFERENTIAL
290
+ | frac
291
+ | additive
292
+ )
293
+ | FUNC_SQRT (L_BRACKET root = expr R_BRACKET)? L_BRACE base = expr R_BRACE
294
+ | FUNC_OVERLINE L_BRACE base = expr R_BRACE
295
+ | (FUNC_SUM | FUNC_PROD) (subeq supexpr | supexpr subeq) mp
296
+ | FUNC_LIM limit_sub mp;
297
+
298
+ args: (expr ',' args) | expr;
299
+
300
+ limit_sub:
301
+ UNDERSCORE L_BRACE (LETTER | SYMBOL) LIM_APPROACH_SYM expr (
302
+ CARET ((L_BRACE (ADD | SUB) R_BRACE) | ADD | SUB)
303
+ )? R_BRACE;
304
+
305
+ func_arg: expr | (expr ',' func_arg);
306
+ func_arg_noparens: mp_nofunc;
307
+
308
+ subexpr: UNDERSCORE (atom | L_BRACE expr R_BRACE);
309
+ supexpr: CARET (atom | L_BRACE expr R_BRACE);
310
+
311
+ subeq: UNDERSCORE L_BRACE equality R_BRACE;
312
+ supeq: UNDERSCORE L_BRACE equality R_BRACE;
evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/latex/__init__.py ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sympy.external import import_module
2
+ from sympy.utilities.decorator import doctest_depends_on
3
+
4
+ from sympy.parsing.latex.lark import LarkLaTeXParser, TransformToSymPyExpr, parse_latex_lark # noqa
5
+
6
+ from .errors import LaTeXParsingError # noqa
7
+
8
+
9
+ __doctest_requires__ = {('parse_latex',): ['antlr4', 'lark']}
10
+
11
+
12
+ @doctest_depends_on(modules=('antlr4', 'lark'))
13
+ def parse_latex(s, strict=False, backend="antlr"):
14
+ r"""Converts the input LaTeX string ``s`` to a SymPy ``Expr``.
15
+
16
+ Parameters
17
+ ==========
18
+
19
+ s : str
20
+ The LaTeX string to parse. In Python source containing LaTeX,
21
+ *raw strings* (denoted with ``r"``, like this one) are preferred,
22
+ as LaTeX makes liberal use of the ``\`` character, which would
23
+ trigger escaping in normal Python strings.
24
+ backend : str, optional
25
+ Currently, there are two backends supported: ANTLR, and Lark.
26
+ The default setting is to use the ANTLR backend, which can be
27
+ changed to Lark if preferred.
28
+
29
+ Use ``backend="antlr"`` for the ANTLR-based parser, and
30
+ ``backend="lark"`` for the Lark-based parser.
31
+
32
+ The ``backend`` option is case-sensitive, and must be in
33
+ all lowercase.
34
+ strict : bool, optional
35
+ This option is only available with the ANTLR backend.
36
+
37
+ If True, raise an exception if the string cannot be parsed as
38
+ valid LaTeX. If False, try to recover gracefully from common
39
+ mistakes.
40
+
41
+ Examples
42
+ ========
43
+
44
+ >>> from sympy.parsing.latex import parse_latex
45
+ >>> expr = parse_latex(r"\frac {1 + \sqrt {\a}} {\b}")
46
+ >>> expr
47
+ (sqrt(a) + 1)/b
48
+ >>> expr.evalf(4, subs=dict(a=5, b=2))
49
+ 1.618
50
+ >>> func = parse_latex(r"\int_1^\alpha \dfrac{\mathrm{d}t}{t}", backend="lark")
51
+ >>> func.evalf(subs={"alpha": 2})
52
+ 0.693147180559945
53
+ """
54
+
55
+ if backend == "antlr":
56
+ _latex = import_module(
57
+ 'sympy.parsing.latex._parse_latex_antlr',
58
+ import_kwargs={'fromlist': ['X']})
59
+
60
+ if _latex is not None:
61
+ return _latex.parse_latex(s, strict)
62
+ elif backend == "lark":
63
+ return parse_latex_lark(s)
64
+ else:
65
+ raise NotImplementedError(f"Using the '{backend}' backend in the LaTeX" \
66
+ " parser is not supported.")
evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/latex/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (2.4 kB). View file
 
evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/latex/__pycache__/_build_latex_antlr.cpython-310.pyc ADDED
Binary file (2.61 kB). View file
 
evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/latex/__pycache__/_parse_latex_antlr.cpython-310.pyc ADDED
Binary file (13.7 kB). View file
 
evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/latex/__pycache__/errors.cpython-310.pyc ADDED
Binary file (350 Bytes). View file
 
evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/latex/_antlr/__init__.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ # *** GENERATED BY `setup.py antlr`, DO NOT EDIT BY HAND ***
2
+ #
3
+ # Generated from ../LaTeX.g4, derived from latex2sympy
4
+ # latex2sympy is licensed under the MIT license
5
+ # https://github.com/augustt198/latex2sympy/blob/master/LICENSE.txt
6
+ #
7
+ # Generated with antlr4
8
+ # antlr4 is licensed under the BSD-3-Clause License
9
+ # https://github.com/antlr/antlr4/blob/master/LICENSE.txt
evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/latex/_antlr/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (185 Bytes). View file
 
evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/latex/_antlr/__pycache__/latexlexer.cpython-310.pyc ADDED
Binary file (43.9 kB). View file
 
evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/latex/_antlr/latexlexer.py ADDED
@@ -0,0 +1,512 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # *** GENERATED BY `setup.py antlr`, DO NOT EDIT BY HAND ***
2
+ #
3
+ # Generated from ../LaTeX.g4, derived from latex2sympy
4
+ # latex2sympy is licensed under the MIT license
5
+ # https://github.com/augustt198/latex2sympy/blob/master/LICENSE.txt
6
+ #
7
+ # Generated with antlr4
8
+ # antlr4 is licensed under the BSD-3-Clause License
9
+ # https://github.com/antlr/antlr4/blob/master/LICENSE.txt
10
+ from antlr4 import *
11
+ from io import StringIO
12
+ import sys
13
+ if sys.version_info[1] > 5:
14
+ from typing import TextIO
15
+ else:
16
+ from typing.io import TextIO
17
+
18
+
19
+ def serializedATN():
20
+ return [
21
+ 4,0,91,911,6,-1,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,
22
+ 2,6,7,6,2,7,7,7,2,8,7,8,2,9,7,9,2,10,7,10,2,11,7,11,2,12,7,12,2,
23
+ 13,7,13,2,14,7,14,2,15,7,15,2,16,7,16,2,17,7,17,2,18,7,18,2,19,7,
24
+ 19,2,20,7,20,2,21,7,21,2,22,7,22,2,23,7,23,2,24,7,24,2,25,7,25,2,
25
+ 26,7,26,2,27,7,27,2,28,7,28,2,29,7,29,2,30,7,30,2,31,7,31,2,32,7,
26
+ 32,2,33,7,33,2,34,7,34,2,35,7,35,2,36,7,36,2,37,7,37,2,38,7,38,2,
27
+ 39,7,39,2,40,7,40,2,41,7,41,2,42,7,42,2,43,7,43,2,44,7,44,2,45,7,
28
+ 45,2,46,7,46,2,47,7,47,2,48,7,48,2,49,7,49,2,50,7,50,2,51,7,51,2,
29
+ 52,7,52,2,53,7,53,2,54,7,54,2,55,7,55,2,56,7,56,2,57,7,57,2,58,7,
30
+ 58,2,59,7,59,2,60,7,60,2,61,7,61,2,62,7,62,2,63,7,63,2,64,7,64,2,
31
+ 65,7,65,2,66,7,66,2,67,7,67,2,68,7,68,2,69,7,69,2,70,7,70,2,71,7,
32
+ 71,2,72,7,72,2,73,7,73,2,74,7,74,2,75,7,75,2,76,7,76,2,77,7,77,2,
33
+ 78,7,78,2,79,7,79,2,80,7,80,2,81,7,81,2,82,7,82,2,83,7,83,2,84,7,
34
+ 84,2,85,7,85,2,86,7,86,2,87,7,87,2,88,7,88,2,89,7,89,2,90,7,90,2,
35
+ 91,7,91,1,0,1,0,1,1,1,1,1,2,4,2,191,8,2,11,2,12,2,192,1,2,1,2,1,
36
+ 3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,3,3,209,8,3,1,3,1,
37
+ 3,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,3,4,224,8,4,1,4,1,
38
+ 4,1,5,1,5,1,5,1,5,1,5,1,5,1,5,1,5,1,5,1,5,1,5,1,5,1,5,3,5,241,8,
39
+ 5,1,5,1,5,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,7,1,7,1,7,1,7,1,7,1,
40
+ 7,1,7,1,7,1,7,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,
41
+ 8,1,8,1,8,3,8,277,8,8,1,8,1,8,1,9,1,9,1,9,1,9,1,9,1,9,1,9,1,9,1,
42
+ 9,1,9,1,9,1,9,1,9,1,9,1,9,1,10,1,10,1,10,1,10,1,10,1,10,1,10,1,10,
43
+ 1,10,1,10,1,10,1,10,1,10,1,10,1,10,1,10,1,10,1,11,1,11,1,11,1,11,
44
+ 1,11,1,11,1,11,1,11,1,12,1,12,1,12,1,12,1,12,1,12,1,12,1,12,1,12,
45
+ 1,13,1,13,1,13,1,13,1,13,1,13,1,13,1,13,1,13,1,13,1,13,1,13,1,13,
46
+ 1,13,1,13,1,13,1,13,1,13,1,13,1,13,1,13,1,13,1,13,1,13,1,13,1,13,
47
+ 1,13,1,13,1,13,1,13,1,13,1,13,1,13,1,13,1,13,1,13,1,13,1,13,1,13,
48
+ 1,13,1,13,1,13,1,13,1,13,1,13,1,13,1,13,1,13,1,13,1,13,1,13,3,13,
49
+ 381,8,13,1,13,1,13,1,14,1,14,1,15,1,15,1,16,1,16,1,17,1,17,1,18,
50
+ 1,18,1,19,1,19,1,20,1,20,1,21,1,21,1,22,1,22,1,22,1,23,1,23,1,23,
51
+ 1,24,1,24,1,25,1,25,1,26,1,26,1,27,1,27,1,27,1,27,1,27,1,27,1,27,
52
+ 1,27,1,28,1,28,1,28,1,28,1,28,1,28,1,28,1,29,1,29,1,29,1,29,1,29,
53
+ 1,29,1,29,1,29,1,30,1,30,1,30,1,30,1,30,1,30,1,30,1,30,1,31,1,31,
54
+ 1,31,1,31,1,31,1,32,1,32,1,32,1,32,1,32,1,32,1,32,1,32,1,32,1,32,
55
+ 1,32,1,32,1,32,1,32,1,32,1,32,1,32,1,32,1,32,1,32,1,32,1,32,1,32,
56
+ 1,32,1,32,1,32,1,32,1,32,1,32,1,32,1,32,1,32,1,32,1,32,1,32,1,32,
57
+ 1,32,1,32,1,32,1,32,1,32,1,32,1,32,1,32,1,32,1,32,1,32,1,32,1,32,
58
+ 1,32,1,32,1,32,1,32,1,32,1,32,3,32,504,8,32,1,33,1,33,1,33,1,33,
59
+ 1,33,1,33,1,33,1,33,1,33,1,33,1,33,1,33,1,33,1,33,1,33,3,33,521,
60
+ 8,33,1,34,1,34,1,34,1,34,1,34,1,35,1,35,1,35,1,35,1,35,1,35,1,36,
61
+ 1,36,1,36,1,36,1,36,1,37,1,37,1,37,1,37,1,37,1,38,1,38,1,38,1,38,
62
+ 1,39,1,39,1,39,1,39,1,40,1,40,1,40,1,40,1,40,1,41,1,41,1,41,1,41,
63
+ 1,41,1,42,1,42,1,42,1,42,1,42,1,43,1,43,1,43,1,43,1,43,1,44,1,44,
64
+ 1,44,1,44,1,44,1,45,1,45,1,45,1,45,1,45,1,46,1,46,1,46,1,46,1,46,
65
+ 1,46,1,46,1,46,1,47,1,47,1,47,1,47,1,47,1,47,1,47,1,47,1,48,1,48,
66
+ 1,48,1,48,1,48,1,48,1,48,1,48,1,49,1,49,1,49,1,49,1,49,1,49,1,49,
67
+ 1,49,1,50,1,50,1,50,1,50,1,50,1,50,1,50,1,50,1,51,1,51,1,51,1,51,
68
+ 1,51,1,51,1,51,1,51,1,52,1,52,1,52,1,52,1,52,1,52,1,53,1,53,1,53,
69
+ 1,53,1,53,1,53,1,54,1,54,1,54,1,54,1,54,1,54,1,55,1,55,1,55,1,55,
70
+ 1,55,1,55,1,55,1,55,1,56,1,56,1,56,1,56,1,56,1,56,1,56,1,56,1,57,
71
+ 1,57,1,57,1,57,1,57,1,57,1,57,1,57,1,58,1,58,1,58,1,58,1,58,1,58,
72
+ 1,58,1,58,1,59,1,59,1,59,1,59,1,59,1,59,1,59,1,59,1,60,1,60,1,60,
73
+ 1,60,1,60,1,60,1,60,1,61,1,61,1,61,1,61,1,61,1,61,1,61,1,62,1,62,
74
+ 1,62,1,62,1,62,1,62,1,63,1,63,1,63,1,63,1,63,1,63,1,63,1,63,1,63,
75
+ 1,63,1,64,1,64,1,64,1,64,1,64,1,64,1,64,1,65,1,65,1,65,1,65,1,65,
76
+ 1,65,1,66,1,66,1,66,1,66,1,66,1,67,1,67,1,67,1,67,1,67,1,67,1,67,
77
+ 1,67,1,67,1,67,1,67,1,67,1,67,1,67,1,67,1,67,1,67,3,67,753,8,67,
78
+ 1,68,1,68,1,68,1,68,1,68,1,68,1,68,1,69,1,69,1,69,1,69,1,69,1,69,
79
+ 1,69,1,69,1,70,1,70,1,70,1,70,1,70,1,70,1,70,1,70,1,71,1,71,1,71,
80
+ 1,71,1,71,1,71,1,71,1,71,1,72,1,72,1,73,1,73,1,74,1,74,1,75,1,75,
81
+ 1,76,1,76,5,76,796,8,76,10,76,12,76,799,9,76,1,76,1,76,1,76,4,76,
82
+ 804,8,76,11,76,12,76,805,3,76,808,8,76,1,77,1,77,1,78,1,78,1,79,
83
+ 1,79,5,79,816,8,79,10,79,12,79,819,9,79,3,79,821,8,79,1,79,1,79,
84
+ 1,79,5,79,826,8,79,10,79,12,79,829,9,79,1,79,3,79,832,8,79,3,79,
85
+ 834,8,79,1,80,1,80,1,80,1,80,1,80,1,81,1,81,1,82,1,82,1,82,1,82,
86
+ 1,82,1,82,1,82,1,82,1,82,3,82,852,8,82,1,83,1,83,1,83,1,83,1,83,
87
+ 1,83,1,84,1,84,1,84,1,84,1,84,1,84,1,84,1,84,1,84,1,84,1,85,1,85,
88
+ 1,86,1,86,1,86,1,86,1,86,1,86,1,86,1,86,1,86,3,86,881,8,86,1,87,
89
+ 1,87,1,87,1,87,1,87,1,87,1,88,1,88,1,88,1,88,1,88,1,88,1,88,1,88,
90
+ 1,88,1,88,1,89,1,89,1,90,4,90,902,8,90,11,90,12,90,903,1,91,1,91,
91
+ 4,91,908,8,91,11,91,12,91,909,3,797,817,827,0,92,1,1,3,2,5,3,7,4,
92
+ 9,5,11,6,13,7,15,8,17,9,19,10,21,11,23,12,25,13,27,14,29,15,31,16,
93
+ 33,17,35,18,37,19,39,20,41,21,43,22,45,23,47,24,49,25,51,26,53,27,
94
+ 55,28,57,29,59,30,61,31,63,32,65,33,67,34,69,35,71,36,73,37,75,38,
95
+ 77,39,79,40,81,41,83,42,85,43,87,44,89,45,91,46,93,47,95,48,97,49,
96
+ 99,50,101,51,103,52,105,53,107,54,109,55,111,56,113,57,115,58,117,
97
+ 59,119,60,121,61,123,62,125,63,127,64,129,65,131,66,133,67,135,68,
98
+ 137,69,139,70,141,71,143,72,145,73,147,74,149,75,151,0,153,76,155,
99
+ 77,157,78,159,79,161,80,163,81,165,82,167,83,169,84,171,85,173,86,
100
+ 175,87,177,88,179,89,181,90,183,91,1,0,3,3,0,9,10,13,13,32,32,2,
101
+ 0,65,90,97,122,1,0,48,57,949,0,1,1,0,0,0,0,3,1,0,0,0,0,5,1,0,0,0,
102
+ 0,7,1,0,0,0,0,9,1,0,0,0,0,11,1,0,0,0,0,13,1,0,0,0,0,15,1,0,0,0,0,
103
+ 17,1,0,0,0,0,19,1,0,0,0,0,21,1,0,0,0,0,23,1,0,0,0,0,25,1,0,0,0,0,
104
+ 27,1,0,0,0,0,29,1,0,0,0,0,31,1,0,0,0,0,33,1,0,0,0,0,35,1,0,0,0,0,
105
+ 37,1,0,0,0,0,39,1,0,0,0,0,41,1,0,0,0,0,43,1,0,0,0,0,45,1,0,0,0,0,
106
+ 47,1,0,0,0,0,49,1,0,0,0,0,51,1,0,0,0,0,53,1,0,0,0,0,55,1,0,0,0,0,
107
+ 57,1,0,0,0,0,59,1,0,0,0,0,61,1,0,0,0,0,63,1,0,0,0,0,65,1,0,0,0,0,
108
+ 67,1,0,0,0,0,69,1,0,0,0,0,71,1,0,0,0,0,73,1,0,0,0,0,75,1,0,0,0,0,
109
+ 77,1,0,0,0,0,79,1,0,0,0,0,81,1,0,0,0,0,83,1,0,0,0,0,85,1,0,0,0,0,
110
+ 87,1,0,0,0,0,89,1,0,0,0,0,91,1,0,0,0,0,93,1,0,0,0,0,95,1,0,0,0,0,
111
+ 97,1,0,0,0,0,99,1,0,0,0,0,101,1,0,0,0,0,103,1,0,0,0,0,105,1,0,0,
112
+ 0,0,107,1,0,0,0,0,109,1,0,0,0,0,111,1,0,0,0,0,113,1,0,0,0,0,115,
113
+ 1,0,0,0,0,117,1,0,0,0,0,119,1,0,0,0,0,121,1,0,0,0,0,123,1,0,0,0,
114
+ 0,125,1,0,0,0,0,127,1,0,0,0,0,129,1,0,0,0,0,131,1,0,0,0,0,133,1,
115
+ 0,0,0,0,135,1,0,0,0,0,137,1,0,0,0,0,139,1,0,0,0,0,141,1,0,0,0,0,
116
+ 143,1,0,0,0,0,145,1,0,0,0,0,147,1,0,0,0,0,149,1,0,0,0,0,153,1,0,
117
+ 0,0,0,155,1,0,0,0,0,157,1,0,0,0,0,159,1,0,0,0,0,161,1,0,0,0,0,163,
118
+ 1,0,0,0,0,165,1,0,0,0,0,167,1,0,0,0,0,169,1,0,0,0,0,171,1,0,0,0,
119
+ 0,173,1,0,0,0,0,175,1,0,0,0,0,177,1,0,0,0,0,179,1,0,0,0,0,181,1,
120
+ 0,0,0,0,183,1,0,0,0,1,185,1,0,0,0,3,187,1,0,0,0,5,190,1,0,0,0,7,
121
+ 208,1,0,0,0,9,223,1,0,0,0,11,240,1,0,0,0,13,244,1,0,0,0,15,252,1,
122
+ 0,0,0,17,276,1,0,0,0,19,280,1,0,0,0,21,295,1,0,0,0,23,312,1,0,0,
123
+ 0,25,320,1,0,0,0,27,380,1,0,0,0,29,384,1,0,0,0,31,386,1,0,0,0,33,
124
+ 388,1,0,0,0,35,390,1,0,0,0,37,392,1,0,0,0,39,394,1,0,0,0,41,396,
125
+ 1,0,0,0,43,398,1,0,0,0,45,400,1,0,0,0,47,403,1,0,0,0,49,406,1,0,
126
+ 0,0,51,408,1,0,0,0,53,410,1,0,0,0,55,412,1,0,0,0,57,420,1,0,0,0,
127
+ 59,427,1,0,0,0,61,435,1,0,0,0,63,443,1,0,0,0,65,503,1,0,0,0,67,520,
128
+ 1,0,0,0,69,522,1,0,0,0,71,527,1,0,0,0,73,533,1,0,0,0,75,538,1,0,
129
+ 0,0,77,543,1,0,0,0,79,547,1,0,0,0,81,551,1,0,0,0,83,556,1,0,0,0,
130
+ 85,561,1,0,0,0,87,566,1,0,0,0,89,571,1,0,0,0,91,576,1,0,0,0,93,581,
131
+ 1,0,0,0,95,589,1,0,0,0,97,597,1,0,0,0,99,605,1,0,0,0,101,613,1,0,
132
+ 0,0,103,621,1,0,0,0,105,629,1,0,0,0,107,635,1,0,0,0,109,641,1,0,
133
+ 0,0,111,647,1,0,0,0,113,655,1,0,0,0,115,663,1,0,0,0,117,671,1,0,
134
+ 0,0,119,679,1,0,0,0,121,687,1,0,0,0,123,694,1,0,0,0,125,701,1,0,
135
+ 0,0,127,707,1,0,0,0,129,717,1,0,0,0,131,724,1,0,0,0,133,730,1,0,
136
+ 0,0,135,752,1,0,0,0,137,754,1,0,0,0,139,761,1,0,0,0,141,769,1,0,
137
+ 0,0,143,777,1,0,0,0,145,785,1,0,0,0,147,787,1,0,0,0,149,789,1,0,
138
+ 0,0,151,791,1,0,0,0,153,793,1,0,0,0,155,809,1,0,0,0,157,811,1,0,
139
+ 0,0,159,833,1,0,0,0,161,835,1,0,0,0,163,840,1,0,0,0,165,851,1,0,
140
+ 0,0,167,853,1,0,0,0,169,859,1,0,0,0,171,869,1,0,0,0,173,880,1,0,
141
+ 0,0,175,882,1,0,0,0,177,888,1,0,0,0,179,898,1,0,0,0,181,901,1,0,
142
+ 0,0,183,905,1,0,0,0,185,186,5,44,0,0,186,2,1,0,0,0,187,188,5,46,
143
+ 0,0,188,4,1,0,0,0,189,191,7,0,0,0,190,189,1,0,0,0,191,192,1,0,0,
144
+ 0,192,190,1,0,0,0,192,193,1,0,0,0,193,194,1,0,0,0,194,195,6,2,0,
145
+ 0,195,6,1,0,0,0,196,197,5,92,0,0,197,209,5,44,0,0,198,199,5,92,0,
146
+ 0,199,200,5,116,0,0,200,201,5,104,0,0,201,202,5,105,0,0,202,203,
147
+ 5,110,0,0,203,204,5,115,0,0,204,205,5,112,0,0,205,206,5,97,0,0,206,
148
+ 207,5,99,0,0,207,209,5,101,0,0,208,196,1,0,0,0,208,198,1,0,0,0,209,
149
+ 210,1,0,0,0,210,211,6,3,0,0,211,8,1,0,0,0,212,213,5,92,0,0,213,224,
150
+ 5,58,0,0,214,215,5,92,0,0,215,216,5,109,0,0,216,217,5,101,0,0,217,
151
+ 218,5,100,0,0,218,219,5,115,0,0,219,220,5,112,0,0,220,221,5,97,0,
152
+ 0,221,222,5,99,0,0,222,224,5,101,0,0,223,212,1,0,0,0,223,214,1,0,
153
+ 0,0,224,225,1,0,0,0,225,226,6,4,0,0,226,10,1,0,0,0,227,228,5,92,
154
+ 0,0,228,241,5,59,0,0,229,230,5,92,0,0,230,231,5,116,0,0,231,232,
155
+ 5,104,0,0,232,233,5,105,0,0,233,234,5,99,0,0,234,235,5,107,0,0,235,
156
+ 236,5,115,0,0,236,237,5,112,0,0,237,238,5,97,0,0,238,239,5,99,0,
157
+ 0,239,241,5,101,0,0,240,227,1,0,0,0,240,229,1,0,0,0,241,242,1,0,
158
+ 0,0,242,243,6,5,0,0,243,12,1,0,0,0,244,245,5,92,0,0,245,246,5,113,
159
+ 0,0,246,247,5,117,0,0,247,248,5,97,0,0,248,249,5,100,0,0,249,250,
160
+ 1,0,0,0,250,251,6,6,0,0,251,14,1,0,0,0,252,253,5,92,0,0,253,254,
161
+ 5,113,0,0,254,255,5,113,0,0,255,256,5,117,0,0,256,257,5,97,0,0,257,
162
+ 258,5,100,0,0,258,259,1,0,0,0,259,260,6,7,0,0,260,16,1,0,0,0,261,
163
+ 262,5,92,0,0,262,277,5,33,0,0,263,264,5,92,0,0,264,265,5,110,0,0,
164
+ 265,266,5,101,0,0,266,267,5,103,0,0,267,268,5,116,0,0,268,269,5,
165
+ 104,0,0,269,270,5,105,0,0,270,271,5,110,0,0,271,272,5,115,0,0,272,
166
+ 273,5,112,0,0,273,274,5,97,0,0,274,275,5,99,0,0,275,277,5,101,0,
167
+ 0,276,261,1,0,0,0,276,263,1,0,0,0,277,278,1,0,0,0,278,279,6,8,0,
168
+ 0,279,18,1,0,0,0,280,281,5,92,0,0,281,282,5,110,0,0,282,283,5,101,
169
+ 0,0,283,284,5,103,0,0,284,285,5,109,0,0,285,286,5,101,0,0,286,287,
170
+ 5,100,0,0,287,288,5,115,0,0,288,289,5,112,0,0,289,290,5,97,0,0,290,
171
+ 291,5,99,0,0,291,292,5,101,0,0,292,293,1,0,0,0,293,294,6,9,0,0,294,
172
+ 20,1,0,0,0,295,296,5,92,0,0,296,297,5,110,0,0,297,298,5,101,0,0,
173
+ 298,299,5,103,0,0,299,300,5,116,0,0,300,301,5,104,0,0,301,302,5,
174
+ 105,0,0,302,303,5,99,0,0,303,304,5,107,0,0,304,305,5,115,0,0,305,
175
+ 306,5,112,0,0,306,307,5,97,0,0,307,308,5,99,0,0,308,309,5,101,0,
176
+ 0,309,310,1,0,0,0,310,311,6,10,0,0,311,22,1,0,0,0,312,313,5,92,0,
177
+ 0,313,314,5,108,0,0,314,315,5,101,0,0,315,316,5,102,0,0,316,317,
178
+ 5,116,0,0,317,318,1,0,0,0,318,319,6,11,0,0,319,24,1,0,0,0,320,321,
179
+ 5,92,0,0,321,322,5,114,0,0,322,323,5,105,0,0,323,324,5,103,0,0,324,
180
+ 325,5,104,0,0,325,326,5,116,0,0,326,327,1,0,0,0,327,328,6,12,0,0,
181
+ 328,26,1,0,0,0,329,330,5,92,0,0,330,331,5,118,0,0,331,332,5,114,
182
+ 0,0,332,333,5,117,0,0,333,334,5,108,0,0,334,381,5,101,0,0,335,336,
183
+ 5,92,0,0,336,337,5,118,0,0,337,338,5,99,0,0,338,339,5,101,0,0,339,
184
+ 340,5,110,0,0,340,341,5,116,0,0,341,342,5,101,0,0,342,381,5,114,
185
+ 0,0,343,344,5,92,0,0,344,345,5,118,0,0,345,346,5,98,0,0,346,347,
186
+ 5,111,0,0,347,381,5,120,0,0,348,349,5,92,0,0,349,350,5,118,0,0,350,
187
+ 351,5,115,0,0,351,352,5,107,0,0,352,353,5,105,0,0,353,381,5,112,
188
+ 0,0,354,355,5,92,0,0,355,356,5,118,0,0,356,357,5,115,0,0,357,358,
189
+ 5,112,0,0,358,359,5,97,0,0,359,360,5,99,0,0,360,381,5,101,0,0,361,
190
+ 362,5,92,0,0,362,363,5,104,0,0,363,364,5,102,0,0,364,365,5,105,0,
191
+ 0,365,381,5,108,0,0,366,367,5,92,0,0,367,381,5,42,0,0,368,369,5,
192
+ 92,0,0,369,381,5,45,0,0,370,371,5,92,0,0,371,381,5,46,0,0,372,373,
193
+ 5,92,0,0,373,381,5,47,0,0,374,375,5,92,0,0,375,381,5,34,0,0,376,
194
+ 377,5,92,0,0,377,381,5,40,0,0,378,379,5,92,0,0,379,381,5,61,0,0,
195
+ 380,329,1,0,0,0,380,335,1,0,0,0,380,343,1,0,0,0,380,348,1,0,0,0,
196
+ 380,354,1,0,0,0,380,361,1,0,0,0,380,366,1,0,0,0,380,368,1,0,0,0,
197
+ 380,370,1,0,0,0,380,372,1,0,0,0,380,374,1,0,0,0,380,376,1,0,0,0,
198
+ 380,378,1,0,0,0,381,382,1,0,0,0,382,383,6,13,0,0,383,28,1,0,0,0,
199
+ 384,385,5,43,0,0,385,30,1,0,0,0,386,387,5,45,0,0,387,32,1,0,0,0,
200
+ 388,389,5,42,0,0,389,34,1,0,0,0,390,391,5,47,0,0,391,36,1,0,0,0,
201
+ 392,393,5,40,0,0,393,38,1,0,0,0,394,395,5,41,0,0,395,40,1,0,0,0,
202
+ 396,397,5,123,0,0,397,42,1,0,0,0,398,399,5,125,0,0,399,44,1,0,0,
203
+ 0,400,401,5,92,0,0,401,402,5,123,0,0,402,46,1,0,0,0,403,404,5,92,
204
+ 0,0,404,405,5,125,0,0,405,48,1,0,0,0,406,407,5,91,0,0,407,50,1,0,
205
+ 0,0,408,409,5,93,0,0,409,52,1,0,0,0,410,411,5,124,0,0,411,54,1,0,
206
+ 0,0,412,413,5,92,0,0,413,414,5,114,0,0,414,415,5,105,0,0,415,416,
207
+ 5,103,0,0,416,417,5,104,0,0,417,418,5,116,0,0,418,419,5,124,0,0,
208
+ 419,56,1,0,0,0,420,421,5,92,0,0,421,422,5,108,0,0,422,423,5,101,
209
+ 0,0,423,424,5,102,0,0,424,425,5,116,0,0,425,426,5,124,0,0,426,58,
210
+ 1,0,0,0,427,428,5,92,0,0,428,429,5,108,0,0,429,430,5,97,0,0,430,
211
+ 431,5,110,0,0,431,432,5,103,0,0,432,433,5,108,0,0,433,434,5,101,
212
+ 0,0,434,60,1,0,0,0,435,436,5,92,0,0,436,437,5,114,0,0,437,438,5,
213
+ 97,0,0,438,439,5,110,0,0,439,440,5,103,0,0,440,441,5,108,0,0,441,
214
+ 442,5,101,0,0,442,62,1,0,0,0,443,444,5,92,0,0,444,445,5,108,0,0,
215
+ 445,446,5,105,0,0,446,447,5,109,0,0,447,64,1,0,0,0,448,449,5,92,
216
+ 0,0,449,450,5,116,0,0,450,504,5,111,0,0,451,452,5,92,0,0,452,453,
217
+ 5,114,0,0,453,454,5,105,0,0,454,455,5,103,0,0,455,456,5,104,0,0,
218
+ 456,457,5,116,0,0,457,458,5,97,0,0,458,459,5,114,0,0,459,460,5,114,
219
+ 0,0,460,461,5,111,0,0,461,504,5,119,0,0,462,463,5,92,0,0,463,464,
220
+ 5,82,0,0,464,465,5,105,0,0,465,466,5,103,0,0,466,467,5,104,0,0,467,
221
+ 468,5,116,0,0,468,469,5,97,0,0,469,470,5,114,0,0,470,471,5,114,0,
222
+ 0,471,472,5,111,0,0,472,504,5,119,0,0,473,474,5,92,0,0,474,475,5,
223
+ 108,0,0,475,476,5,111,0,0,476,477,5,110,0,0,477,478,5,103,0,0,478,
224
+ 479,5,114,0,0,479,480,5,105,0,0,480,481,5,103,0,0,481,482,5,104,
225
+ 0,0,482,483,5,116,0,0,483,484,5,97,0,0,484,485,5,114,0,0,485,486,
226
+ 5,114,0,0,486,487,5,111,0,0,487,504,5,119,0,0,488,489,5,92,0,0,489,
227
+ 490,5,76,0,0,490,491,5,111,0,0,491,492,5,110,0,0,492,493,5,103,0,
228
+ 0,493,494,5,114,0,0,494,495,5,105,0,0,495,496,5,103,0,0,496,497,
229
+ 5,104,0,0,497,498,5,116,0,0,498,499,5,97,0,0,499,500,5,114,0,0,500,
230
+ 501,5,114,0,0,501,502,5,111,0,0,502,504,5,119,0,0,503,448,1,0,0,
231
+ 0,503,451,1,0,0,0,503,462,1,0,0,0,503,473,1,0,0,0,503,488,1,0,0,
232
+ 0,504,66,1,0,0,0,505,506,5,92,0,0,506,507,5,105,0,0,507,508,5,110,
233
+ 0,0,508,521,5,116,0,0,509,510,5,92,0,0,510,511,5,105,0,0,511,512,
234
+ 5,110,0,0,512,513,5,116,0,0,513,514,5,92,0,0,514,515,5,108,0,0,515,
235
+ 516,5,105,0,0,516,517,5,109,0,0,517,518,5,105,0,0,518,519,5,116,
236
+ 0,0,519,521,5,115,0,0,520,505,1,0,0,0,520,509,1,0,0,0,521,68,1,0,
237
+ 0,0,522,523,5,92,0,0,523,524,5,115,0,0,524,525,5,117,0,0,525,526,
238
+ 5,109,0,0,526,70,1,0,0,0,527,528,5,92,0,0,528,529,5,112,0,0,529,
239
+ 530,5,114,0,0,530,531,5,111,0,0,531,532,5,100,0,0,532,72,1,0,0,0,
240
+ 533,534,5,92,0,0,534,535,5,101,0,0,535,536,5,120,0,0,536,537,5,112,
241
+ 0,0,537,74,1,0,0,0,538,539,5,92,0,0,539,540,5,108,0,0,540,541,5,
242
+ 111,0,0,541,542,5,103,0,0,542,76,1,0,0,0,543,544,5,92,0,0,544,545,
243
+ 5,108,0,0,545,546,5,103,0,0,546,78,1,0,0,0,547,548,5,92,0,0,548,
244
+ 549,5,108,0,0,549,550,5,110,0,0,550,80,1,0,0,0,551,552,5,92,0,0,
245
+ 552,553,5,115,0,0,553,554,5,105,0,0,554,555,5,110,0,0,555,82,1,0,
246
+ 0,0,556,557,5,92,0,0,557,558,5,99,0,0,558,559,5,111,0,0,559,560,
247
+ 5,115,0,0,560,84,1,0,0,0,561,562,5,92,0,0,562,563,5,116,0,0,563,
248
+ 564,5,97,0,0,564,565,5,110,0,0,565,86,1,0,0,0,566,567,5,92,0,0,567,
249
+ 568,5,99,0,0,568,569,5,115,0,0,569,570,5,99,0,0,570,88,1,0,0,0,571,
250
+ 572,5,92,0,0,572,573,5,115,0,0,573,574,5,101,0,0,574,575,5,99,0,
251
+ 0,575,90,1,0,0,0,576,577,5,92,0,0,577,578,5,99,0,0,578,579,5,111,
252
+ 0,0,579,580,5,116,0,0,580,92,1,0,0,0,581,582,5,92,0,0,582,583,5,
253
+ 97,0,0,583,584,5,114,0,0,584,585,5,99,0,0,585,586,5,115,0,0,586,
254
+ 587,5,105,0,0,587,588,5,110,0,0,588,94,1,0,0,0,589,590,5,92,0,0,
255
+ 590,591,5,97,0,0,591,592,5,114,0,0,592,593,5,99,0,0,593,594,5,99,
256
+ 0,0,594,595,5,111,0,0,595,596,5,115,0,0,596,96,1,0,0,0,597,598,5,
257
+ 92,0,0,598,599,5,97,0,0,599,600,5,114,0,0,600,601,5,99,0,0,601,602,
258
+ 5,116,0,0,602,603,5,97,0,0,603,604,5,110,0,0,604,98,1,0,0,0,605,
259
+ 606,5,92,0,0,606,607,5,97,0,0,607,608,5,114,0,0,608,609,5,99,0,0,
260
+ 609,610,5,99,0,0,610,611,5,115,0,0,611,612,5,99,0,0,612,100,1,0,
261
+ 0,0,613,614,5,92,0,0,614,615,5,97,0,0,615,616,5,114,0,0,616,617,
262
+ 5,99,0,0,617,618,5,115,0,0,618,619,5,101,0,0,619,620,5,99,0,0,620,
263
+ 102,1,0,0,0,621,622,5,92,0,0,622,623,5,97,0,0,623,624,5,114,0,0,
264
+ 624,625,5,99,0,0,625,626,5,99,0,0,626,627,5,111,0,0,627,628,5,116,
265
+ 0,0,628,104,1,0,0,0,629,630,5,92,0,0,630,631,5,115,0,0,631,632,5,
266
+ 105,0,0,632,633,5,110,0,0,633,634,5,104,0,0,634,106,1,0,0,0,635,
267
+ 636,5,92,0,0,636,637,5,99,0,0,637,638,5,111,0,0,638,639,5,115,0,
268
+ 0,639,640,5,104,0,0,640,108,1,0,0,0,641,642,5,92,0,0,642,643,5,116,
269
+ 0,0,643,644,5,97,0,0,644,645,5,110,0,0,645,646,5,104,0,0,646,110,
270
+ 1,0,0,0,647,648,5,92,0,0,648,649,5,97,0,0,649,650,5,114,0,0,650,
271
+ 651,5,115,0,0,651,652,5,105,0,0,652,653,5,110,0,0,653,654,5,104,
272
+ 0,0,654,112,1,0,0,0,655,656,5,92,0,0,656,657,5,97,0,0,657,658,5,
273
+ 114,0,0,658,659,5,99,0,0,659,660,5,111,0,0,660,661,5,115,0,0,661,
274
+ 662,5,104,0,0,662,114,1,0,0,0,663,664,5,92,0,0,664,665,5,97,0,0,
275
+ 665,666,5,114,0,0,666,667,5,116,0,0,667,668,5,97,0,0,668,669,5,110,
276
+ 0,0,669,670,5,104,0,0,670,116,1,0,0,0,671,672,5,92,0,0,672,673,5,
277
+ 108,0,0,673,674,5,102,0,0,674,675,5,108,0,0,675,676,5,111,0,0,676,
278
+ 677,5,111,0,0,677,678,5,114,0,0,678,118,1,0,0,0,679,680,5,92,0,0,
279
+ 680,681,5,114,0,0,681,682,5,102,0,0,682,683,5,108,0,0,683,684,5,
280
+ 111,0,0,684,685,5,111,0,0,685,686,5,114,0,0,686,120,1,0,0,0,687,
281
+ 688,5,92,0,0,688,689,5,108,0,0,689,690,5,99,0,0,690,691,5,101,0,
282
+ 0,691,692,5,105,0,0,692,693,5,108,0,0,693,122,1,0,0,0,694,695,5,
283
+ 92,0,0,695,696,5,114,0,0,696,697,5,99,0,0,697,698,5,101,0,0,698,
284
+ 699,5,105,0,0,699,700,5,108,0,0,700,124,1,0,0,0,701,702,5,92,0,0,
285
+ 702,703,5,115,0,0,703,704,5,113,0,0,704,705,5,114,0,0,705,706,5,
286
+ 116,0,0,706,126,1,0,0,0,707,708,5,92,0,0,708,709,5,111,0,0,709,710,
287
+ 5,118,0,0,710,711,5,101,0,0,711,712,5,114,0,0,712,713,5,108,0,0,
288
+ 713,714,5,105,0,0,714,715,5,110,0,0,715,716,5,101,0,0,716,128,1,
289
+ 0,0,0,717,718,5,92,0,0,718,719,5,116,0,0,719,720,5,105,0,0,720,721,
290
+ 5,109,0,0,721,722,5,101,0,0,722,723,5,115,0,0,723,130,1,0,0,0,724,
291
+ 725,5,92,0,0,725,726,5,99,0,0,726,727,5,100,0,0,727,728,5,111,0,
292
+ 0,728,729,5,116,0,0,729,132,1,0,0,0,730,731,5,92,0,0,731,732,5,100,
293
+ 0,0,732,733,5,105,0,0,733,734,5,118,0,0,734,134,1,0,0,0,735,736,
294
+ 5,92,0,0,736,737,5,102,0,0,737,738,5,114,0,0,738,739,5,97,0,0,739,
295
+ 753,5,99,0,0,740,741,5,92,0,0,741,742,5,100,0,0,742,743,5,102,0,
296
+ 0,743,744,5,114,0,0,744,745,5,97,0,0,745,753,5,99,0,0,746,747,5,
297
+ 92,0,0,747,748,5,116,0,0,748,749,5,102,0,0,749,750,5,114,0,0,750,
298
+ 751,5,97,0,0,751,753,5,99,0,0,752,735,1,0,0,0,752,740,1,0,0,0,752,
299
+ 746,1,0,0,0,753,136,1,0,0,0,754,755,5,92,0,0,755,756,5,98,0,0,756,
300
+ 757,5,105,0,0,757,758,5,110,0,0,758,759,5,111,0,0,759,760,5,109,
301
+ 0,0,760,138,1,0,0,0,761,762,5,92,0,0,762,763,5,100,0,0,763,764,5,
302
+ 98,0,0,764,765,5,105,0,0,765,766,5,110,0,0,766,767,5,111,0,0,767,
303
+ 768,5,109,0,0,768,140,1,0,0,0,769,770,5,92,0,0,770,771,5,116,0,0,
304
+ 771,772,5,98,0,0,772,773,5,105,0,0,773,774,5,110,0,0,774,775,5,111,
305
+ 0,0,775,776,5,109,0,0,776,142,1,0,0,0,777,778,5,92,0,0,778,779,5,
306
+ 109,0,0,779,780,5,97,0,0,780,781,5,116,0,0,781,782,5,104,0,0,782,
307
+ 783,5,105,0,0,783,784,5,116,0,0,784,144,1,0,0,0,785,786,5,95,0,0,
308
+ 786,146,1,0,0,0,787,788,5,94,0,0,788,148,1,0,0,0,789,790,5,58,0,
309
+ 0,790,150,1,0,0,0,791,792,7,0,0,0,792,152,1,0,0,0,793,797,5,100,
310
+ 0,0,794,796,3,151,75,0,795,794,1,0,0,0,796,799,1,0,0,0,797,798,1,
311
+ 0,0,0,797,795,1,0,0,0,798,807,1,0,0,0,799,797,1,0,0,0,800,808,7,
312
+ 1,0,0,801,803,5,92,0,0,802,804,7,1,0,0,803,802,1,0,0,0,804,805,1,
313
+ 0,0,0,805,803,1,0,0,0,805,806,1,0,0,0,806,808,1,0,0,0,807,800,1,
314
+ 0,0,0,807,801,1,0,0,0,808,154,1,0,0,0,809,810,7,1,0,0,810,156,1,
315
+ 0,0,0,811,812,7,2,0,0,812,158,1,0,0,0,813,817,5,38,0,0,814,816,3,
316
+ 151,75,0,815,814,1,0,0,0,816,819,1,0,0,0,817,818,1,0,0,0,817,815,
317
+ 1,0,0,0,818,821,1,0,0,0,819,817,1,0,0,0,820,813,1,0,0,0,820,821,
318
+ 1,0,0,0,821,822,1,0,0,0,822,834,5,61,0,0,823,831,5,61,0,0,824,826,
319
+ 3,151,75,0,825,824,1,0,0,0,826,829,1,0,0,0,827,828,1,0,0,0,827,825,
320
+ 1,0,0,0,828,830,1,0,0,0,829,827,1,0,0,0,830,832,5,38,0,0,831,827,
321
+ 1,0,0,0,831,832,1,0,0,0,832,834,1,0,0,0,833,820,1,0,0,0,833,823,
322
+ 1,0,0,0,834,160,1,0,0,0,835,836,5,92,0,0,836,837,5,110,0,0,837,838,
323
+ 5,101,0,0,838,839,5,113,0,0,839,162,1,0,0,0,840,841,5,60,0,0,841,
324
+ 164,1,0,0,0,842,843,5,92,0,0,843,844,5,108,0,0,844,845,5,101,0,0,
325
+ 845,852,5,113,0,0,846,847,5,92,0,0,847,848,5,108,0,0,848,852,5,101,
326
+ 0,0,849,852,3,167,83,0,850,852,3,169,84,0,851,842,1,0,0,0,851,846,
327
+ 1,0,0,0,851,849,1,0,0,0,851,850,1,0,0,0,852,166,1,0,0,0,853,854,
328
+ 5,92,0,0,854,855,5,108,0,0,855,856,5,101,0,0,856,857,5,113,0,0,857,
329
+ 858,5,113,0,0,858,168,1,0,0,0,859,860,5,92,0,0,860,861,5,108,0,0,
330
+ 861,862,5,101,0,0,862,863,5,113,0,0,863,864,5,115,0,0,864,865,5,
331
+ 108,0,0,865,866,5,97,0,0,866,867,5,110,0,0,867,868,5,116,0,0,868,
332
+ 170,1,0,0,0,869,870,5,62,0,0,870,172,1,0,0,0,871,872,5,92,0,0,872,
333
+ 873,5,103,0,0,873,874,5,101,0,0,874,881,5,113,0,0,875,876,5,92,0,
334
+ 0,876,877,5,103,0,0,877,881,5,101,0,0,878,881,3,175,87,0,879,881,
335
+ 3,177,88,0,880,871,1,0,0,0,880,875,1,0,0,0,880,878,1,0,0,0,880,879,
336
+ 1,0,0,0,881,174,1,0,0,0,882,883,5,92,0,0,883,884,5,103,0,0,884,885,
337
+ 5,101,0,0,885,886,5,113,0,0,886,887,5,113,0,0,887,176,1,0,0,0,888,
338
+ 889,5,92,0,0,889,890,5,103,0,0,890,891,5,101,0,0,891,892,5,113,0,
339
+ 0,892,893,5,115,0,0,893,894,5,108,0,0,894,895,5,97,0,0,895,896,5,
340
+ 110,0,0,896,897,5,116,0,0,897,178,1,0,0,0,898,899,5,33,0,0,899,180,
341
+ 1,0,0,0,900,902,5,39,0,0,901,900,1,0,0,0,902,903,1,0,0,0,903,901,
342
+ 1,0,0,0,903,904,1,0,0,0,904,182,1,0,0,0,905,907,5,92,0,0,906,908,
343
+ 7,1,0,0,907,906,1,0,0,0,908,909,1,0,0,0,909,907,1,0,0,0,909,910,
344
+ 1,0,0,0,910,184,1,0,0,0,22,0,192,208,223,240,276,380,503,520,752,
345
+ 797,805,807,817,820,827,831,833,851,880,903,909,1,6,0,0
346
+ ]
347
+
348
+ class LaTeXLexer(Lexer):
349
+
350
+ atn = ATNDeserializer().deserialize(serializedATN())
351
+
352
+ decisionsToDFA = [ DFA(ds, i) for i, ds in enumerate(atn.decisionToState) ]
353
+
354
+ T__0 = 1
355
+ T__1 = 2
356
+ WS = 3
357
+ THINSPACE = 4
358
+ MEDSPACE = 5
359
+ THICKSPACE = 6
360
+ QUAD = 7
361
+ QQUAD = 8
362
+ NEGTHINSPACE = 9
363
+ NEGMEDSPACE = 10
364
+ NEGTHICKSPACE = 11
365
+ CMD_LEFT = 12
366
+ CMD_RIGHT = 13
367
+ IGNORE = 14
368
+ ADD = 15
369
+ SUB = 16
370
+ MUL = 17
371
+ DIV = 18
372
+ L_PAREN = 19
373
+ R_PAREN = 20
374
+ L_BRACE = 21
375
+ R_BRACE = 22
376
+ L_BRACE_LITERAL = 23
377
+ R_BRACE_LITERAL = 24
378
+ L_BRACKET = 25
379
+ R_BRACKET = 26
380
+ BAR = 27
381
+ R_BAR = 28
382
+ L_BAR = 29
383
+ L_ANGLE = 30
384
+ R_ANGLE = 31
385
+ FUNC_LIM = 32
386
+ LIM_APPROACH_SYM = 33
387
+ FUNC_INT = 34
388
+ FUNC_SUM = 35
389
+ FUNC_PROD = 36
390
+ FUNC_EXP = 37
391
+ FUNC_LOG = 38
392
+ FUNC_LG = 39
393
+ FUNC_LN = 40
394
+ FUNC_SIN = 41
395
+ FUNC_COS = 42
396
+ FUNC_TAN = 43
397
+ FUNC_CSC = 44
398
+ FUNC_SEC = 45
399
+ FUNC_COT = 46
400
+ FUNC_ARCSIN = 47
401
+ FUNC_ARCCOS = 48
402
+ FUNC_ARCTAN = 49
403
+ FUNC_ARCCSC = 50
404
+ FUNC_ARCSEC = 51
405
+ FUNC_ARCCOT = 52
406
+ FUNC_SINH = 53
407
+ FUNC_COSH = 54
408
+ FUNC_TANH = 55
409
+ FUNC_ARSINH = 56
410
+ FUNC_ARCOSH = 57
411
+ FUNC_ARTANH = 58
412
+ L_FLOOR = 59
413
+ R_FLOOR = 60
414
+ L_CEIL = 61
415
+ R_CEIL = 62
416
+ FUNC_SQRT = 63
417
+ FUNC_OVERLINE = 64
418
+ CMD_TIMES = 65
419
+ CMD_CDOT = 66
420
+ CMD_DIV = 67
421
+ CMD_FRAC = 68
422
+ CMD_BINOM = 69
423
+ CMD_DBINOM = 70
424
+ CMD_TBINOM = 71
425
+ CMD_MATHIT = 72
426
+ UNDERSCORE = 73
427
+ CARET = 74
428
+ COLON = 75
429
+ DIFFERENTIAL = 76
430
+ LETTER = 77
431
+ DIGIT = 78
432
+ EQUAL = 79
433
+ NEQ = 80
434
+ LT = 81
435
+ LTE = 82
436
+ LTE_Q = 83
437
+ LTE_S = 84
438
+ GT = 85
439
+ GTE = 86
440
+ GTE_Q = 87
441
+ GTE_S = 88
442
+ BANG = 89
443
+ SINGLE_QUOTES = 90
444
+ SYMBOL = 91
445
+
446
+ channelNames = [ u"DEFAULT_TOKEN_CHANNEL", u"HIDDEN" ]
447
+
448
+ modeNames = [ "DEFAULT_MODE" ]
449
+
450
+ literalNames = [ "<INVALID>",
451
+ "','", "'.'", "'\\quad'", "'\\qquad'", "'\\negmedspace'", "'\\negthickspace'",
452
+ "'\\left'", "'\\right'", "'+'", "'-'", "'*'", "'/'", "'('",
453
+ "')'", "'{'", "'}'", "'\\{'", "'\\}'", "'['", "']'", "'|'",
454
+ "'\\right|'", "'\\left|'", "'\\langle'", "'\\rangle'", "'\\lim'",
455
+ "'\\sum'", "'\\prod'", "'\\exp'", "'\\log'", "'\\lg'", "'\\ln'",
456
+ "'\\sin'", "'\\cos'", "'\\tan'", "'\\csc'", "'\\sec'", "'\\cot'",
457
+ "'\\arcsin'", "'\\arccos'", "'\\arctan'", "'\\arccsc'", "'\\arcsec'",
458
+ "'\\arccot'", "'\\sinh'", "'\\cosh'", "'\\tanh'", "'\\arsinh'",
459
+ "'\\arcosh'", "'\\artanh'", "'\\lfloor'", "'\\rfloor'", "'\\lceil'",
460
+ "'\\rceil'", "'\\sqrt'", "'\\overline'", "'\\times'", "'\\cdot'",
461
+ "'\\div'", "'\\binom'", "'\\dbinom'", "'\\tbinom'", "'\\mathit'",
462
+ "'_'", "'^'", "':'", "'\\neq'", "'<'", "'\\leqq'", "'\\leqslant'",
463
+ "'>'", "'\\geqq'", "'\\geqslant'", "'!'" ]
464
+
465
+ symbolicNames = [ "<INVALID>",
466
+ "WS", "THINSPACE", "MEDSPACE", "THICKSPACE", "QUAD", "QQUAD",
467
+ "NEGTHINSPACE", "NEGMEDSPACE", "NEGTHICKSPACE", "CMD_LEFT",
468
+ "CMD_RIGHT", "IGNORE", "ADD", "SUB", "MUL", "DIV", "L_PAREN",
469
+ "R_PAREN", "L_BRACE", "R_BRACE", "L_BRACE_LITERAL", "R_BRACE_LITERAL",
470
+ "L_BRACKET", "R_BRACKET", "BAR", "R_BAR", "L_BAR", "L_ANGLE",
471
+ "R_ANGLE", "FUNC_LIM", "LIM_APPROACH_SYM", "FUNC_INT", "FUNC_SUM",
472
+ "FUNC_PROD", "FUNC_EXP", "FUNC_LOG", "FUNC_LG", "FUNC_LN", "FUNC_SIN",
473
+ "FUNC_COS", "FUNC_TAN", "FUNC_CSC", "FUNC_SEC", "FUNC_COT",
474
+ "FUNC_ARCSIN", "FUNC_ARCCOS", "FUNC_ARCTAN", "FUNC_ARCCSC",
475
+ "FUNC_ARCSEC", "FUNC_ARCCOT", "FUNC_SINH", "FUNC_COSH", "FUNC_TANH",
476
+ "FUNC_ARSINH", "FUNC_ARCOSH", "FUNC_ARTANH", "L_FLOOR", "R_FLOOR",
477
+ "L_CEIL", "R_CEIL", "FUNC_SQRT", "FUNC_OVERLINE", "CMD_TIMES",
478
+ "CMD_CDOT", "CMD_DIV", "CMD_FRAC", "CMD_BINOM", "CMD_DBINOM",
479
+ "CMD_TBINOM", "CMD_MATHIT", "UNDERSCORE", "CARET", "COLON",
480
+ "DIFFERENTIAL", "LETTER", "DIGIT", "EQUAL", "NEQ", "LT", "LTE",
481
+ "LTE_Q", "LTE_S", "GT", "GTE", "GTE_Q", "GTE_S", "BANG", "SINGLE_QUOTES",
482
+ "SYMBOL" ]
483
+
484
+ ruleNames = [ "T__0", "T__1", "WS", "THINSPACE", "MEDSPACE", "THICKSPACE",
485
+ "QUAD", "QQUAD", "NEGTHINSPACE", "NEGMEDSPACE", "NEGTHICKSPACE",
486
+ "CMD_LEFT", "CMD_RIGHT", "IGNORE", "ADD", "SUB", "MUL",
487
+ "DIV", "L_PAREN", "R_PAREN", "L_BRACE", "R_BRACE", "L_BRACE_LITERAL",
488
+ "R_BRACE_LITERAL", "L_BRACKET", "R_BRACKET", "BAR", "R_BAR",
489
+ "L_BAR", "L_ANGLE", "R_ANGLE", "FUNC_LIM", "LIM_APPROACH_SYM",
490
+ "FUNC_INT", "FUNC_SUM", "FUNC_PROD", "FUNC_EXP", "FUNC_LOG",
491
+ "FUNC_LG", "FUNC_LN", "FUNC_SIN", "FUNC_COS", "FUNC_TAN",
492
+ "FUNC_CSC", "FUNC_SEC", "FUNC_COT", "FUNC_ARCSIN", "FUNC_ARCCOS",
493
+ "FUNC_ARCTAN", "FUNC_ARCCSC", "FUNC_ARCSEC", "FUNC_ARCCOT",
494
+ "FUNC_SINH", "FUNC_COSH", "FUNC_TANH", "FUNC_ARSINH",
495
+ "FUNC_ARCOSH", "FUNC_ARTANH", "L_FLOOR", "R_FLOOR", "L_CEIL",
496
+ "R_CEIL", "FUNC_SQRT", "FUNC_OVERLINE", "CMD_TIMES", "CMD_CDOT",
497
+ "CMD_DIV", "CMD_FRAC", "CMD_BINOM", "CMD_DBINOM", "CMD_TBINOM",
498
+ "CMD_MATHIT", "UNDERSCORE", "CARET", "COLON", "WS_CHAR",
499
+ "DIFFERENTIAL", "LETTER", "DIGIT", "EQUAL", "NEQ", "LT",
500
+ "LTE", "LTE_Q", "LTE_S", "GT", "GTE", "GTE_Q", "GTE_S",
501
+ "BANG", "SINGLE_QUOTES", "SYMBOL" ]
502
+
503
+ grammarFileName = "LaTeX.g4"
504
+
505
+ def __init__(self, input=None, output:TextIO = sys.stdout):
506
+ super().__init__(input, output)
507
+ self.checkVersion("4.11.1")
508
+ self._interp = LexerATNSimulator(self, self.atn, self.decisionsToDFA, PredictionContextCache())
509
+ self._actions = None
510
+ self._predicates = None
511
+
512
+
evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/latex/_antlr/latexparser.py ADDED
The diff for this file is too large to render. See raw diff
 
evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/latex/_build_latex_antlr.py ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import subprocess
3
+ import glob
4
+
5
+ from sympy.utilities.misc import debug
6
+
7
+ here = os.path.dirname(__file__)
8
+ grammar_file = os.path.abspath(os.path.join(here, "LaTeX.g4"))
9
+ dir_latex_antlr = os.path.join(here, "_antlr")
10
+
11
+ header = '''\
12
+ # *** GENERATED BY `setup.py antlr`, DO NOT EDIT BY HAND ***
13
+ #
14
+ # Generated from ../LaTeX.g4, derived from latex2sympy
15
+ # latex2sympy is licensed under the MIT license
16
+ # https://github.com/augustt198/latex2sympy/blob/master/LICENSE.txt
17
+ #
18
+ # Generated with antlr4
19
+ # antlr4 is licensed under the BSD-3-Clause License
20
+ # https://github.com/antlr/antlr4/blob/master/LICENSE.txt
21
+ '''
22
+
23
+
24
+ def check_antlr_version():
25
+ debug("Checking antlr4 version...")
26
+
27
+ try:
28
+ debug(subprocess.check_output(["antlr4"])
29
+ .decode('utf-8').split("\n")[0])
30
+ return True
31
+ except (subprocess.CalledProcessError, FileNotFoundError):
32
+ debug("The 'antlr4' command line tool is not installed, "
33
+ "or not on your PATH.\n"
34
+ "> Please refer to the README.md file for more information.")
35
+ return False
36
+
37
+
38
+ def build_parser(output_dir=dir_latex_antlr):
39
+ check_antlr_version()
40
+
41
+ debug("Updating ANTLR-generated code in {}".format(output_dir))
42
+
43
+ if not os.path.exists(output_dir):
44
+ os.makedirs(output_dir)
45
+
46
+ with open(os.path.join(output_dir, "__init__.py"), "w+") as fp:
47
+ fp.write(header)
48
+
49
+ args = [
50
+ "antlr4",
51
+ grammar_file,
52
+ "-o", output_dir,
53
+ # for now, not generating these as latex2sympy did not use them
54
+ "-no-visitor",
55
+ "-no-listener",
56
+ ]
57
+
58
+ debug("Running code generation...\n\t$ {}".format(" ".join(args)))
59
+ subprocess.check_output(args, cwd=output_dir)
60
+
61
+ debug("Applying headers, removing unnecessary files and renaming...")
62
+ # Handle case insensitive file systems. If the files are already
63
+ # generated, they will be written to latex* but LaTeX*.* won't match them.
64
+ for path in (glob.glob(os.path.join(output_dir, "LaTeX*.*")) or
65
+ glob.glob(os.path.join(output_dir, "latex*.*"))):
66
+
67
+ # Remove files ending in .interp or .tokens as they are not needed.
68
+ if not path.endswith(".py"):
69
+ os.unlink(path)
70
+ continue
71
+
72
+ new_path = os.path.join(output_dir, os.path.basename(path).lower())
73
+ with open(path, 'r') as f:
74
+ lines = [line.rstrip() + '\n' for line in f.readlines()]
75
+
76
+ os.unlink(path)
77
+
78
+ with open(new_path, "w") as out_file:
79
+ offset = 0
80
+ while lines[offset].startswith('#'):
81
+ offset += 1
82
+ out_file.write(header)
83
+ out_file.writelines(lines[offset:])
84
+
85
+ debug("\t{}".format(new_path))
86
+
87
+ return True
88
+
89
+
90
+ if __name__ == "__main__":
91
+ build_parser()
evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/latex/_parse_latex_antlr.py ADDED
@@ -0,0 +1,607 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Ported from latex2sympy by @augustt198
2
+ # https://github.com/augustt198/latex2sympy
3
+ # See license in LICENSE.txt
4
+ from importlib.metadata import version
5
+ import sympy
6
+ from sympy.external import import_module
7
+ from sympy.printing.str import StrPrinter
8
+ from sympy.physics.quantum.state import Bra, Ket
9
+
10
+ from .errors import LaTeXParsingError
11
+
12
+
13
+ LaTeXParser = LaTeXLexer = MathErrorListener = None
14
+
15
+ try:
16
+ LaTeXParser = import_module('sympy.parsing.latex._antlr.latexparser',
17
+ import_kwargs={'fromlist': ['LaTeXParser']}).LaTeXParser
18
+ LaTeXLexer = import_module('sympy.parsing.latex._antlr.latexlexer',
19
+ import_kwargs={'fromlist': ['LaTeXLexer']}).LaTeXLexer
20
+ except Exception:
21
+ pass
22
+
23
+ ErrorListener = import_module('antlr4.error.ErrorListener',
24
+ warn_not_installed=True,
25
+ import_kwargs={'fromlist': ['ErrorListener']}
26
+ )
27
+
28
+
29
+
30
+ if ErrorListener:
31
+ class MathErrorListener(ErrorListener.ErrorListener): # type:ignore # noqa:F811
32
+ def __init__(self, src):
33
+ super(ErrorListener.ErrorListener, self).__init__()
34
+ self.src = src
35
+
36
+ def syntaxError(self, recog, symbol, line, col, msg, e):
37
+ fmt = "%s\n%s\n%s"
38
+ marker = "~" * col + "^"
39
+
40
+ if msg.startswith("missing"):
41
+ err = fmt % (msg, self.src, marker)
42
+ elif msg.startswith("no viable"):
43
+ err = fmt % ("I expected something else here", self.src, marker)
44
+ elif msg.startswith("mismatched"):
45
+ names = LaTeXParser.literalNames
46
+ expected = [
47
+ names[i] for i in e.getExpectedTokens() if i < len(names)
48
+ ]
49
+ if len(expected) < 10:
50
+ expected = " ".join(expected)
51
+ err = (fmt % ("I expected one of these: " + expected, self.src,
52
+ marker))
53
+ else:
54
+ err = (fmt % ("I expected something else here", self.src,
55
+ marker))
56
+ else:
57
+ err = fmt % ("I don't understand this", self.src, marker)
58
+ raise LaTeXParsingError(err)
59
+
60
+
61
+ def parse_latex(sympy, strict=False):
62
+ antlr4 = import_module('antlr4')
63
+
64
+ if None in [antlr4, MathErrorListener] or \
65
+ not version('antlr4-python3-runtime').startswith('4.11'):
66
+ raise ImportError("LaTeX parsing requires the antlr4 Python package,"
67
+ " provided by pip (antlr4-python3-runtime) or"
68
+ " conda (antlr-python-runtime), version 4.11")
69
+
70
+ sympy = sympy.strip()
71
+ matherror = MathErrorListener(sympy)
72
+
73
+ stream = antlr4.InputStream(sympy)
74
+ lex = LaTeXLexer(stream)
75
+ lex.removeErrorListeners()
76
+ lex.addErrorListener(matherror)
77
+
78
+ tokens = antlr4.CommonTokenStream(lex)
79
+ parser = LaTeXParser(tokens)
80
+
81
+ # remove default console error listener
82
+ parser.removeErrorListeners()
83
+ parser.addErrorListener(matherror)
84
+
85
+ relation = parser.math().relation()
86
+ if strict and (relation.start.start != 0 or relation.stop.stop != len(sympy) - 1):
87
+ raise LaTeXParsingError("Invalid LaTeX")
88
+ expr = convert_relation(relation)
89
+
90
+ return expr
91
+
92
+
93
+ def convert_relation(rel):
94
+ if rel.expr():
95
+ return convert_expr(rel.expr())
96
+
97
+ lh = convert_relation(rel.relation(0))
98
+ rh = convert_relation(rel.relation(1))
99
+ if rel.LT():
100
+ return sympy.StrictLessThan(lh, rh)
101
+ elif rel.LTE():
102
+ return sympy.LessThan(lh, rh)
103
+ elif rel.GT():
104
+ return sympy.StrictGreaterThan(lh, rh)
105
+ elif rel.GTE():
106
+ return sympy.GreaterThan(lh, rh)
107
+ elif rel.EQUAL():
108
+ return sympy.Eq(lh, rh)
109
+ elif rel.NEQ():
110
+ return sympy.Ne(lh, rh)
111
+
112
+
113
+ def convert_expr(expr):
114
+ return convert_add(expr.additive())
115
+
116
+
117
+ def convert_add(add):
118
+ if add.ADD():
119
+ lh = convert_add(add.additive(0))
120
+ rh = convert_add(add.additive(1))
121
+ return sympy.Add(lh, rh, evaluate=False)
122
+ elif add.SUB():
123
+ lh = convert_add(add.additive(0))
124
+ rh = convert_add(add.additive(1))
125
+ if hasattr(rh, "is_Atom") and rh.is_Atom:
126
+ return sympy.Add(lh, -1 * rh, evaluate=False)
127
+ return sympy.Add(lh, sympy.Mul(-1, rh, evaluate=False), evaluate=False)
128
+ else:
129
+ return convert_mp(add.mp())
130
+
131
+
132
+ def convert_mp(mp):
133
+ if hasattr(mp, 'mp'):
134
+ mp_left = mp.mp(0)
135
+ mp_right = mp.mp(1)
136
+ else:
137
+ mp_left = mp.mp_nofunc(0)
138
+ mp_right = mp.mp_nofunc(1)
139
+
140
+ if mp.MUL() or mp.CMD_TIMES() or mp.CMD_CDOT():
141
+ lh = convert_mp(mp_left)
142
+ rh = convert_mp(mp_right)
143
+ return sympy.Mul(lh, rh, evaluate=False)
144
+ elif mp.DIV() or mp.CMD_DIV() or mp.COLON():
145
+ lh = convert_mp(mp_left)
146
+ rh = convert_mp(mp_right)
147
+ return sympy.Mul(lh, sympy.Pow(rh, -1, evaluate=False), evaluate=False)
148
+ else:
149
+ if hasattr(mp, 'unary'):
150
+ return convert_unary(mp.unary())
151
+ else:
152
+ return convert_unary(mp.unary_nofunc())
153
+
154
+
155
+ def convert_unary(unary):
156
+ if hasattr(unary, 'unary'):
157
+ nested_unary = unary.unary()
158
+ else:
159
+ nested_unary = unary.unary_nofunc()
160
+ if hasattr(unary, 'postfix_nofunc'):
161
+ first = unary.postfix()
162
+ tail = unary.postfix_nofunc()
163
+ postfix = [first] + tail
164
+ else:
165
+ postfix = unary.postfix()
166
+
167
+ if unary.ADD():
168
+ return convert_unary(nested_unary)
169
+ elif unary.SUB():
170
+ numabs = convert_unary(nested_unary)
171
+ # Use Integer(-n) instead of Mul(-1, n)
172
+ return -numabs
173
+ elif postfix:
174
+ return convert_postfix_list(postfix)
175
+
176
+
177
+ def convert_postfix_list(arr, i=0):
178
+ if i >= len(arr):
179
+ raise LaTeXParsingError("Index out of bounds")
180
+
181
+ res = convert_postfix(arr[i])
182
+ if isinstance(res, sympy.Expr):
183
+ if i == len(arr) - 1:
184
+ return res # nothing to multiply by
185
+ else:
186
+ if i > 0:
187
+ left = convert_postfix(arr[i - 1])
188
+ right = convert_postfix(arr[i + 1])
189
+ if isinstance(left, sympy.Expr) and isinstance(
190
+ right, sympy.Expr):
191
+ left_syms = convert_postfix(arr[i - 1]).atoms(sympy.Symbol)
192
+ right_syms = convert_postfix(arr[i + 1]).atoms(
193
+ sympy.Symbol)
194
+ # if the left and right sides contain no variables and the
195
+ # symbol in between is 'x', treat as multiplication.
196
+ if not (left_syms or right_syms) and str(res) == 'x':
197
+ return convert_postfix_list(arr, i + 1)
198
+ # multiply by next
199
+ return sympy.Mul(
200
+ res, convert_postfix_list(arr, i + 1), evaluate=False)
201
+ else: # must be derivative
202
+ wrt = res[0]
203
+ if i == len(arr) - 1:
204
+ raise LaTeXParsingError("Expected expression for derivative")
205
+ else:
206
+ expr = convert_postfix_list(arr, i + 1)
207
+ return sympy.Derivative(expr, wrt)
208
+
209
+
210
+ def do_subs(expr, at):
211
+ if at.expr():
212
+ at_expr = convert_expr(at.expr())
213
+ syms = at_expr.atoms(sympy.Symbol)
214
+ if len(syms) == 0:
215
+ return expr
216
+ elif len(syms) > 0:
217
+ sym = next(iter(syms))
218
+ return expr.subs(sym, at_expr)
219
+ elif at.equality():
220
+ lh = convert_expr(at.equality().expr(0))
221
+ rh = convert_expr(at.equality().expr(1))
222
+ return expr.subs(lh, rh)
223
+
224
+
225
+ def convert_postfix(postfix):
226
+ if hasattr(postfix, 'exp'):
227
+ exp_nested = postfix.exp()
228
+ else:
229
+ exp_nested = postfix.exp_nofunc()
230
+
231
+ exp = convert_exp(exp_nested)
232
+ for op in postfix.postfix_op():
233
+ if op.BANG():
234
+ if isinstance(exp, list):
235
+ raise LaTeXParsingError("Cannot apply postfix to derivative")
236
+ exp = sympy.factorial(exp, evaluate=False)
237
+ elif op.eval_at():
238
+ ev = op.eval_at()
239
+ at_b = None
240
+ at_a = None
241
+ if ev.eval_at_sup():
242
+ at_b = do_subs(exp, ev.eval_at_sup())
243
+ if ev.eval_at_sub():
244
+ at_a = do_subs(exp, ev.eval_at_sub())
245
+ if at_b is not None and at_a is not None:
246
+ exp = sympy.Add(at_b, -1 * at_a, evaluate=False)
247
+ elif at_b is not None:
248
+ exp = at_b
249
+ elif at_a is not None:
250
+ exp = at_a
251
+
252
+ return exp
253
+
254
+
255
+ def convert_exp(exp):
256
+ if hasattr(exp, 'exp'):
257
+ exp_nested = exp.exp()
258
+ else:
259
+ exp_nested = exp.exp_nofunc()
260
+
261
+ if exp_nested:
262
+ base = convert_exp(exp_nested)
263
+ if isinstance(base, list):
264
+ raise LaTeXParsingError("Cannot raise derivative to power")
265
+ if exp.atom():
266
+ exponent = convert_atom(exp.atom())
267
+ elif exp.expr():
268
+ exponent = convert_expr(exp.expr())
269
+ return sympy.Pow(base, exponent, evaluate=False)
270
+ else:
271
+ if hasattr(exp, 'comp'):
272
+ return convert_comp(exp.comp())
273
+ else:
274
+ return convert_comp(exp.comp_nofunc())
275
+
276
+
277
+ def convert_comp(comp):
278
+ if comp.group():
279
+ return convert_expr(comp.group().expr())
280
+ elif comp.abs_group():
281
+ return sympy.Abs(convert_expr(comp.abs_group().expr()), evaluate=False)
282
+ elif comp.atom():
283
+ return convert_atom(comp.atom())
284
+ elif comp.floor():
285
+ return convert_floor(comp.floor())
286
+ elif comp.ceil():
287
+ return convert_ceil(comp.ceil())
288
+ elif comp.func():
289
+ return convert_func(comp.func())
290
+
291
+
292
+ def convert_atom(atom):
293
+ if atom.LETTER():
294
+ sname = atom.LETTER().getText()
295
+ if atom.subexpr():
296
+ if atom.subexpr().expr(): # subscript is expr
297
+ subscript = convert_expr(atom.subexpr().expr())
298
+ else: # subscript is atom
299
+ subscript = convert_atom(atom.subexpr().atom())
300
+ sname += '_{' + StrPrinter().doprint(subscript) + '}'
301
+ if atom.SINGLE_QUOTES():
302
+ sname += atom.SINGLE_QUOTES().getText() # put after subscript for easy identify
303
+ return sympy.Symbol(sname)
304
+ elif atom.SYMBOL():
305
+ s = atom.SYMBOL().getText()[1:]
306
+ if s == "infty":
307
+ return sympy.oo
308
+ else:
309
+ if atom.subexpr():
310
+ subscript = None
311
+ if atom.subexpr().expr(): # subscript is expr
312
+ subscript = convert_expr(atom.subexpr().expr())
313
+ else: # subscript is atom
314
+ subscript = convert_atom(atom.subexpr().atom())
315
+ subscriptName = StrPrinter().doprint(subscript)
316
+ s += '_{' + subscriptName + '}'
317
+ return sympy.Symbol(s)
318
+ elif atom.number():
319
+ s = atom.number().getText().replace(",", "")
320
+ return sympy.Number(s)
321
+ elif atom.DIFFERENTIAL():
322
+ var = get_differential_var(atom.DIFFERENTIAL())
323
+ return sympy.Symbol('d' + var.name)
324
+ elif atom.mathit():
325
+ text = rule2text(atom.mathit().mathit_text())
326
+ return sympy.Symbol(text)
327
+ elif atom.frac():
328
+ return convert_frac(atom.frac())
329
+ elif atom.binom():
330
+ return convert_binom(atom.binom())
331
+ elif atom.bra():
332
+ val = convert_expr(atom.bra().expr())
333
+ return Bra(val)
334
+ elif atom.ket():
335
+ val = convert_expr(atom.ket().expr())
336
+ return Ket(val)
337
+
338
+
339
+ def rule2text(ctx):
340
+ stream = ctx.start.getInputStream()
341
+ # starting index of starting token
342
+ startIdx = ctx.start.start
343
+ # stopping index of stopping token
344
+ stopIdx = ctx.stop.stop
345
+
346
+ return stream.getText(startIdx, stopIdx)
347
+
348
+
349
+ def convert_frac(frac):
350
+ diff_op = False
351
+ partial_op = False
352
+ if frac.lower and frac.upper:
353
+ lower_itv = frac.lower.getSourceInterval()
354
+ lower_itv_len = lower_itv[1] - lower_itv[0] + 1
355
+ if (frac.lower.start == frac.lower.stop
356
+ and frac.lower.start.type == LaTeXLexer.DIFFERENTIAL):
357
+ wrt = get_differential_var_str(frac.lower.start.text)
358
+ diff_op = True
359
+ elif (lower_itv_len == 2 and frac.lower.start.type == LaTeXLexer.SYMBOL
360
+ and frac.lower.start.text == '\\partial'
361
+ and (frac.lower.stop.type == LaTeXLexer.LETTER
362
+ or frac.lower.stop.type == LaTeXLexer.SYMBOL)):
363
+ partial_op = True
364
+ wrt = frac.lower.stop.text
365
+ if frac.lower.stop.type == LaTeXLexer.SYMBOL:
366
+ wrt = wrt[1:]
367
+
368
+ if diff_op or partial_op:
369
+ wrt = sympy.Symbol(wrt)
370
+ if (diff_op and frac.upper.start == frac.upper.stop
371
+ and frac.upper.start.type == LaTeXLexer.LETTER
372
+ and frac.upper.start.text == 'd'):
373
+ return [wrt]
374
+ elif (partial_op and frac.upper.start == frac.upper.stop
375
+ and frac.upper.start.type == LaTeXLexer.SYMBOL
376
+ and frac.upper.start.text == '\\partial'):
377
+ return [wrt]
378
+ upper_text = rule2text(frac.upper)
379
+
380
+ expr_top = None
381
+ if diff_op and upper_text.startswith('d'):
382
+ expr_top = parse_latex(upper_text[1:])
383
+ elif partial_op and frac.upper.start.text == '\\partial':
384
+ expr_top = parse_latex(upper_text[len('\\partial'):])
385
+ if expr_top:
386
+ return sympy.Derivative(expr_top, wrt)
387
+ if frac.upper:
388
+ expr_top = convert_expr(frac.upper)
389
+ else:
390
+ expr_top = sympy.Number(frac.upperd.text)
391
+ if frac.lower:
392
+ expr_bot = convert_expr(frac.lower)
393
+ else:
394
+ expr_bot = sympy.Number(frac.lowerd.text)
395
+ inverse_denom = sympy.Pow(expr_bot, -1, evaluate=False)
396
+ if expr_top == 1:
397
+ return inverse_denom
398
+ else:
399
+ return sympy.Mul(expr_top, inverse_denom, evaluate=False)
400
+
401
+ def convert_binom(binom):
402
+ expr_n = convert_expr(binom.n)
403
+ expr_k = convert_expr(binom.k)
404
+ return sympy.binomial(expr_n, expr_k, evaluate=False)
405
+
406
+ def convert_floor(floor):
407
+ val = convert_expr(floor.val)
408
+ return sympy.floor(val, evaluate=False)
409
+
410
+ def convert_ceil(ceil):
411
+ val = convert_expr(ceil.val)
412
+ return sympy.ceiling(val, evaluate=False)
413
+
414
+ def convert_func(func):
415
+ if func.func_normal():
416
+ if func.L_PAREN(): # function called with parenthesis
417
+ arg = convert_func_arg(func.func_arg())
418
+ else:
419
+ arg = convert_func_arg(func.func_arg_noparens())
420
+
421
+ name = func.func_normal().start.text[1:]
422
+
423
+ # change arc<trig> -> a<trig>
424
+ if name in [
425
+ "arcsin", "arccos", "arctan", "arccsc", "arcsec", "arccot"
426
+ ]:
427
+ name = "a" + name[3:]
428
+ expr = getattr(sympy.functions, name)(arg, evaluate=False)
429
+ if name in ["arsinh", "arcosh", "artanh"]:
430
+ name = "a" + name[2:]
431
+ expr = getattr(sympy.functions, name)(arg, evaluate=False)
432
+
433
+ if name == "exp":
434
+ expr = sympy.exp(arg, evaluate=False)
435
+
436
+ if name in ("log", "lg", "ln"):
437
+ if func.subexpr():
438
+ if func.subexpr().expr():
439
+ base = convert_expr(func.subexpr().expr())
440
+ else:
441
+ base = convert_atom(func.subexpr().atom())
442
+ elif name == "lg": # ISO 80000-2:2019
443
+ base = 10
444
+ elif name in ("ln", "log"): # SymPy's latex printer prints ln as log by default
445
+ base = sympy.E
446
+ expr = sympy.log(arg, base, evaluate=False)
447
+
448
+ func_pow = None
449
+ should_pow = True
450
+ if func.supexpr():
451
+ if func.supexpr().expr():
452
+ func_pow = convert_expr(func.supexpr().expr())
453
+ else:
454
+ func_pow = convert_atom(func.supexpr().atom())
455
+
456
+ if name in [
457
+ "sin", "cos", "tan", "csc", "sec", "cot", "sinh", "cosh",
458
+ "tanh"
459
+ ]:
460
+ if func_pow == -1:
461
+ name = "a" + name
462
+ should_pow = False
463
+ expr = getattr(sympy.functions, name)(arg, evaluate=False)
464
+
465
+ if func_pow and should_pow:
466
+ expr = sympy.Pow(expr, func_pow, evaluate=False)
467
+
468
+ return expr
469
+ elif func.LETTER() or func.SYMBOL():
470
+ if func.LETTER():
471
+ fname = func.LETTER().getText()
472
+ elif func.SYMBOL():
473
+ fname = func.SYMBOL().getText()[1:]
474
+ fname = str(fname) # can't be unicode
475
+ if func.subexpr():
476
+ if func.subexpr().expr(): # subscript is expr
477
+ subscript = convert_expr(func.subexpr().expr())
478
+ else: # subscript is atom
479
+ subscript = convert_atom(func.subexpr().atom())
480
+ subscriptName = StrPrinter().doprint(subscript)
481
+ fname += '_{' + subscriptName + '}'
482
+ if func.SINGLE_QUOTES():
483
+ fname += func.SINGLE_QUOTES().getText()
484
+ input_args = func.args()
485
+ output_args = []
486
+ while input_args.args(): # handle multiple arguments to function
487
+ output_args.append(convert_expr(input_args.expr()))
488
+ input_args = input_args.args()
489
+ output_args.append(convert_expr(input_args.expr()))
490
+ return sympy.Function(fname)(*output_args)
491
+ elif func.FUNC_INT():
492
+ return handle_integral(func)
493
+ elif func.FUNC_SQRT():
494
+ expr = convert_expr(func.base)
495
+ if func.root:
496
+ r = convert_expr(func.root)
497
+ return sympy.root(expr, r, evaluate=False)
498
+ else:
499
+ return sympy.sqrt(expr, evaluate=False)
500
+ elif func.FUNC_OVERLINE():
501
+ expr = convert_expr(func.base)
502
+ return sympy.conjugate(expr, evaluate=False)
503
+ elif func.FUNC_SUM():
504
+ return handle_sum_or_prod(func, "summation")
505
+ elif func.FUNC_PROD():
506
+ return handle_sum_or_prod(func, "product")
507
+ elif func.FUNC_LIM():
508
+ return handle_limit(func)
509
+
510
+
511
+ def convert_func_arg(arg):
512
+ if hasattr(arg, 'expr'):
513
+ return convert_expr(arg.expr())
514
+ else:
515
+ return convert_mp(arg.mp_nofunc())
516
+
517
+
518
+ def handle_integral(func):
519
+ if func.additive():
520
+ integrand = convert_add(func.additive())
521
+ elif func.frac():
522
+ integrand = convert_frac(func.frac())
523
+ else:
524
+ integrand = 1
525
+
526
+ int_var = None
527
+ if func.DIFFERENTIAL():
528
+ int_var = get_differential_var(func.DIFFERENTIAL())
529
+ else:
530
+ for sym in integrand.atoms(sympy.Symbol):
531
+ s = str(sym)
532
+ if len(s) > 1 and s[0] == 'd':
533
+ if s[1] == '\\':
534
+ int_var = sympy.Symbol(s[2:])
535
+ else:
536
+ int_var = sympy.Symbol(s[1:])
537
+ int_sym = sym
538
+ if int_var:
539
+ integrand = integrand.subs(int_sym, 1)
540
+ else:
541
+ # Assume dx by default
542
+ int_var = sympy.Symbol('x')
543
+
544
+ if func.subexpr():
545
+ if func.subexpr().atom():
546
+ lower = convert_atom(func.subexpr().atom())
547
+ else:
548
+ lower = convert_expr(func.subexpr().expr())
549
+ if func.supexpr().atom():
550
+ upper = convert_atom(func.supexpr().atom())
551
+ else:
552
+ upper = convert_expr(func.supexpr().expr())
553
+ return sympy.Integral(integrand, (int_var, lower, upper))
554
+ else:
555
+ return sympy.Integral(integrand, int_var)
556
+
557
+
558
+ def handle_sum_or_prod(func, name):
559
+ val = convert_mp(func.mp())
560
+ iter_var = convert_expr(func.subeq().equality().expr(0))
561
+ start = convert_expr(func.subeq().equality().expr(1))
562
+ if func.supexpr().expr(): # ^{expr}
563
+ end = convert_expr(func.supexpr().expr())
564
+ else: # ^atom
565
+ end = convert_atom(func.supexpr().atom())
566
+
567
+ if name == "summation":
568
+ return sympy.Sum(val, (iter_var, start, end))
569
+ elif name == "product":
570
+ return sympy.Product(val, (iter_var, start, end))
571
+
572
+
573
+ def handle_limit(func):
574
+ sub = func.limit_sub()
575
+ if sub.LETTER():
576
+ var = sympy.Symbol(sub.LETTER().getText())
577
+ elif sub.SYMBOL():
578
+ var = sympy.Symbol(sub.SYMBOL().getText()[1:])
579
+ else:
580
+ var = sympy.Symbol('x')
581
+ if sub.SUB():
582
+ direction = "-"
583
+ elif sub.ADD():
584
+ direction = "+"
585
+ else:
586
+ direction = "+-"
587
+ approaching = convert_expr(sub.expr())
588
+ content = convert_mp(func.mp())
589
+
590
+ return sympy.Limit(content, var, approaching, direction)
591
+
592
+
593
+ def get_differential_var(d):
594
+ text = get_differential_var_str(d.getText())
595
+ return sympy.Symbol(text)
596
+
597
+
598
+ def get_differential_var_str(text):
599
+ for i in range(1, len(text)):
600
+ c = text[i]
601
+ if not (c == " " or c == "\r" or c == "\n" or c == "\t"):
602
+ idx = i
603
+ break
604
+ text = text[idx:]
605
+ if text[0] == "\\":
606
+ text = text[1:]
607
+ return text
evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/latex/errors.py ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ class LaTeXParsingError(Exception):
2
+ pass
evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/latex/lark/__init__.py ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ from .latex_parser import parse_latex_lark, LarkLaTeXParser # noqa
2
+ from .transformer import TransformToSymPyExpr # noqa
evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/latex/lark/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (318 Bytes). View file
 
evalkit_tf437/lib/python3.10/site-packages/sympy/parsing/latex/lark/__pycache__/latex_parser.cpython-310.pyc ADDED
Binary file (4.16 kB). View file