Doxygen
Toggle main menu visibility
Loading...
Searching...
No Matches
constexp.l
Go to the documentation of this file.
1
/******************************************************************************
2
*
3
*
4
*
5
*
6
* Copyright (C) 1997-2015 by Dimitri van Heesch.
7
*
8
* Permission to use, copy, modify, and distribute this software and its
9
* documentation under the terms of the GNU General Public License is hereby
10
* granted. No representations are made about the suitability of this software
11
* for any purpose. It is provided "as is" without express or implied warranty.
12
* See the GNU General Public License for more details.
13
*
14
* Documents produced by Doxygen are derivative works derived from the
15
* input used in their production; they are not affected by this license.
16
*
17
*/
18
%option never-interactive
19
%option prefix="constexpYY"
20
%option nounput
21
%option reentrant bison-bridge
22
%option extra-type="struct constexpYY_state *"
23
%top{
24
#include <stdint.h>
25
// forward declare yyscan_t to improve typesafety
26
#include "
constexp_p.h
"
constexp_p.h
Private interface between Parser (constexp.y) and Lexer (constexp.l).
27
}
28
29
%{
30
31
#include "
constexp.h
"
32
#include "
cppvalue.h
"
33
#include "ce_parse.hpp"
// generated header file
34
#include "
message.h
"
35
#include "
debug.h
"
36
37
#define YY_NO_INPUT 1
38
#define YY_NO_UNISTD_H 1
39
40
[[maybe_unused]]
static
const
char
*
stateToString
(
int
state);
41
42
static
int
yyread
(
char
*buf,
int
max_size,
yyscan_t
yyscanner);
43
44
#undef YY_INPUT
45
#define YY_INPUT(buf,result,max_size) result=yyread(buf,max_size,yyscanner);
46
47
// otherwise the filename would be the name of the converted file (*.cpp instead of *.l)
48
static
inline
const
char
*
getLexerFILE
() {
return
__FILE__;}
49
#define LEX_NO_INPUT_FILENAME
50
#include "
doxygen_lex.h
"
51
yyscan_t
yyguts_t * yyscan_t
Definition
code.l:24
constexp.h
yyread
static int yyread(char *buf, int max_size, yyscan_t yyscanner)
Definition
constexp.l:110
stateToString
static const char * stateToString(int state)
getLexerFILE
static const char * getLexerFILE()
Definition
constexp.l:48
cppvalue.h
debug.h
doxygen_lex.h
message.h
52
%}
53
54
CONSTSUFFIX ([uU][lL]?[lL]?)|([lL][lL]?[uU]?)
55
56
57
%%
58
59
"?"
{
return
TOK_QUESTIONMARK; }
60
":"
{
return
TOK_COLON; }
61
"||"
{
return
TOK_OR; }
62
"&&"
{
return
TOK_AND; }
63
"|"
{
return
TOK_BITWISEOR; }
64
"^"
{
return
TOK_BITWISEXOR; }
65
"&"
{
return
TOK_AMPERSAND; }
66
"!="
{
return
TOK_NOTEQUAL; }
67
"=="
{
return
TOK_EQUAL; }
68
"<"
{
return
TOK_LESSTHAN; }
69
">"
{
return
TOK_GREATERTHAN; }
70
"<="
{
return
TOK_LESSTHANOREQUALTO; }
71
">="
{
return
TOK_GREATERTHANOREQUALTO; }
72
"<<"
{
return
TOK_SHIFTLEFT; }
73
">>"
{
return
TOK_SHIFTRIGHT; }
74
"+"
{
return
TOK_PLUS; }
75
"-"
{
return
TOK_MINUS; }
76
"*"
{
return
TOK_STAR; }
77
"/"
{
return
TOK_DIVIDE; }
78
"%"
{
return
TOK_MOD; }
79
"~"
{
return
TOK_TILDE; }
80
"!"
{
return
TOK_NOT; }
81
"("
{
return
TOK_LPAREN; }
82
")"
{
return
TOK_RPAREN; }
83
"'"(([^\'\n\r\\]+)|(\\(([ntvbrfa\\?'\"])|([0-9]+)|([xX][0-9a-fA-F]+))))"'"
{
84
yyextra->strToken=yytext;
85
return
TOK_CHARACTER;
86
}
87
0[0-7]*{CONSTSUFFIX}?
{ yyextra->strToken=yytext;
88
return
TOK_OCTALINT;
89
}
90
[1-9][0-9]*{CONSTSUFFIX}?
{ yyextra->strToken=yytext;
91
return
TOK_DECIMALINT;
92
}
93
(0x|0X)[0-9a-fA-F]+{CONSTSUFFIX}?
{ yyextra->strToken=yytext+2;
94
return
TOK_HEXADECIMALINT;
95
}
96
(0b|0B)[01]+{CONSTSUFFIX}?
{ yyextra->strToken=yytext+2;
97
return
TOK_BINARYINT;
98
}
99
(([0-9]+\.[0-9]*)|([0-9]*\.[0-9]+))([eE]([\-\+])?[0-9]+)?([fFlL])?
{
100
yyextra->strToken=yytext;
return
TOK_FLOAT;
101
}
102
([0-9]+[eE])([\-\+])?[0-9]+([fFlL])?
{
103
yyextra->strToken=yytext;
return
TOK_FLOAT;
104
}
105
.
106
\n
107
108
%%
109
110
static
int
yyread
(
char
*buf,
int
max_size,
yyscan_t
yyscanner)
111
{
112
struct
yyguts_t *yyg =
static_cast<
struct yyguts_t*
>
(yyscanner);
113
int
c=0;
114
while
( c < max_size && yyextra->inputString[yyextra->inputPosition] )
115
{
116
*buf = yyextra->inputString[yyextra->inputPosition++] ;
117
c++; buf++;
118
}
119
return
c;
120
}
121
122
struct
ConstExpressionParser::Private
123
{
124
yyscan_t
yyscanner
;
125
struct
constexpYY_state
constexpYY_extra
;
126
};
127
128
129
ConstExpressionParser::ConstExpressionParser
() :
p
(std::make_unique<
Private
>())
130
{
131
constexpYYlex_init_extra(&
p
->constexpYY_extra, &
p
->yyscanner);
132
}
133
134
ConstExpressionParser::~ConstExpressionParser
()
135
{
136
constexpYYlex_destroy(
p
->yyscanner);
137
}
138
139
bool
ConstExpressionParser::parse
(
const
char
*fileName,
int
lineNr,
const
std::string &s,
const
std::string &orgStr)
140
{
141
struct
yyguts_t *yyg = (
struct
yyguts_t*)
p
->yyscanner;
142
143
#ifdef FLEX_DEBUG
144
constexpYYset_debug(
Debug::isFlagSet
(
Debug::Lex_constexp
)?1:0,
p
->yyscanner);
145
#endif
146
147
yyextra->constExpFileName = fileName;
148
yyextra->constExpLineNr = lineNr;
149
yyextra->orgString = orgStr;
150
yyextra->inputString = s;
151
yyextra->inputPosition = 0;
152
constexpYYrestart( yyin,
p
->yyscanner );
153
154
DebugLex
debugLex(
Debug::Lex_constexp
, __FILE__, fileName);
155
//printf("Expression: '%s'\n",qPrint(s));
156
157
constexpYYparse
(
p
->yyscanner);
158
159
//printf("Result: %ld\n",(long)g_resultValue);
160
bool
result =
static_cast<
long
>
(yyextra->resultValue)!=0;
161
162
return
result;
163
}
164
165
extern
"C"
{
166
int
constexpYYwrap
(
yyscan_t
/* yyscanner */
) {
return
1; }
167
}
168
169
#include "constexp.l.h"
ConstExpressionParser::ConstExpressionParser
ConstExpressionParser()
Definition
constexp.l:129
ConstExpressionParser::p
std::unique_ptr< Private > p
Definition
constexp.h:34
ConstExpressionParser::~ConstExpressionParser
~ConstExpressionParser()
Definition
constexp.l:134
ConstExpressionParser::parse
bool parse(const char *fileName, int line, const std::string &expression, const std::string &orgExpression)
Definition
constexp.l:139
Debug::Lex_constexp
@ Lex_constexp
Definition
debug.h:57
Debug::isFlagSet
static bool isFlagSet(const DebugMask mask)
Definition
debug.cpp:133
DebugLex
Definition
debug.h:98
yyread
static int yyread(yyscan_t yyscanner, char *buf, int max_size)
Definition
code.l:3982
constexpYYwrap
int constexpYYwrap(yyscan_t)
Definition
constexp.l:166
constexpYYparse
int constexpYYparse(yyscan_t)
ConstExpressionParser::Private
Definition
constexp.l:123
ConstExpressionParser::Private::yyscanner
yyscan_t yyscanner
Definition
constexp.l:124
ConstExpressionParser::Private::constexpYY_extra
struct constexpYY_state constexpYY_extra
Definition
constexp.l:125
constexpYY_state
Definition
constexp_p.h:34
src
constexp.l
Generated by
1.17.0