Add syntax files for expression and directive preprocessor.
[mesa.git] / src / mesa / shader / slang / library / slang_pp_expression.syn
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.6
4 *
5 * Copyright (C) 2006 Brian Paul All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25 /**
26 * \file slang_pp_expression.syn
27 * slang preprocessor expression parser
28 * \author Michal Krol
29 */
30
31 /*
32 * Parses one or two (optional) expressions on literal integer constants. Those expressions come
33 * from #if #elif and #line directives. The preprocessor already parsed those directives and
34 * expanded the expression (expressions). All occurences of the operator "defined" are already
35 * replaced with either "0" or "1" literals.
36 */
37
38 .syntax expression;
39
40 /*
41 * Those separate individual expressions.
42 * For #if/#elif case it is: EXP_EXPRESSION ... EXP_END
43 * For #line case it may be: EXP_EXPRESSION ... EXP_EXPRESSION ... EXP_END
44 */
45 .emtcode EXP_END 0
46 .emtcode EXP_EXPRESSION 1
47
48 .emtcode OP_END 0
49 .emtcode OP_PUSHINT 1
50 .emtcode OP_LOGICALOR 2
51 .emtcode OP_LOGICALAND 3
52 .emtcode OP_OR 4
53 .emtcode OP_XOR 5
54 .emtcode OP_AND 6
55 .emtcode OP_EQUAL 7
56 .emtcode OP_NOTEQUAL 8
57 .emtcode OP_LESSEQUAL 9
58 .emtcode OP_GREATEREQUAL 10
59 .emtcode OP_LESS 11
60 .emtcode OP_GREATER 12
61 .emtcode OP_LEFTSHIFT 13
62 .emtcode OP_RIGHTSHIFT 14
63 .emtcode OP_ADD 15
64 .emtcode OP_SUBTRACT 16
65 .emtcode OP_MULTIPLY 17
66 .emtcode OP_DIVIDE 18
67 .emtcode OP_MODULUS 19
68 .emtcode OP_PLUS 20
69 .emtcode OP_MINUS 21
70 .emtcode OP_NEGATE 22
71 .emtcode OP_COMPLEMENT 23
72
73 expression
74 first_expression .and optional_second_expression .and optional_space .and '\0' .emit EXP_END;
75
76 first_expression
77 optional_space .and logical_or_expression .emit EXP_EXPRESSION .and .true .emit OP_END;
78
79 optional_second_expression
80 second_expression .or .true;
81
82 second_expression
83 space .and logical_or_expression .emit EXP_EXPRESSION .and .true .emit OP_END;
84
85 logical_or_expression
86 logical_and_expression .and .loop logical_or_expression_1;
87 logical_or_expression_1
88 barbar .and logical_and_expression .and .true .emit OP_LOGICALOR;
89
90 logical_and_expression
91 or_expression .and .loop logical_and_expression_1;
92 logical_and_expression_1
93 ampersandampersand .and or_expression .and .true .emit OP_LOGICALAND;
94
95 or_expression
96 xor_expression .and .loop or_expression_1;
97 or_expression_1
98 bar .and xor_expression .and .true .emit OP_OR;
99
100 xor_expression
101 and_expression .and .loop xor_expression_1;
102 xor_expression_1
103 caret .and and_expression .and .true .emit OP_XOR;
104
105 and_expression
106 equality_expression .and .loop and_expression_1;
107 and_expression_1
108 ampersand .and equality_expression .and .true .emit OP_AND;
109
110 equality_expression
111 relational_expression .and .loop equality_expression_1;
112 equality_expression_1
113 equality_expression_2 .or equality_expression_3;
114 equality_expression_2
115 equalsequals .and relational_expression .and .true .emit OP_EQUAL;
116 equality_expression_3
117 bangequals .and relational_expression .and .true .emit OP_NOTEQUAL;
118
119 relational_expression
120 shift_expression .and .loop relational_expression_1;
121 relational_expression_1
122 relational_expression_2 .or relational_expression_3 .or relational_expression_4 .or
123 relational_expression_5;
124 relational_expression_2
125 lessequals .and shift_expression .and .true .emit OP_LESSEQUAL;
126 relational_expression_3
127 greaterequals .and shift_expression .and .true .emit OP_GREATEREQUAL;
128 relational_expression_4
129 less .and shift_expression .and .true .emit OP_LESS;
130 relational_expression_5
131 greater .and shift_expression .and .true .emit OP_GREATER;
132
133 shift_expression
134 additive_expression .and .loop shift_expression_1;
135 shift_expression_1
136 shift_expression_2 .or shift_expression_3;
137 shift_expression_2
138 lessless .and additive_expression .and .true .emit OP_LEFTSHIFT;
139 shift_expression_3
140 greatergreater .and additive_expression .and .true .emit OP_RIGHTSHIFT;
141
142 additive_expression
143 multiplicative_expression .and .loop additive_expression_1;
144 additive_expression_1
145 additive_expression_2 .or additive_expression_3;
146 additive_expression_2
147 plus .and multiplicative_expression .and .true .emit OP_ADD;
148 additive_expression_3
149 dash .and multiplicative_expression .and .true .emit OP_SUBTRACT;
150
151 multiplicative_expression
152 unary_expression .and .loop multiplicative_expression_1;
153 multiplicative_expression_1
154 multiplicative_expression_2 .or multiplicative_expression_3 .or multiplicative_expression_4;
155 multiplicative_expression_2
156 star .and unary_expression .and .true .emit OP_MULTIPLY;
157 multiplicative_expression_3
158 slash .and unary_expression .and .true .emit OP_DIVIDE;
159 multiplicative_expression_4
160 percent .and unary_expression .and .true .emit OP_MODULUS;
161
162 unary_expression
163 primary_expression .or unary_expression_1 .or unary_expression_2 .or unary_expression_3 .or
164 unary_expression_4;
165 unary_expression_1
166 plus .and unary_expression .and .true .emit OP_PLUS;
167 unary_expression_2
168 dash .and unary_expression .and .true .emit OP_MINUS;
169 unary_expression_3
170 bang .and unary_expression .and .true .emit OP_NEGATE;
171 unary_expression_4
172 tilda .and unary_expression .and .true .emit OP_COMPLEMENT;
173
174 primary_expression
175 intconstant .or primary_expression_1;
176 primary_expression_1
177 lparen .and logical_or_expression .and rparen;
178
179 intconstant
180 integer .emit OP_PUSHINT;
181
182 integer
183 integer_dec;
184
185 integer_dec
186 digit_dec .emit 10 .emit * .and .loop digit_dec .emit * .and .true .emit '\0';
187
188 digit_dec
189 '0'-'9';
190
191 optional_space
192 .loop single_space;
193
194 space
195 single_space .and .loop single_space;
196
197 single_space
198 ' ' .or '\t';
199
200 ampersand
201 optional_space .and '&' .and optional_space;
202
203 ampersandampersand
204 optional_space .and '&' .and '&' .and optional_space;
205
206 bang
207 optional_space .and '!' .and optional_space;
208
209 bangequals
210 optional_space .and '!' .and '=' .and optional_space;
211
212 bar
213 optional_space .and '|' .and optional_space;
214
215 barbar
216 optional_space .and '|' .and '|' .and optional_space;
217
218 caret
219 optional_space .and '^' .and optional_space;
220
221 dash
222 optional_space .and '-' .and optional_space;
223
224 equalsequals
225 optional_space .and '=' .and '=' .and optional_space;
226
227 greater
228 optional_space .and '>' .and optional_space;
229
230 greaterequals
231 optional_space .and '>' .and '=' .and optional_space;
232
233 greatergreater
234 optional_space .and '>' .and '>' .and optional_space;
235
236 less
237 optional_space .and '<' .and optional_space;
238
239 lessequals
240 optional_space .and '<' .and '=' .and optional_space;
241
242 lessless
243 optional_space .and '<' .and '<' .and optional_space;
244
245 lparen
246 optional_space .and '(' .and optional_space;
247
248 percent
249 optional_space .and '%' .and optional_space;
250
251 plus
252 optional_space .and '+' .and optional_space;
253
254 rparen
255 optional_space .and ')' .and optional_space;
256
257 slash
258 optional_space .and '/' .and optional_space;
259
260 star
261 optional_space .and '*' .and optional_space;
262
263 tilda
264 optional_space .and '~' .and optional_space;
265