SCM Repository
Annotation of /branches/vis15/doc/syntax.md
Parent Directory
|
Revision Log
Revision 4478 - (view) (download)
1 : | jhr | 3822 | ## Collected syntax of Diderot |
2 : | |||
3 : | |||
4 : | :---------------|:--:|:----------- | ||
5 : | jhr | 3995 | _Program_ | ::= | { _GlobalDcl_ } [ _Block_ ] _StrandDcl_ _InitialStrands_ [ _GlobalInitially_ ] [ _GlobalUpdate_ ] |
6 : | jhr | 3822 | | | | | |
7 : | _GlobalDcl_ | ::= | _InputDcl_ | ||
8 : | | \| | _ConstDcl_ | ||
9 : | | \| | _GlobalVarDcl_ | ||
10 : | | \| | _FunctionDcl_ | ||
11 : | | | | | | ||
12 : | _InputDcl_ | ::= | **input** _ValueType_ Id [ `(` String `)` ] [ `=` _ConstExpr_ ] `;` | ||
13 : | | | | | | ||
14 : | jhr | 4463 | _ConstDcl_ | ::= | **const** _ConcreteType_ Id [ `=` _ConstExpr_ ] `;` |
15 : | jhr | 3822 | | | | | |
16 : | _GlobalVarDcl_ | ::= | _Type_ Id [ `=` _Expression_ ] `;` | ||
17 : | | | | | | ||
18 : | _FunctionDcl_ | ::= | **function** _Type_ Id `(` _Parameters_ `)` `=` _Expression_ `;` | ||
19 : | | \| | **function** _Type_ Id `(` _Parameters_ `)` _Block_ | ||
20 : | | | | | | ||
21 : | _Parameters_ | ::= | [ _Parameter_ { `,` _Parameter_ } ] | ||
22 : | | | | | | ||
23 : | _Parameter_ | ::= | _Type_ Id | ||
24 : | | | | | | ||
25 : | jhr | 4125 | _StrandDcl_ | ::= | **strand** Id _Parameters_ `{` { _StateVarDcl_ } [ _Block_ ] { _MethodDcl_ } `}` |
26 : | jhr | 3822 | | | | | |
27 : | jhr | 4463 | _StateVarDcl_ | ::= | _ConcreteType_ Id [ `=` _Expression_ ] `;` |
28 : | | | | | | ||
29 : | jhr | 3822 | _MethodDcl_ | ::= | _MethodName_ _Block_ |
30 : | | | | | | ||
31 : | _MethodName_ | ::= | **initially** \| **update** \| **stabilize** | ||
32 : | | | | | | ||
33 : | _InitialStrands_ | ::= | **collection** _Comprehension_ | ||
34 : | | \| | **grid** `(` _ConstExpr_ `)` _Comprehension_ | ||
35 : | | | | | | ||
36 : | jhr | 3995 | _GlobalInitially_ | ::= | **initially** _Block_ |
37 : | jhr | 3822 | | | | | |
38 : | jhr | 3995 | _GlobalUpdate_ | ::= | **update** _Block_ |
39 : | | | | | | ||
40 : | jhr | 3822 | _Block_ | ::= | `{` { _Statement_ } `}` |
41 : | | | | | | ||
42 : | _Statement_ | ::= | _Block_ | ||
43 : | | \| | **if** `(` _Expression_ `)` _Block_ { _ElseIf_ } [ **else** _Block_ ] | ||
44 : | | \| | **foreach** `(` _Iterator_ `)` _Block_ | ||
45 : | | \| | **print** `(` _Expression_ { `,` _Expression_ } `)` `;` | ||
46 : | | \| | **new** Id `(` _Arguments_ `)` `;` | ||
47 : | | \| | **stabilize** `;` | ||
48 : | | \| | **die** `;` | ||
49 : | | \| | **continue** `;` | ||
50 : | | \| | **return** _Expression_ `;` | ||
51 : | | \| | _Type_ Id `=` _Expression_ `;` | ||
52 : | | \| | Id _AssignOp_ _Expression_ `;` | ||
53 : | | | | | | ||
54 : | _ElseIf_ | ::= | **else** **if** `(` _Expression_ `)` _Block_ | ||
55 : | | | | | | ||
56 : | _AssignOp_ | ::= | `=` \| `+=` \| `-=` \| `*=` \| `/=` \| `%=` | ||
57 : | | | | | | ||
58 : | jhr | 4463 | _Type_ | ::= | **field** `#` _Dimension_ `(` _ConstExpr_ `)` _Shape_ |
59 : | jhr | 3822 | | \| | **kernel** `#` _Dimension_ |
60 : | jhr | 4463 | | \| | _ValueType_ |
61 : | jhr | 3822 | | | | | |
62 : | _Dimension_ | ::= | Int | ||
63 : | | | | | | ||
64 : | jhr | 4463 | _ValueType_ | ::= | **image** `(` _ConstExpr_ `)` _Shape_ |
65 : | | \| | _ConcreteType_ | ||
66 : | jhr | 3822 | | | | | |
67 : | jhr | 4463 | _ConcreteType_ | ::= | _PrimitiveType_ { _SequenceDims_ } |
68 : | | | | | | ||
69 : | jhr | 3822 | _SequenceDims_ | ::= | |
70 : | | \| | `[` `]` | ||
71 : | | \| | `[` _ConstExpr_ `]` | ||
72 : | | | | | | ||
73 : | _PrimitiveType_ | ::= | **tensor** _Shape_ | ||
74 : | | \| | **vec2** | ||
75 : | | \| | **vec3** | ||
76 : | | \| | **vec4** | ||
77 : | | \| | **mat2** | ||
78 : | | \| | **mat3** | ||
79 : | | \| | **mat4** | ||
80 : | | \| | **bool** | ||
81 : | | \| | **int** | ||
82 : | | \| | **real** | ||
83 : | | \| | **string** | ||
84 : | | | | | | ||
85 : | _Shape_ | ::= | `[` [ _ConstExpr_ { `,` _ConstExpr_ } ] `]` | ||
86 : | | | | | | ||
87 : | _Comprehension_ | ::= | `{` _Expression_ `|` _Iterator_ { `,` _Iterator_ } `}` | ||
88 : | | | | | | ||
89 : | _Iterator_ | ::= | Id **in** _Expression_ | ||
90 : | | | | | | ||
91 : | _Expression_ | ::= | _RangeExpr_ [ `?` _Expression_ `:` _Expression_ ] | ||
92 : | | | | | | ||
93 : | _RangeExpr_ | ::= | _OrExpr_ `..` _OrExpr_ | ||
94 : | | | | | | ||
95 : | _OrExpr_ | ::= | _AndExpr_ { `||` _AndExpr_ } | ||
96 : | | | | | | ||
97 : | _AndExpr_ | ::= | _CompareExpr_ { `&&` _CompareExpr_ } | ||
98 : | | | | | | ||
99 : | _CompareExpr_ | ::= | _AddExpr_ { _CompareOp_ _AddExpr_ } | ||
100 : | | | | | | ||
101 : | _CompareOp_ | ::= | `<` \| `<=` \| `==` \| `!=` \| `>=` \| `>` | ||
102 : | | | | | | ||
103 : | _AddExpr_ | ::= | _MultiplyExpr_ { _AddOp_ _MultiplyExpr_ } | ||
104 : | | | | | | ||
105 : | _AddOp_ | ::= | `+` \| `-` \| `@` | ||
106 : | | | | | | ||
107 : | _MultiplyExpr_ | ::= | _PrefixExpr_ { _MultiplyOp_ _PrefixExpr_ } | ||
108 : | | | | | | ||
109 : | _MultiplyOp_ | ::= | `*` \| `/` \| `%` \| `⊛` \| `•` \| `×` \| `⊗` \| `:` | ||
110 : | | | | | | ||
111 : | _PrefixExpr_ | ::= | _PowerExpr_ | ||
112 : | | \| | _PrefixOp_ _PrefixExpr_ | ||
113 : | | | | | | ||
114 : | _PrefixOp_ | ::= | `-` \| `!` | ||
115 : | | | | | | ||
116 : | _PowerExpr_ | ::= | _SuffixExpr_ { `^` _SuffixExpr_ } | ||
117 : | | | | | | ||
118 : | _SuffixExpr_ | ::= | _DiffExpr_ { _Suffix_ } | ||
119 : | | \| | **real** `(` _Expression_ `)` | ||
120 : | | \| | **load** `(` _ConstExpr_ `)` | ||
121 : | | \| | **image** `(` _ConstExpr_ `)` | ||
122 : | | | | | | ||
123 : | jhr | 4477 | _Suffix_ | ::= | `(` _Arguments_ `)` |
124 : | jhr | 3822 | | \| | `[` _Indices_ `]` |
125 : | | \| | `.` Id | ||
126 : | | | | | | ||
127 : | _Indices_ | ::= | _IndexExpr_ [ `,` _IndexExpr_ ] | ||
128 : | | | | | | ||
129 : | _IndexExpr_ | ::= | _Expression_ | ||
130 : | | \| | `:` | ||
131 : | | | | | | ||
132 : | _DiffExpr_ | ::= | _AtomicExpr_ | ||
133 : | | \| | _DiffOp_ _DiffExpr_ | ||
134 : | | | | | | ||
135 : | _DiffOp_ | ::= | `∇` \| `∇⊗` \| `∇×` \| `∇•` | ||
136 : | | | | | | ||
137 : | _AtomicExpr_ | ::= | Id | ||
138 : | | \| | Id `#` _Dimension_ | ||
139 : | | \| | Int | ||
140 : | | \| | Real | ||
141 : | | \| | String | ||
142 : | | \| | **true** | ||
143 : | | \| | **false** | ||
144 : | | \| | **identity** `[` _ConstExpr_ `]` | ||
145 : | | \| | **zeros** [ _Shape_ ] | ||
146 : | | \| | **nan** [ _Shape_ ] | ||
147 : | | \| | `{` _Expression_ `|` _Iterator_ `}` | ||
148 : | | \| | `(` _Expression_ { `,` _Expression_ } `)` | ||
149 : | | \| | `{` `}` | ||
150 : | | \| | `{` _Expression_ { `,` _Expression_ } `}` | ||
151 : | | \| | `[` _Expression_ { `,` _Expression_ } `]` | ||
152 : | | \| | `|` _Expression_ `|` | ||
153 : | jhr | 4477 | | \| | `(` _Expression_ `)` |
154 : | jhr | 3822 | | | | | |
155 : | _Arguments_ | ::= | [ _Expression_ { `,` _Expression_ } ] | ||
156 : | | | | | | ||
157 : | _ConstExpr_ | ::= | _Expression_ | ||
158 : | |||
159 : | |||
160 : | ### Syntactic restrictions | ||
161 : | |||
162 : | * Constant expressions (_ConstExpr_) are restricted to have a concrete type (_ConcreteType_) | ||
163 : | and be can be evaluated statically. | ||
164 : | |||
165 : | jhr | 4463 | * A sequence type can have at most one dynamic dimension (*e.g.*, `int [][3]` or |
166 : | `int [3][]`, but not `int[][]`). | ||
167 : | |||
168 : | jhr | 3822 | * When indexing a tensor or field (e.g., `e1[e2]`), the index expression must be a constant |
169 : | expression. | ||
170 : | |||
171 : | jhr | 4125 | * Conditional expressions must have value type. |
172 : | |||
173 : | * Assignment to global variables is not permitted inside strands. | ||
174 : | |||
175 : | * Strands must have an `update` method | ||
176 : | |||
177 : | jhr | 4478 | * The **stabilize** statement is only permitted inside a strand's **initially** or **update** |
178 : | method (where it affects the calling strand) or in a global **initially** or **update** | ||
179 : | block (where it stabilizes all active strands). | ||
180 : | jhr | 4477 | |
181 : | jhr | 4478 | * The **die** statement is only permitted inside a strand's **initially** or **update** |
182 : | method. | ||
183 : | |||
184 : | jhr | 4477 | ### Lexical issues |
185 : | |||
186 : | * Comments are as in C++ (either `//` to end of line or enclosed in `/*` `*/`) | ||
187 : | |||
188 : | jhr | 3822 | ### Questions |
189 : | |||
190 : | * What about tuples? Can we have sequences of tuples? Tuples of sequences? Fields inside | ||
191 : | tuples? |
root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |
Powered by ViewVC 1.0.0 |