summaryrefslogtreecommitdiffstats
path: root/util/qlalr/examples/glsl/glsl-lex.l
blob: 1e07c3b71e266f5b99d96612a9283829d525811b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201

%{
#include <cassert>
#define YY_DECL int GLSLParser::nextToken()
%}

%option noyywrap

hex [0-9a-fA-F]
dec [1-9][0-9]*
oct [0-7]
digit [0-9]

fract {digit}*\.{digit}+|{digit}+\.
exp [eE][+-]?{digit}+

hexfract {hex}*\.{hex}+|{hex}+\.
binexp [pP][+-]?{digit}+

icst ({dec}|0{oct}*|0[xX]{hex}+)

%%

[\n]					{ ++context.line; }
[ \t\r]+				{ /* skip */ }

"+=" { return ADD_ASSIGN; }
"&" { return AMPERSAND; }
"&=" { return AND_ASSIGN; }
"&&" { return AND_OP; }
"attribute" { return ATTRIBUTE; }
"!" { return BANG; }
"bool" { return BOOL; }
"true" { return BOOLCONSTANT; }
"false" { return BOOLCONSTANT; }
"break" { return BREAK; }
"bvec2" { return BVEC2; }
"bvec3" { return BVEC3; }
"bvec4" { return BVEC4; }
":" { return COLON; }
"," { return COMMA; }
"const" { return CONST; }
"continue" { return CONTINUE; }
"-" { return DASH; }
"--" { return DEC_OP; }
"discard" { return DISCARD; }
"/=" { return DIV_ASSIGN; }
"do" { return DO; }
"." { return DOT; }
"else" { return ELSE; }
"=" { return EQUAL; }
"==" { return EQ_OP; }
"float" { return FLOAT; }
"for" { return FOR; }
">=" { return GE_OP; }
"if" { return IF; }
"in" { return IN; }
"++" { return INC_OP; }
"inout" { return INOUT; }
"int" { return INT; }
"ivec2" { return IVEC2; }
"ivec3" { return IVEC3; }
"ivec4" { return IVEC4; }
"<" { return LEFT_ANGLE; }
"<<=" { return LEFT_ASSIGN; }
"{" { return LEFT_BRACE; }
"[" { return LEFT_BRACKET; }
"<<" { return LEFT_OP; }
"(" { return LEFT_PAREN; }
"<=" { return LE_OP; }
"mat2" { return MAT2; }
"mat3" { return MAT3; }
"mat4" { return MAT4; }
"%=" { return MOD_ASSIGN; }
"*=" { return MUL_ASSIGN; }
"!=" { return NE_OP; }
"|=" { return OR_ASSIGN; }
"||" { return OR_OP; }
"out" { return OUT; }
"%" { return PERCENT; }
"+" { return PLUS; }
"?" { return QUESTION; }
"return" { return RETURN; }
">" { return RIGHT_ANGLE; }
">>=" { return RIGHT_ASSIGN; }
"}" { return RIGHT_BRACE; }
"]" { return RIGHT_BRACKET; }
">>" { return RIGHT_OP; }
")" { return RIGHT_PAREN; }
"sampler1D" { return SAMPLER1D; }
"sampler1DShadow" { return SAMPLER1DSHADOW; }
"sampler2D" { return SAMPLER2D; }
"sampler2DShadow" { return SAMPLER2DSHADOW; }
"sampler3D" { return SAMPLER3D; }
"samplerCube" { return SAMPLERCUBE; }
";" { return SEMICOLON; }
"/" { return SLASH; }
"*" { return STAR; }
"struct" { return STRUCT; }
"-=" { return SUB_ASSIGN; }
"~" { return TILDE; }
"uniform" { return UNIFORM; }
"varying" { return VARYING; }
"vec2" { return VEC2; }
"vec3" { return VEC3; }
"vec4" { return VEC4; }
"|" { return VERTICAL_BAR; }
"void" { return VOID; }
"while" { return WHILE; }
"^=" { return XOR_ASSIGN; }
"^" { return XOR_OP; }

#[ \t]+[0-9]+.* {
  char *eptr = 0;
  context.line = (int) strtod(&yytext[1], &eptr);
  QString fn = QString::fromUtf8(eptr).trimmed();
  if (fn.length() > 2)
    context.fileName = fn.mid(1, fn.length()-2);
}

#.* {
  /* skip */
}

[_a-zA-Z][_a-zA-Z0-9]* {
  yylval.s = intern (yytext);

  if (isTypename (yylval.s))
    return TYPE_NAME;

  return IDENTIFIER;
}

{icst} {
  yylval.i = (int) strtol (yytext, 0, 0);
  return INTCONSTANT;
}

{icst}[uU] {
  yylval.u = (unsigned) strtoul (yytext, 0, 0);
  return INTCONSTANT;
}

{icst}[uU][lL] {
  yylval.ul = strtoul (yytext, 0, 0);
  return INTCONSTANT;
}

{icst}[lL][uU] {
  yylval.ul = strtoul (yytext, 0, 0);
  return INTCONSTANT;
}

{icst}[lL] {
  yylval.l = strtol (yytext, 0, 0);
  return INTCONSTANT;
}

{icst}[uU](ll|LL) {
  yylval.l = strtoull (yytext, 0, 0);
  return INTCONSTANT;
}

{icst}(ll|LL) {
  yylval.l = strtoll (yytext, 0, 0);
  return INTCONSTANT;
}

{icst}(ll|LL)[uU] {
  yylval.l = strtoull (yytext, 0, 0);
  return INTCONSTANT;
}

{fract}{exp}?[flFL]? {
  yylval.f = strtof (yytext, 0);
  return FLOATCONSTANT;
}

{digit}+{exp}[flFL]? {
  yylval.f = strtof (yytext, 0);
  return FLOATCONSTANT;
}

0[xX]{hexfract}{binexp}[flFL]? {
  yylval.f = strtof (yytext, 0);
  return FLOATCONSTANT;
}

0[xX]{hex}+{binexp}[flFL]? {
  yylval.f = strtof (yytext, 0);
  return FLOATCONSTANT;
}

. {
  fprintf (stderr, "invalid char: %d\n", yytext [0]);
  return ERROR;
}


%%