2010-05-10 11:44:09 -07:00
|
|
|
%{
|
|
|
|
/*
|
|
|
|
* 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>
|
|
|
|
|
2010-05-10 13:17:25 -07:00
|
|
|
#include "glcpp.h"
|
2010-05-10 11:44:09 -07:00
|
|
|
#include "glcpp-parse.h"
|
|
|
|
%}
|
|
|
|
|
2010-05-10 11:52:29 -07:00
|
|
|
%option reentrant noyywrap
|
2010-05-12 12:45:33 -07:00
|
|
|
%option extra-type="glcpp_parser_t *"
|
2010-05-10 11:44:09 -07:00
|
|
|
|
2010-05-25 15:04:32 -07:00
|
|
|
/* This lexer has two states:
|
|
|
|
*
|
|
|
|
* The CONTROL state is for control lines (directives)
|
|
|
|
* It lexes exactly as specified in the C99 specification.
|
|
|
|
*
|
|
|
|
* The INITIAL state is for input lines. In this state, we
|
|
|
|
* make the OTHER token much more broad in that it now
|
|
|
|
* includes tokens consisting entirely of whitespace. This
|
|
|
|
* allows us to pass text through verbatim. It avoids the
|
|
|
|
* "inadvertent token pasting" problem that would occur if we
|
|
|
|
* just printed tokens, while also avoiding excess whitespace
|
|
|
|
* insertion in the output.*/
|
|
|
|
|
|
|
|
%x CONTROL
|
|
|
|
|
2010-05-10 16:16:06 -07:00
|
|
|
SPACE [[:space:]]
|
|
|
|
NONSPACE [^[:space:]]
|
2010-05-12 12:17:10 -07:00
|
|
|
NEWLINE [\n]
|
2010-05-10 16:16:06 -07:00
|
|
|
HSPACE [ \t]
|
2010-05-14 17:29:24 -07:00
|
|
|
HASH ^{HSPACE}*#{HSPACE}*
|
2010-05-10 16:16:06 -07:00
|
|
|
IDENTIFIER [_a-zA-Z][_a-zA-Z0-9]*
|
2010-05-25 13:09:03 -07:00
|
|
|
PUNCTUATION [][(){}.&*~!/%<>^|;,+-]
|
|
|
|
OTHER [^][(){}.&*~!/%<>^|;,=#[:space:]+-]+
|
2010-05-12 12:17:10 -07:00
|
|
|
|
2010-05-24 11:29:02 -07:00
|
|
|
DECIMAL_INTEGER [1-9][0-9]*[uU]?
|
|
|
|
OCTAL_INTEGER 0[0-7]*[uU]?
|
|
|
|
HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]?
|
|
|
|
|
2010-05-10 11:44:09 -07:00
|
|
|
%%
|
|
|
|
|
2010-05-25 13:09:03 -07:00
|
|
|
{HASH}define{HSPACE}+/{IDENTIFIER}"(" {
|
2010-05-25 15:04:32 -07:00
|
|
|
BEGIN CONTROL;
|
2010-05-25 13:09:03 -07:00
|
|
|
return HASH_DEFINE_FUNC;
|
2010-05-20 22:27:07 -07:00
|
|
|
}
|
|
|
|
|
2010-05-25 13:09:03 -07:00
|
|
|
{HASH}define {
|
2010-05-25 15:04:32 -07:00
|
|
|
BEGIN CONTROL;
|
2010-05-25 13:09:03 -07:00
|
|
|
return HASH_DEFINE_OBJ;
|
2010-05-24 11:29:02 -07:00
|
|
|
}
|
|
|
|
|
2010-05-25 13:09:03 -07:00
|
|
|
{HASH}undef {
|
2010-05-25 15:04:32 -07:00
|
|
|
BEGIN CONTROL;
|
2010-05-25 13:09:03 -07:00
|
|
|
return HASH_UNDEF;
|
2010-05-24 11:29:02 -07:00
|
|
|
}
|
|
|
|
|
2010-05-25 13:09:03 -07:00
|
|
|
{HASH} {
|
2010-05-25 15:04:32 -07:00
|
|
|
BEGIN CONTROL;
|
2010-05-25 13:09:03 -07:00
|
|
|
return HASH;
|
2010-05-20 22:27:07 -07:00
|
|
|
}
|
|
|
|
|
2010-05-25 15:04:32 -07:00
|
|
|
<CONTROL>{IDENTIFIER} {
|
2010-05-25 13:09:03 -07:00
|
|
|
yylval.str = xtalloc_strdup (yyextra, yytext);
|
|
|
|
return IDENTIFIER;
|
2010-05-24 10:37:38 -07:00
|
|
|
}
|
|
|
|
|
2010-05-25 15:04:32 -07:00
|
|
|
<CONTROL>"<<" {
|
2010-05-24 10:37:38 -07:00
|
|
|
return LEFT_SHIFT;
|
|
|
|
}
|
|
|
|
|
2010-05-25 15:04:32 -07:00
|
|
|
<CONTROL>">>" {
|
2010-05-24 10:37:38 -07:00
|
|
|
return RIGHT_SHIFT;
|
|
|
|
}
|
|
|
|
|
2010-05-25 15:04:32 -07:00
|
|
|
<CONTROL>"<=" {
|
2010-05-24 10:37:38 -07:00
|
|
|
return LESS_OR_EQUAL;
|
|
|
|
}
|
|
|
|
|
2010-05-25 15:04:32 -07:00
|
|
|
<CONTROL>">=" {
|
2010-05-24 10:37:38 -07:00
|
|
|
return GREATER_OR_EQUAL;
|
|
|
|
}
|
|
|
|
|
2010-05-25 15:04:32 -07:00
|
|
|
<CONTROL>"==" {
|
2010-05-24 10:37:38 -07:00
|
|
|
return EQUAL;
|
|
|
|
}
|
|
|
|
|
2010-05-25 15:04:32 -07:00
|
|
|
<CONTROL>"!=" {
|
2010-05-24 10:37:38 -07:00
|
|
|
return NOT_EQUAL;
|
|
|
|
}
|
|
|
|
|
2010-05-25 15:04:32 -07:00
|
|
|
<CONTROL>"&&" {
|
2010-05-24 10:37:38 -07:00
|
|
|
return AND;
|
|
|
|
}
|
|
|
|
|
2010-05-25 15:04:32 -07:00
|
|
|
<CONTROL>"||" {
|
2010-05-24 10:37:38 -07:00
|
|
|
return OR;
|
|
|
|
}
|
|
|
|
|
2010-05-25 15:04:32 -07:00
|
|
|
<CONTROL>"##" {
|
2010-05-25 13:09:03 -07:00
|
|
|
return PASTE;
|
2010-05-20 22:27:07 -07:00
|
|
|
}
|
|
|
|
|
2010-05-25 15:04:32 -07:00
|
|
|
<CONTROL>{PUNCTUATION} {
|
2010-05-25 13:09:03 -07:00
|
|
|
return yytext[0];
|
2010-05-19 13:28:24 -07:00
|
|
|
}
|
|
|
|
|
2010-05-25 15:04:32 -07:00
|
|
|
<CONTROL>{OTHER} {
|
|
|
|
yylval.str = xtalloc_strdup (yyextra, yytext);
|
|
|
|
return OTHER;
|
|
|
|
}
|
|
|
|
|
|
|
|
<CONTROL>{HSPACE}+
|
|
|
|
|
|
|
|
<CONTROL>\n {
|
|
|
|
BEGIN INITIAL;
|
2010-05-19 13:28:24 -07:00
|
|
|
return NEWLINE;
|
2010-05-17 13:19:04 -07:00
|
|
|
}
|
|
|
|
|
2010-05-25 15:04:32 -07:00
|
|
|
{IDENTIFIER} {
|
|
|
|
yylval.str = xtalloc_strdup (yyextra, yytext);
|
|
|
|
return IDENTIFIER;
|
|
|
|
}
|
|
|
|
|
2010-05-25 16:28:26 -07:00
|
|
|
"(" {
|
|
|
|
return '(';
|
|
|
|
}
|
|
|
|
|
|
|
|
")" {
|
|
|
|
return ')';
|
|
|
|
}
|
|
|
|
|
|
|
|
"," {
|
|
|
|
return ',';
|
|
|
|
}
|
|
|
|
|
2010-05-25 15:04:32 -07:00
|
|
|
{OTHER}+ {
|
|
|
|
yylval.str = xtalloc_strdup (yyextra, yytext);
|
|
|
|
return OTHER;
|
|
|
|
}
|
|
|
|
|
|
|
|
{HSPACE}+ {
|
2010-05-18 22:10:04 -07:00
|
|
|
yylval.str = xtalloc_strdup (yyextra, yytext);
|
2010-05-25 16:28:26 -07:00
|
|
|
return SPACE;
|
2010-05-12 13:19:23 -07:00
|
|
|
}
|
|
|
|
|
2010-05-25 15:04:32 -07:00
|
|
|
\n {
|
|
|
|
return NEWLINE;
|
|
|
|
}
|
|
|
|
|
|
|
|
. {
|
|
|
|
yylval.str = xtalloc_strdup (yyextra, yytext);
|
|
|
|
return OTHER;
|
|
|
|
}
|
2010-05-12 13:19:23 -07:00
|
|
|
|
2010-05-10 11:44:09 -07:00
|
|
|
%%
|