blob: f1dd11ea9bdcac0f640db4479734a9b5c1c9d748 [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}"(" {
51 return HASH_DEFINE_FUNC;
Carl Worthb20d33c2010-05-20 22:27:07 -070052}
53
Carl Worth3ff81672010-05-25 13:09:03 -070054{HASH}define {
55 return HASH_DEFINE_OBJ;
Carl Worthb20d33c2010-05-20 22:27:07 -070056}
57
Carl Worth3ff81672010-05-25 13:09:03 -070058{HASH}undef {
59 return HASH_UNDEF;
Carl Worth03f6d5d2010-05-24 11:29:02 -070060}
61
Carl Worth3ff81672010-05-25 13:09:03 -070062{HASH} {
63 return HASH;
Carl Worth81f01432010-05-14 17:08:45 -070064}
65
Carl Worth0a93cbb2010-05-13 10:29:07 -070066{IDENTIFIER} {
Carl Wortha807fb72010-05-18 22:10:04 -070067 yylval.str = xtalloc_strdup (yyextra, yytext);
Carl Worth3ff81672010-05-25 13:09:03 -070068 return IDENTIFIER;
Carl Worthcd27e642010-05-12 13:11:50 -070069}
70
Carl Worth3ff81672010-05-25 13:09:03 -070071"<<" {
72 return LEFT_SHIFT;
73}
74
75">>" {
76 return RIGHT_SHIFT;
77}
78
79"<=" {
80 return LESS_OR_EQUAL;
81}
82
83">=" {
84 return GREATER_OR_EQUAL;
85}
86
87"==" {
88 return EQUAL;
89}
90
91"!=" {
92 return NOT_EQUAL;
93}
94
95"&&" {
96 return AND;
97}
98
99"||" {
100 return OR;
101}
102
103"##" {
104 return PASTE;
105}
106
107{PUNCTUATION} {
Carl Worth0a93cbb2010-05-13 10:29:07 -0700108 return yytext[0];
109}
Carl Worthfcbbb462010-05-13 09:36:23 -0700110
Carl Worth3ff81672010-05-25 13:09:03 -0700111\n {
112 return NEWLINE;
Carl Worth33cc4002010-05-12 12:17:10 -0700113}
Carl Worth3a37b872010-05-10 11:44:09 -0700114
Carl Worth3ff81672010-05-25 13:09:03 -0700115{OTHER} {
116 yylval.str = xtalloc_strdup (yyextra, yytext);
117 return OTHER;
Carl Worth012295f2010-05-12 13:19:23 -0700118}
119
Carl Worthe36a4d52010-05-14 17:29:24 -0700120{HSPACE}+
Carl Worth012295f2010-05-12 13:19:23 -0700121
Carl Worth3a37b872010-05-10 11:44:09 -0700122%%