1 2 %{ 3 /**************************************************************************** 4 ** 5 ** Copyright (C) 2015 The Qt Company Ltd. 6 ** Contact: http://www.qt.io/licensing/ 7 ** 8 ** This file is part of the QLALR tool of the Qt Toolkit. 9 ** 10 ** $QT_BEGIN_LICENSE:LGPL$ 11 ** Commercial License Usage 12 ** Licensees holding valid commercial Qt licenses may use this file in 13 ** accordance with the commercial license agreement provided with the 14 ** Software or, alternatively, in accordance with the terms contained in 15 ** a written agreement between you and The Qt Company. For licensing terms 16 ** and conditions see http://www.qt.io/terms-conditions. For further 17 ** information use the contact form at http://www.qt.io/contact-us. 18 ** 19 ** GNU Lesser General Public License Usage 20 ** Alternatively, this file may be used under the terms of the GNU Lesser 21 ** General Public License version 2.1 or version 3 as published by the Free 22 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and 23 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the 24 ** following information to ensure the GNU Lesser General Public License 25 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and 26 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 27 ** 28 ** As a special exception, The Qt Company gives you certain additional 29 ** rights. These rights are described in The Qt Company LGPL Exception 30 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 31 ** 32 ** GNU General Public License Usage 33 ** Alternatively, this file may be used under the terms of the GNU 34 ** General Public License version 3.0 as published by the Free Software 35 ** Foundation and appearing in the file LICENSE.GPL included in the 36 ** packaging of this file. Please review the following information to 37 ** ensure the GNU General Public License version 3.0 requirements will be 38 ** met: http://www.gnu.org/copyleft/gpl.html. 39 ** 40 ** $QT_END_LICENSE$ 41 ** 42 ****************************************************************************/ 43 44 #include <cassert> 45 #define YY_DECL int GLSLParser::nextToken() 46 %} 47 48 %option noyywrap 49 50 hex [0-9a-fA-F] 51 dec [1-9][0-9]* 52 oct [0-7] 53 digit [0-9] 54 55 fract {digit}*\.{digit}+|{digit}+\. 56 exp [eE][+-]?{digit}+ 57 58 hexfract {hex}*\.{hex}+|{hex}+\. 59 binexp [pP][+-]?{digit}+ 60 61 icst ({dec}|0{oct}*|0[xX]{hex}+) 62 63 %% 64 65 [\n] { ++context.line; } 66 [ \t\r]+ { /* skip */ } 67 68 "+=" { return ADD_ASSIGN; } 69 "&" { return AMPERSAND; } 70 "&=" { return AND_ASSIGN; } 71 "&&" { return AND_OP; } 72 "attribute" { return ATTRIBUTE; } 73 "!" { return BANG; } 74 "bool" { return BOOL; } 75 "true" { return BOOLCONSTANT; } 76 "false" { return BOOLCONSTANT; } 77 "break" { return BREAK; } 78 "bvec2" { return BVEC2; } 79 "bvec3" { return BVEC3; } 80 "bvec4" { return BVEC4; } 81 ":" { return COLON; } 82 "," { return COMMA; } 83 "const" { return CONST; } 84 "continue" { return CONTINUE; } 85 "-" { return DASH; } 86 "--" { return DEC_OP; } 87 "discard" { return DISCARD; } 88 "/=" { return DIV_ASSIGN; } 89 "do" { return DO; } 90 "." { return DOT; } 91 "else" { return ELSE; } 92 "=" { return EQUAL; } 93 "==" { return EQ_OP; } 94 "float" { return FLOAT; } 95 "for" { return FOR; } 96 ">=" { return GE_OP; } 97 "if" { return IF; } 98 "in" { return IN; } 99 "++" { return INC_OP; } 100 "inout" { return INOUT; } 101 "int" { return INT; } 102 "ivec2" { return IVEC2; } 103 "ivec3" { return IVEC3; } 104 "ivec4" { return IVEC4; } 105 "<" { return LEFT_ANGLE; } 106 "<<=" { return LEFT_ASSIGN; } 107 "{" { return LEFT_BRACE; } 108 "[" { return LEFT_BRACKET; } 109 "<<" { return LEFT_OP; } 110 "(" { return LEFT_PAREN; } 111 "<=" { return LE_OP; } 112 "mat2" { return MAT2; } 113 "mat3" { return MAT3; } 114 "mat4" { return MAT4; } 115 "%=" { return MOD_ASSIGN; } 116 "*=" { return MUL_ASSIGN; } 117 "!=" { return NE_OP; } 118 "|=" { return OR_ASSIGN; } 119 "||" { return OR_OP; } 120 "out" { return OUT; } 121 "%" { return PERCENT; } 122 "+" { return PLUS; } 123 "?" { return QUESTION; } 124 "return" { return RETURN; } 125 ">" { return RIGHT_ANGLE; } 126 ">>=" { return RIGHT_ASSIGN; } 127 "}" { return RIGHT_BRACE; } 128 "]" { return RIGHT_BRACKET; } 129 ">>" { return RIGHT_OP; } 130 ")" { return RIGHT_PAREN; } 131 "sampler1D" { return SAMPLER1D; } 132 "sampler1DShadow" { return SAMPLER1DSHADOW; } 133 "sampler2D" { return SAMPLER2D; } 134 "sampler2DShadow" { return SAMPLER2DSHADOW; } 135 "sampler3D" { return SAMPLER3D; } 136 "samplerCube" { return SAMPLERCUBE; } 137 ";" { return SEMICOLON; } 138 "/" { return SLASH; } 139 "*" { return STAR; } 140 "struct" { return STRUCT; } 141 "-=" { return SUB_ASSIGN; } 142 "~" { return TILDE; } 143 "uniform" { return UNIFORM; } 144 "varying" { return VARYING; } 145 "vec2" { return VEC2; } 146 "vec3" { return VEC3; } 147 "vec4" { return VEC4; } 148 "|" { return VERTICAL_BAR; } 149 "void" { return VOID; } 150 "while" { return WHILE; } 151 "^=" { return XOR_ASSIGN; } 152 "^" { return XOR_OP; } 153 "highp" { return HIGH_PRECISION; } 154 "mediump" { return MEDIUM_PRECISION; } 155 "lowp" { return LOW_PRECISION; } 156 157 #[ \t]+[0-9]+.* { 158 char *eptr = 0; 159 context.line = (int) strtod(&yytext[1], &eptr); 160 QString fn = QString::fromUtf8(eptr).trimmed(); 161 if (fn.length() > 2) 162 context.fileName = fn.mid(1, fn.length()-2); 163 } 164 165 #.* { 166 /* skip */ 167 } 168 169 [_a-zA-Z][_a-zA-Z0-9]* { 170 yylval.s = intern (yytext); 171 172 if (isTypename (yylval.s)) 173 return TYPE_NAME; 174 175 return IDENTIFIER; 176 } 177 178 {icst} { 179 yylval.i = (int) strtol (yytext, 0, 0); 180 return INTCONSTANT; 181 } 182 183 {icst}[uU] { 184 yylval.u = (unsigned) strtoul (yytext, 0, 0); 185 return INTCONSTANT; 186 } 187 188 {icst}[uU][lL] { 189 yylval.ul = strtoul (yytext, 0, 0); 190 return INTCONSTANT; 191 } 192 193 {icst}[lL][uU] { 194 yylval.ul = strtoul (yytext, 0, 0); 195 return INTCONSTANT; 196 } 197 198 {icst}[lL] { 199 yylval.l = strtol (yytext, 0, 0); 200 return INTCONSTANT; 201 } 202 203 {icst}[uU](ll|LL) { 204 yylval.l = strtoull (yytext, 0, 0); 205 return INTCONSTANT; 206 } 207 208 {icst}(ll|LL) { 209 yylval.l = strtoll (yytext, 0, 0); 210 return INTCONSTANT; 211 } 212 213 {icst}(ll|LL)[uU] { 214 yylval.l = strtoull (yytext, 0, 0); 215 return INTCONSTANT; 216 } 217 218 {fract}{exp}?[flFL]? { 219 yylval.f = strtof (yytext, 0); 220 return FLOATCONSTANT; 221 } 222 223 {digit}+{exp}[flFL]? { 224 yylval.f = strtof (yytext, 0); 225 return FLOATCONSTANT; 226 } 227 228 0[xX]{hexfract}{binexp}[flFL]? { 229 yylval.f = strtof (yytext, 0); 230 return FLOATCONSTANT; 231 } 232 233 0[xX]{hex}+{binexp}[flFL]? { 234 yylval.f = strtof (yytext, 0); 235 return FLOATCONSTANT; 236 } 237 238 . { 239 fprintf (stderr, "invalid char: %d\n", yytext [0]); 240 return ERROR; 241 } 242 243 244 %% 245 246