-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkpython-syntax.k
More file actions
91 lines (81 loc) · 3.79 KB
/
Copy pathkpython-syntax.k
File metadata and controls
91 lines (81 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
module KPYTHON-SYNTAX
imports DOMAINS-SYNTAX
syntax Id ::= "Object" [token] | "Main" [token] | "__init__" [token] //legacy
syntax Decl ::= "var" Exps ";"
| "def" Id "(" Ids ")" Block
| "def" Id "(" "self" ")" Block
| "def" Id "(" "self" "," Ids ")" Block
| "class" Id Block
| "class" Id "(" Id ")" Block
syntax Exp ::= Int | Bool | String | Id
| "True"
| "False"
| "self"
| "super" "(" ")"
| "(" Exp ")" [bracket]
| "[" Exps "]" [strict]
| "range" "(" Exps ")" [strict]
| "isinstance" "(" Exp "," Id ")" [strict(1)]
| "(" Id ")" Exp [strict(2)]
| Exp "." Id
> Exp "[" Exps "]" [strict]
> Exp "(" Exps ")" [strict(2)]
| "-" Exp [strict]
| "len" "(" Exp ")" [strict]
| "read" "(" ")"
> left:
Exp "*" Exp [strict, left]
| Exp "/" Exp [strict, left]
| Exp "%" Exp [strict, left]
> left:
Exp "+" Exp [strict, left]
| Exp "-" Exp [strict, left]
> non-assoc:
Exp "<" Exp [strict, non-assoc]
| Exp "<=" Exp [strict, non-assoc]
| Exp ">" Exp [strict, non-assoc]
| Exp ">=" Exp [strict, non-assoc]
| Exp "==" Exp [strict, non-assoc]
| Exp "!=" Exp [strict, non-assoc]
| Exp "in" Exp [strict, non-assoc]
| Exp "not" "in" Exp [strict, non-assoc]
> "not" Exp [strict]
> left:
Exp "and" Exp [strict(1), left]
| Exp "or" Exp [strict(1), left]
> Exp "if" Exp "else" Exp [strict(2), right]
> Exp "=" Exp [strict(2), right]
syntax Ids ::= List{Id,","}
syntax Exps ::= List{Exp,","} [strict]
syntax Block ::= "{" "}"
| "{" Stmts "}"
syntax Stmt ::= Decl | Block
| Exp ";" [strict]
| Exp "+=" Exp ";" [strict(2), right]
| Exp "-=" Exp ";" [strict(2), right]
| Exp "*=" Exp ";" [strict(2), right]
| Exp "/=" Exp ";" [strict(2), right]
| Exp "%=" Exp ";" [strict(2), right]
| "if" Exp Block "else" Block [strict(1), avoid]
| "if" Exp Block [strict(1)]
| "if" "__name__" "==" "'__main__'" Block
| "while" Exp Block
| "for" Exp "in" Exp Block [strict(2)]
| "return" Exp ";" [strict]
| "return" ";"
| "print" "(" Exps ")" ";" [strict]
| "try" Block "except" Id Block
| "raise" Exp ";" [strict]
| "pass" ";"
| "break" ";"
| "continue" ";"
syntax Stmts ::= Stmt
| Stmts Stmts [right]
syntax SimpleVal ::= Int | Bool | String
syntax CombinedVal ::= array(Int,Int)
syntax NoneVal ::= "None"
syntax Val ::= SimpleVal | CombinedVal | NoneVal
syntax Vals ::= List{Val,","}
syntax Exp ::= Val
syntax Exps ::= Vals
endmodule