2 * Mesa 3-D graphics library
5 * Copyright (C) 2006 Brian Paul All Rights Reserved.
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:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
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.
26 * \file slang_pp_expression.syn
27 * slang preprocessor expression parser
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.
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
46 .emtcode EXP_EXPRESSION 1
50 .emtcode OP_LOGICALOR 2
51 .emtcode OP_LOGICALAND 3
56 .emtcode OP_NOTEQUAL 8
57 .emtcode OP_LESSEQUAL 9
58 .emtcode OP_GREATEREQUAL 10
60 .emtcode OP_GREATER 12
61 .emtcode OP_LEFTSHIFT 13
62 .emtcode OP_RIGHTSHIFT 14
64 .emtcode OP_SUBTRACT 16
65 .emtcode OP_MULTIPLY 17
67 .emtcode OP_MODULUS 19
71 .emtcode OP_COMPLEMENT 23
74 first_expression .and optional_second_expression .and optional_space .and '\0' .emit EXP_END;
77 optional_space .and logical_or_expression .emit EXP_EXPRESSION .and .true .emit OP_END;
79 optional_second_expression
80 second_expression .or .true;
83 space .and logical_or_expression .emit EXP_EXPRESSION .and .true .emit OP_END;
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;
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;
96 xor_expression .and .loop or_expression_1;
98 bar .and xor_expression .and .true .emit OP_OR;
101 and_expression .and .loop xor_expression_1;
103 caret .and and_expression .and .true .emit OP_XOR;
106 equality_expression .and .loop and_expression_1;
108 ampersand .and equality_expression .and .true .emit OP_AND;
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;
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;
134 additive_expression .and .loop shift_expression_1;
136 shift_expression_2 .or shift_expression_3;
138 lessless .and additive_expression .and .true .emit OP_LEFTSHIFT;
140 greatergreater .and additive_expression .and .true .emit OP_RIGHTSHIFT;
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;
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;
163 primary_expression .or unary_expression_1 .or unary_expression_2 .or unary_expression_3 .or
166 plus .and unary_expression .and .true .emit OP_PLUS;
168 dash .and unary_expression .and .true .emit OP_MINUS;
170 bang .and unary_expression .and .true .emit OP_NEGATE;
172 tilda .and unary_expression .and .true .emit OP_COMPLEMENT;
175 intconstant .or primary_expression_1;
177 lparen .and logical_or_expression .and rparen;
180 integer .emit OP_PUSHINT;
186 digit_dec .emit 10 .emit * .and .loop digit_dec .emit * .and .true .emit '\0';
195 single_space .and .loop single_space;
201 optional_space .and '&' .and optional_space;
204 optional_space .and '&' .and '&' .and optional_space;
207 optional_space .and '!' .and optional_space;
210 optional_space .and '!' .and '=' .and optional_space;
213 optional_space .and '|' .and optional_space;
216 optional_space .and '|' .and '|' .and optional_space;
219 optional_space .and '^' .and optional_space;
222 optional_space .and '-' .and optional_space;
225 optional_space .and '=' .and '=' .and optional_space;
228 optional_space .and '>' .and optional_space;
231 optional_space .and '>' .and '=' .and optional_space;
234 optional_space .and '>' .and '>' .and optional_space;
237 optional_space .and '<' .and optional_space;
240 optional_space .and '<' .and '=' .and optional_space;
243 optional_space .and '<' .and '<' .and optional_space;
246 optional_space .and '(' .and optional_space;
249 optional_space .and '%' .and optional_space;
252 optional_space .and '+' .and optional_space;
255 optional_space .and ')' .and optional_space;
258 optional_space .and '/' .and optional_space;
261 optional_space .and '*' .and optional_space;
264 optional_space .and '~' .and optional_space;