123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- %{
- /*
- * Copyright © 2010 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
- #include <stdio.h>
- #include <string.h>
-
- #include "glcpp.h"
- #include "glcpp-parse.h"
- %}
-
- %option reentrant noyywrap
- %option extra-type="glcpp_parser_t *"
-
- SPACE [[:space:]]
- NONSPACE [^[:space:]]
- NEWLINE [\n]
- HSPACE [ \t]
- HASH ^{HSPACE}*#{HSPACE}*
- IDENTIFIER [_a-zA-Z][_a-zA-Z0-9]*
- PUNCTUATION [][(){}.&*~!/%<>^|;,=+-]
- OTHER [^][(){}.&*~!/%<>^|;,=#[:space:]+-]+
-
- DECIMAL_INTEGER [1-9][0-9]*[uU]?
- OCTAL_INTEGER 0[0-7]*[uU]?
- HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]?
-
- %%
-
- /* Single-line comments */
- "//"[^\n]+\n {
- return NEWLINE;
- }
-
- /* Multi-line comments */
- [/][*]([^*]*[*]+[^/])*[^*]*[*]*[/] {
- if (yyextra->space_tokens)
- return SPACE;
- }
-
- {HASH}if/.*\n {
- yyextra->lexing_if = 1;
- yyextra->space_tokens = 0;
- return HASH_IF;
- }
-
- {HASH}elif/.*\n {
- yyextra->lexing_if = 1;
- yyextra->space_tokens = 0;
- return HASH_ELIF;
- }
-
- {HASH}else/.*\n {
- yyextra->space_tokens = 0;
- return HASH_ELSE;
- }
-
- {HASH}endif/.*\n {
- yyextra->space_tokens = 0;
- return HASH_ENDIF;
- }
-
- /* When skipping (due to an #if 0 or similar) consume anything
- * up to a newline. We do this less priroty than any
- * #if-related directive (#if, #elif, #else, #endif), but with
- * more priority than any other directive or token to avoid
- * any side-effects from skipped content.
- *
- * We use the lexing_if flag to avoid skipping any part of an
- * if conditional expression. */
- [^\n]+/\n {
- if (yyextra->lexing_if ||
- yyextra->skip_stack == NULL ||
- yyextra->skip_stack->type == SKIP_NO_SKIP)
- {
- REJECT;
- }
- }
-
- {HASH}define{HSPACE}+/{IDENTIFIER}"(" {
- yyextra->space_tokens = 0;
- return HASH_DEFINE_FUNC;
- }
-
- {HASH}define {
- yyextra->space_tokens = 0;
- return HASH_DEFINE_OBJ;
- }
-
- {HASH}undef {
- yyextra->space_tokens = 0;
- return HASH_UNDEF;
- }
-
- {HASH} {
- yyextra->space_tokens = 0;
- return HASH;
- }
-
- {DECIMAL_INTEGER} {
- yylval.str = xtalloc_strdup (yyextra, yytext);
- return INTEGER_STRING;
- }
-
- {OCTAL_INTEGER} {
- yylval.str = xtalloc_strdup (yyextra, yytext);
- return INTEGER_STRING;
- }
-
- {HEXADECIMAL_INTEGER} {
- yylval.str = xtalloc_strdup (yyextra, yytext);
- return INTEGER_STRING;
- }
-
- "<<" {
- return LEFT_SHIFT;
- }
-
- ">>" {
- return RIGHT_SHIFT;
- }
-
- "<=" {
- return LESS_OR_EQUAL;
- }
-
- ">=" {
- return GREATER_OR_EQUAL;
- }
-
- "==" {
- return EQUAL;
- }
-
- "!=" {
- return NOT_EQUAL;
- }
-
- "&&" {
- return AND;
- }
-
- "||" {
- return OR;
- }
-
- "##" {
- return PASTE;
- }
-
- "defined" {
- return DEFINED;
- }
-
- {IDENTIFIER} {
- yylval.str = xtalloc_strdup (yyextra, yytext);
- return IDENTIFIER;
- }
-
- {PUNCTUATION} {
- return yytext[0];
- }
-
- {OTHER}+ {
- yylval.str = xtalloc_strdup (yyextra, yytext);
- return OTHER;
- }
-
- {HSPACE}+ {
- if (yyextra->space_tokens) {
- return SPACE;
- }
- }
-
- \n {
- yyextra->lexing_if = 0;
- return NEWLINE;
- }
-
- %%
|