-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathduck2.cfg
173 lines (173 loc) · 5.03 KB
/
duck2.cfg
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
; *************************
; * Duck Syntax *
; * Version 0.2.17.5.15 *
; *************************
; root symbol
<program> ::= <top-level-block>
;
; root level stmts
<top-level-block> ::= <top-level-stmt> <top-level-block>
<top-level-block> ::= <epsilon>
;
; one or more comma separated identifiers
<identifier-list> ::= <identifier> , <identifier-list>
<identifier-list> ::= <identifier>
;
; optional endlines
<optendl> ::= <endl>
<optendl> ::= <epsilon>
;
; import, include, module, or statement are top level
<top-level-stmt> ::= import <identifier-list> <endl>
<top-level-stmt> ::= include <string> <endl>
<top-level-stmt> ::= module <identifier> <endl> <block> endmodule <endl>
<top-level-stmt> ::= <stmt>
;
; statement block
<block> ::= <stmt> <block>
<block> ::= <epsilon>
;
; program statements
<stmt> ::= <expr> <endl>
<stmt> ::= <assignment> <endl>
<stmt> ::= <self-assignment> <endl>
<stmt> ::= <class> <endl>
<stmt> ::= <function> <endl>
<stmt> ::= <if> <endl>
<stmt> ::= <for> <endl>
<stmt> ::= <while> <endl>
<stmt> ::= <let-block> <endl>
<stmt> ::= <try-block> <endl>
<stmt> ::= return <endl>
<stmt> ::= return <expr> <endl>
<stmt> ::= continue <endl>
<stmt> ::= break <endl>
<stmt> ::= throw <expr> <endl>
<stmt> ::= <endl>
;
; class structure
<class> ::= class <identifier> <endl> <class-body>
<class> ::= class <identifier> extends <identifier-list> <endl> <class-body>
<class-body> ::= <class-block> endclass
<class-block> ::= <class-stmt> <class-block>
<class-block> ::= <epsilon>
<class-stmt> ::= static <assignment> <endl>
<class-stmt> ::= static <function> <endl>
<class-stmt> ::= <assignment> <endl>
<class-stmt> ::= <function> <endl>
<class-stmt> ::= <endl>
;
; function definitions
<function> ::= func <identifier> <function-def>
<function> ::= func <string> <function-def>
<function-def> ::= <parameters> <endl> <block> endfunc
;
; function definition parameters
<parameters> ::= ( <identifier-list> )
<parameters> ::= ( )
<parameters> ::= <epsilon>
;
; function call arguments
<arguments> ::= <epsilon>
<arguments> ::= <expr-list>
<expr-list> ::= <expr> , <expr-list>
<expr-list> ::= <expr>
;
; if conditions
<if> ::= if <condition> then <endl> <block> <elseif>
<elseif> ::= else <endl> <block> endif
<elseif> ::= else <if>
<elseif> ::= endif
;
; for-to and for-in loops
<for> ::= for <identifier> <for-start>
<for-start> ::= = <arithmetic> to <arithmetic> do <endl> <loop-end>
<for-start> ::= = <arithmetic> to <arithmetic> step <arithmetic> do <endl> <loop-end>
<for-start> ::= in <final> do <endl> <loop-end>
;
; while and do-while loops
<while> ::= while <condition> do <endl> <loop-end>
<while> ::= do <endl> <block> loop while <condition>
<loop-end> ::= <block> loop
;
; let block
<let-block> ::= let <bindings> <endl> begin <endl> <block> end
<bindings> ::= <binding> , <optendl> <bindings>
<bindings> ::= <binding>
<binding> ::= <identifier> = <expr>
;
; try exception catching blocks
<try-block> ::= try <endl> <block> <catch-block>
<catch-block> ::= catch <l-value> <endl> <block> done
<catch-block> ::= done
;
; assignment statements
<assignment> ::= <l-value> = <expr>
<assignment> ::= <l-value> = <object>
<self-assignment> ::= <l-value> += <arithmetic>
<self-assignment> ::= <l-value> -= <arithmetic>
<self-assignment> ::= <l-value> *= <arithmetic>
<self-assignment> ::= <l-value> /= <arithmetic>
<self-assignment> ::= <l-value> ++
<self-assignment> ::= <l-value> --
;
; l-value, assignables
<l-value> ::= <identifier>
<l-value> ::= <l-value> [ <arithmetic> ]
<l-value> ::= <l-value> . <identifier>
;
; associative arithmetic and logic
<expr> ::= <condition>
<condition> ::= <condition> and <logic>
<condition> ::= <condition> or <logic>
<condition> ::= <logic>
<logic> ::= not <comparison>
<logic> ::= <comparison>
<comparison> ::= <comparison> == <arithmetic>
<comparison> ::= <comparison> != <arithmetic>
<comparison> ::= <comparison> \< <arithmetic>
<comparison> ::= <comparison> > <arithmetic>
<comparison> ::= <comparison> \<= <arithmetic>
<comparison> ::= <comparison> >= <arithmetic>
<comparison> ::= <final> is <l-value>
<comparison> ::= <final> is not <l-value>
<comparison> ::= <arithmetic>
<arithmetic> ::= <arithmetic> + <term>
<arithmetic> ::= <arithmetic> - <term>
<arithmetic> ::= <term>
<term> ::= <term> * <factor>
<term> ::= <term> / <factor>
<term> ::= <term> mod <factor>
<term> ::= <factor>
<factor> ::= - <value>
<factor> ::= ! <value>
<factor> ::= <value>
;
; basic value
<value> ::= <primitive>
<value> ::= <l-value>
<value> ::= <l-value> ( <arguments> )
<value> ::= new <l-value> ( <arguments> )
<value> ::= ( <expr> )
;
; primitive values
<primitive> ::= true
<primitive> ::= false
<primitive> ::= <integer>
<primitive> ::= <float>
<primitive> ::= <string>
;
; object initializers
<object> ::= [ <optendl> ]
<object> ::= [ <optendl> <array-init>
<object> ::= [ <optendl> <dictionary-init>
;
; arrays
<array-init> ::= <expr> , <optendl> <array-init>
<array-init> ::= <expr> <optendl> ]
;
; objects
<dictionary-init> ::= <dictionary-entry> , <optendl> <dictionary-init>
<dictionary-init> ::= <dictionary-entry> ]
<dictionary-entry> ::= <identifier> : <optendl> <expr>
; EOF