util/qlalr/examples/glsl/glsl-lex.l
changeset 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 
       
     2 %{
       
     3 /****************************************************************************
       
     4 **
       
     5 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     6 ** All rights reserved.
       
     7 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     8 **
       
     9 ** This file is part of the QLALR tool of the Qt Toolkit.
       
    10 **
       
    11 ** $QT_BEGIN_LICENSE:LGPL$
       
    12 ** No Commercial Usage
       
    13 ** This file contains pre-release code and may not be distributed.
       
    14 ** You may use this file in accordance with the terms and conditions
       
    15 ** contained in the Technology Preview License Agreement accompanying
       
    16 ** this package.
       
    17 **
       
    18 ** GNU Lesser General Public License Usage
       
    19 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    20 ** General Public License version 2.1 as published by the Free Software
       
    21 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    22 ** packaging of this file.  Please review the following information to
       
    23 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    24 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    25 **
       
    26 ** In addition, as a special exception, Nokia gives you certain additional
       
    27 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    29 **
       
    30 ** If you have questions regarding the use of this file, please contact
       
    31 ** Nokia at qt-info@nokia.com.
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 **
       
    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