3 * Copyright © 2010 Intel Corporation
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
29 #include "glcpp-parse.h"
32 %option reentrant noyywrap
33 %option extra-type="glcpp_parser_t *"
39 HASH ^{HSPACE}*#{HSPACE}*
40 IDENTIFIER [_a-zA-Z][_a-zA-Z0-9]*
41 PUNCTUATION [][(){}.&*~!/%<>^|;,=+-]
42 OTHER [^][(){}.&*~!/%<>^|;,=#[:space:]+-]+
44 DECIMAL_INTEGER [1-9][0-9]*[uU]?
45 OCTAL_INTEGER 0[0-7]*[uU]?
46 HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]?
50 /* Single-line comments */
55 /* Multi-line comments */
56 [/][*]([^*]*[*]+[^/])*[^*]*[*]*[/] {
57 if (yyextra->space_tokens)
62 yyextra->lexing_if = 1;
63 yyextra->space_tokens = 0;
68 yyextra->lexing_if = 1;
69 yyextra->space_tokens = 0;
74 yyextra->space_tokens = 0;
79 yyextra->space_tokens = 0;
83 /* When skipping (due to an #if 0 or similar) consume anything
84 * up to a newline. We do this less priroty than any
85 * #if-related directive (#if, #elif, #else, #endif), but with
86 * more priority than any other directive or token to avoid
87 * any side-effects from skipped content.
89 * We use the lexing_if flag to avoid skipping any part of an
90 * if conditional expression. */
92 if (yyextra->lexing_if ||
93 yyextra->skip_stack == NULL ||
94 yyextra->skip_stack->type == SKIP_NO_SKIP)
100 {HASH}define{HSPACE}+/{IDENTIFIER}"(" {
101 yyextra->space_tokens = 0;
102 return HASH_DEFINE_FUNC;
106 yyextra->space_tokens = 0;
107 return HASH_DEFINE_OBJ;
111 yyextra->space_tokens = 0;
116 yyextra->space_tokens = 0;
121 yylval.str = xtalloc_strdup (yyextra, yytext);
122 return INTEGER_STRING;
126 yylval.str = xtalloc_strdup (yyextra, yytext);
127 return INTEGER_STRING;
130 {HEXADECIMAL_INTEGER} {
131 yylval.str = xtalloc_strdup (yyextra, yytext);
132 return INTEGER_STRING;
144 return LESS_OR_EQUAL;
148 return GREATER_OR_EQUAL;
176 yylval.str = xtalloc_strdup (yyextra, yytext);
185 yylval.str = xtalloc_strdup (yyextra, yytext);
190 if (yyextra->space_tokens) {
196 yyextra->lexing_if = 0;