aboutsummaryrefslogtreecommitdiff
path: root/Auxiliary/Grammars/kranc2.peg
blob: 9111540a0c84e1cddeac95fdb8fa5a8ceaba4846 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
skipper = \b([ \t\n\r]+|#.*)*
int = [0-9]+
end = ([ \t]+|#.*)*\r*\n
name = [A-Za-z][A-Za-z0-9]*
uname = [A-Za-z][A-Za-z0-9_]*
lower_index = ({index_symbol}|\({index_expr}(,{index_expr})*\))
upper_index = ({index_symbol}|\({index_expr}(,{index_expr})*\))
indices = (\_{lower_index}+|\^{upper_index}+)*
index_symbol = [a-zA-Z]'*|[0-9]
index_op = [+-]
index_expr = {index_symbol}({index_op}{int}|)
tensor = {name}{indices}
dname = D[a-z0-9]*
dtensor = {dname}{indices}? {tensor} # Can this "?" be removed?
number = -?[0-9]+(\.[0-9]*|)([eEdD][+-]?[0-9]+|)
func = {name} \( ({expr}( , {expr})*|) \)
value = {func}|{dtensor}|-?{tensor}|{number}|-?\( {expr} \)
pow = {value}( \*\* {value}|)
mulop = [*/%]
mul = {pow}( {mulop} {pow})*
addop = [+-]
expr = {mul}( {addop} {mul})*
eqn = ({dtensor}|{tensor}) \= {expr}{-end}
deqn = {dtensor} \= {expr}{-end}
eqns = {eqn}( {eqn})*
deqns = {deqn}( {deqn})*
at_or_in = (at|in)
schedule = scheduled[ \t]+{at_or_in}[ \t]{uname}
thorn = begin[ ]+thorn {name}{-end}( {calculation}| {variables}| {temporaries}| {derivatives}| {option})* end[ ]+thorn
calculation = begin[ \t]+calculation[ \t]+{uname}[ \t]+{schedule}{-end} {eqns} end[ \t]+calculation
variables = begin[ \t]+variables{-end} ( end[ \t]+variables\b{brk}| {tensor})*{-end}
temporaries = begin[ \t]+temporaries{-end} ( end[ \t]+temporaries\b{brk}| {tensor})*{-end}
option = {inherit}|{use}|{disable}|{implement}
inherit = inherit[ \t]+({uname}[ \t]*)+{-end}
feature = loopcontrol|vectors|opencl|jacobian|cse
use = use[ \t]+({feature}[ \t]*)+
disable = disable[ \t]+({feature}[ \t]*)+
implement = implement[ \t]+{uname}{-end}
derivatives = begin[ \t]+derivatives{-end} {deqns} end[ \t]+derivatives