blob: 70d47d24975fa90c4668ad0a51ffc8b7134f102a [file] [log] [blame]
Carl Worth3a37b872010-05-10 11:44:09 -07001%{
2/*
3 * Copyright © 2010 Intel Corporation
4 *
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:
11 *
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
14 * Software.
15 *
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.
23 */
24
25#include <stdio.h>
26#include <string.h>
27
Carl Wortha1e32bc2010-05-10 13:17:25 -070028#include "glcpp.h"
Carl Worth3a37b872010-05-10 11:44:09 -070029#include "glcpp-parse.h"
30%}
31
Carl Worth38aa8352010-05-10 11:52:29 -070032%option reentrant noyywrap
Carl Worth5070a202010-05-12 12:45:33 -070033%option extra-type="glcpp_parser_t *"
Carl Worth3a37b872010-05-10 11:44:09 -070034
Carl Worth0b27b5f2010-05-10 16:16:06 -070035SPACE [[:space:]]
36NONSPACE [^[:space:]]
Carl Worth33cc4002010-05-12 12:17:10 -070037NEWLINE [\n]
Carl Worth0b27b5f2010-05-10 16:16:06 -070038HSPACE [ \t]
Carl Worthe36a4d52010-05-14 17:29:24 -070039HASH ^{HSPACE}*#{HSPACE}*
Carl Worth0b27b5f2010-05-10 16:16:06 -070040IDENTIFIER [_a-zA-Z][_a-zA-Z0-9]*
Carl Worth3ff81672010-05-25 13:09:03 -070041PUNCTUATION [][(){}.&*~!/%<>^|;,+-]
42OTHER [^][(){}.&*~!/%<>^|;,=#[:space:]+-]+
Carl Worth33cc4002010-05-12 12:17:10 -070043
Carl Worth03f6d5d2010-05-24 11:29:02 -070044DECIMAL_INTEGER [1-9][0-9]*[uU]?
45OCTAL_INTEGER 0[0-7]*[uU]?
46HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]?
47
Carl Worth3a37b872010-05-10 11:44:09 -070048%%
49
Carl Worth3ff81672010-05-25 13:09:03 -070050{HASH}define{HSPACE}+/{IDENTIFIER}"(" {
Carl Worthf34a0002010-05-25 16:59:02 -070051 yyextra->space_tokens = 0;
Carl Worth3ff81672010-05-25 13:09:03 -070052 return HASH_DEFINE_FUNC;
Carl Worthb20d33c2010-05-20 22:27:07 -070053}
54
Carl Worth3ff81672010-05-25 13:09:03 -070055{HASH}define {
Carl Worthf34a0002010-05-25 16:59:02 -070056 yyextra->space_tokens = 0;
Carl Worth3ff81672010-05-25 13:09:03 -070057 return HASH_DEFINE_OBJ;
Carl Worthb20d33c2010-05-20 22:27:07 -070058}
59
Carl Worth3ff81672010-05-25 13:09:03 -070060{HASH}undef {
Carl Worthf34a0002010-05-25 16:59:02 -070061 yyextra->space_tokens = 0;
Carl Worth3ff81672010-05-25 13:09:03 -070062 return HASH_UNDEF;
Carl Worth03f6d5d2010-05-24 11:29:02 -070063}
64
Carl Worth8fed1cd2010-05-26 09:32:12 -070065{HASH}if {
66 yyextra->space_tokens = 0;
67 return HASH_IF;
68}
69
70{HASH}elif {
71 yyextra->space_tokens = 0;
72 return HASH_ELIF;
73}
74
75{HASH}else {
76 yyextra->space_tokens = 0;
77 return HASH_ELSE;
78}
79
80{HASH}endif {
81 yyextra->space_tokens = 0;
82 return HASH_ENDIF;
83}
84
Carl Worth3ff81672010-05-25 13:09:03 -070085{HASH} {
Carl Worthf34a0002010-05-25 16:59:02 -070086 yyextra->space_tokens = 0;
Carl Worth3ff81672010-05-25 13:09:03 -070087 return HASH;
Carl Worth81f01432010-05-14 17:08:45 -070088}
89
Carl Worth8fed1cd2010-05-26 09:32:12 -070090{DECIMAL_INTEGER} {
Carl Worth050e3de2010-05-27 14:36:29 -070091 yylval.str = xtalloc_strdup (yyextra, yytext);
92 return INTEGER_STRING;
Carl Worth8fed1cd2010-05-26 09:32:12 -070093}
94
95{OCTAL_INTEGER} {
Carl Worth050e3de2010-05-27 14:36:29 -070096 yylval.str = xtalloc_strdup (yyextra, yytext);
97 return INTEGER_STRING;
Carl Worth8fed1cd2010-05-26 09:32:12 -070098}
99
100{HEXADECIMAL_INTEGER} {
Carl Worth050e3de2010-05-27 14:36:29 -0700101 yylval.str = xtalloc_strdup (yyextra, yytext);
102 return INTEGER_STRING;
Carl Worth8fed1cd2010-05-26 09:32:12 -0700103}
104
Carl Worthf34a0002010-05-25 16:59:02 -0700105"<<" {
106 return LEFT_SHIFT;
Carl Worthb1854fd2010-05-25 16:28:26 -0700107}
108
Carl Worthf34a0002010-05-25 16:59:02 -0700109">>" {
110 return RIGHT_SHIFT;
Carl Worthb1854fd2010-05-25 16:28:26 -0700111}
112
Carl Worthf34a0002010-05-25 16:59:02 -0700113"<=" {
114 return LESS_OR_EQUAL;
115}
116
117">=" {
118 return GREATER_OR_EQUAL;
119}
120
121"==" {
122 return EQUAL;
123}
124
125"!=" {
126 return NOT_EQUAL;
127}
128
129"&&" {
130 return AND;
131}
132
133"||" {
134 return OR;
135}
136
137"##" {
138 return PASTE;
139}
140
Carl Worth8fed1cd2010-05-26 09:32:12 -0700141"defined" {
142 return DEFINED;
143}
144
Carl Worth16c1e982010-05-26 09:35:34 -0700145{IDENTIFIER} {
146 yylval.str = xtalloc_strdup (yyextra, yytext);
147 return IDENTIFIER;
148}
149
Carl Worthf34a0002010-05-25 16:59:02 -0700150{PUNCTUATION} {
151 return yytext[0];
Carl Worthb1854fd2010-05-25 16:28:26 -0700152}
153
Carl Worth9fb8b7a2010-05-25 15:04:32 -0700154{OTHER}+ {
155 yylval.str = xtalloc_strdup (yyextra, yytext);
156 return OTHER;
Carl Worth3ff81672010-05-25 13:09:03 -0700157}
158
Carl Worth9fb8b7a2010-05-25 15:04:32 -0700159{HSPACE}+ {
Carl Worthf34a0002010-05-25 16:59:02 -0700160 if (yyextra->space_tokens) {
Carl Worthf34a0002010-05-25 16:59:02 -0700161 return SPACE;
162 }
Carl Worth0a93cbb2010-05-13 10:29:07 -0700163}
Carl Worthfcbbb462010-05-13 09:36:23 -0700164
Carl Worth3ff81672010-05-25 13:09:03 -0700165\n {
166 return NEWLINE;
Carl Worth33cc4002010-05-12 12:17:10 -0700167}
Carl Worth3a37b872010-05-10 11:44:09 -0700168
Carl Worth3a37b872010-05-10 11:44:09 -0700169%%