Debian Codegraph @

visa/iga/IGALibrary/Frontend/LexicalSpec.flex

raw
1 /*========================== begin_copyright_notice ============================
2
3 Copyright (C) 2017-2021 Intel Corporation
4
5 SPDX-License-Identifier: MIT
6
7 ============================= end_copyright_notice ===========================*/
8
9 %{
10 /*
11 * Contains the lexical specification for Intel Gen Assembly.
12 *
13 * Build with:
14 * % flex ThisFile.flex
15 * First constructed with flex 2.5.39 (you can use Cygwin if you want).
16 * update 3/2018: flex 2.6.4
17 * *** It should build without warnings. ***
18 * => It's nice to strip end of line whitespace on the generated files.
19 */
20 #if defined(_MSC_VER)
21 #pragma warning(default : 4505)
22 #pragma warning(disable:4701)
23 #else
24 #pragma GCC diagnostic ignored "-Wmissing-declarations"
25 #endif
26
27 #include "Lexemes.hpp"
28
29 #define YY_DECL iga::Lexeme yylex (yyscan_t yyscanner, unsigned int &inp_off)
30
31 /*
32 * It seems many versions of flex don't support column info in re-entrant
33 * scanners. This works around the issue.
34 */
35 #define YY_USER_ACTION \
36 yyset_column(yyget_column(yyscanner) + (int)yyget_leng(yyscanner), yyscanner);
37
38 %}
39
40 %option outfile="lex.yy.cpp" header-file="lex.yy.hpp"
41 %option nounistd
42 %option reentrant
43 %option noyywrap
44 %option yylineno
45 /* omits isatty */
46 %option never-interactive
47
48 %x SLASH_STAR
49 %x STRING_DBL
50 %x STRING_SNG
51
52 DEC_DIGIT [0-9]
53 DEC_DIGITS {DEC_DIGIT}+
54 /* DEC_FRAC ({DEC_DIGITS}\.{DEC_DIGITS}?)|({DEC_DIGITS}?\.{DEC_DIGITS}) */
55 HEX_DIGIT [0-9A-Fa-f]
56 HEX_DIGITS {HEX_DIGIT}+
57 HEX_FRAC ({HEX_DIGITS}\.{HEX_DIGITS}?)|({HEX_DIGITS}?\.{HEX_DIGITS})
58
59 EXP_SUFFIX [-+]?{DEC_DIGITS}
60
61 %%
62
63 <SLASH_STAR>"*/" { inp_off += 2; BEGIN(INITIAL); }
64 <SLASH_STAR>[^*\n]+ { inp_off += (unsigned int)yyget_leng(yyscanner); } // eat comment in line chunks
65 <SLASH_STAR>"*" { inp_off++; } // eat the lone star
66 <SLASH_STAR>\n { inp_off++; }
67
68 <STRING_DBL>\" { inp_off++;
69 BEGIN(INITIAL);
70 return iga::Lexeme::STRLIT; }
71 <STRING_DBL>\\. { inp_off += 2; }
72 <STRING_DBL>. { inp_off++; }
73
74 <STRING_SNG>\' { inp_off++;
75 BEGIN(INITIAL);
76 return iga::Lexeme::CHRLIT; }
77 <STRING_SNG>\\. { inp_off += 2; }
78 <STRING_SNG>. { inp_off++; }
79
80 "/*" {inp_off += 2; BEGIN(SLASH_STAR);}
81 \< return iga::Lexeme::LANGLE;
82 \> return iga::Lexeme::RANGLE;
83 \[ return iga::Lexeme::LBRACK;
84 \] return iga::Lexeme::RBRACK;
85 \{ return iga::Lexeme::LBRACE;
86 \} return iga::Lexeme::RBRACE;
87 \( return iga::Lexeme::LPAREN;
88 \) return iga::Lexeme::RPAREN;
89
90 \$ return iga::Lexeme::DOLLAR;
91 \. return iga::Lexeme::DOT;
92 \, return iga::Lexeme::COMMA;
93 \; return iga::Lexeme::SEMI;
94 \: return iga::Lexeme::COLON;
95
96 \~ return iga::Lexeme::TILDE;
97 \(abs\) return iga::Lexeme::ABS;
98 \(sat\) return iga::Lexeme::SAT;
99
100 \! return iga::Lexeme::BANG;
101 \@ return iga::Lexeme::AT;
102 \# return iga::Lexeme::HASH;
103 \= return iga::Lexeme::EQ;
104
105 \% return iga::Lexeme::MOD;
106 \* return iga::Lexeme::MUL;
107 \/ return iga::Lexeme::DIV;
108 \+ return iga::Lexeme::ADD;
109 \- return iga::Lexeme::SUB;
110 \<< return iga::Lexeme::LSH;
111 \>> return iga::Lexeme::RSH;
112 \& return iga::Lexeme::AMP;
113 \^ return iga::Lexeme::CIRC;
114 \| return iga::Lexeme::PIPE;
115
116 {DEC_DIGITS} return iga::Lexeme::INTLIT10; /* 13 */
117 0[xX]{HEX_DIGITS} return iga::Lexeme::INTLIT16; /* 0x13 */
118 0[bB][01]+ return iga::Lexeme::INTLIT02; /* 0b1101 */
119
120 {DEC_DIGITS}\.{DEC_DIGITS} return iga::Lexeme::FLTLIT; /* 3.14 (cannot have .3 because that screws up (f0.0)) */
121 {DEC_DIGITS}(\.{DEC_DIGITS})?[eE]{EXP_SUFFIX} return iga::Lexeme::FLTLIT; /* 3e-9/3.14e9*/
122 0[xX]({HEX_FRAC}|{HEX_DIGITS})[pP]{EXP_SUFFIX} return iga::Lexeme::FLTLIT; /* 0x1.2p3/0x.2p3/0x1.p3/ */
123 [_a-zA-Z][_a-zA-Z0-9]* return iga::Lexeme::IDENT;
124
125 %{
126 /*
127 * enables identifier such as "128x16"; this pattern requires a non-zero
128 * initial character so that 0x13 will be scanned as a hex int
129 */
130 %}
131 [1-9][0-9]*x[0-9]+ return iga::Lexeme::IDENT;
132
133
134 \n return iga::Lexeme::NEWLINE; /* newlines are explicitly represented */
135 [ \t\r]+ {inp_off += (unsigned int)yyget_leng(yyscanner);} /* whitespace */;
136 "//"[^\n]* {inp_off += (unsigned int)yyget_leng(yyscanner);} /* EOL comment ?*/
137
138 . return iga::Lexeme::LEXICAL_ERROR;
139 <<EOF>> return iga::Lexeme::END_OF_FILE;
140
141 %%