Doxygen
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 */
16%option never-interactive
17%option prefix="constexpYY"
18%option nounput
19%option reentrant bison-bridge
20%option extra-type="struct constexpYY_state *"
21%top{
22#include <stdint.h>
23// forward declare yyscan_t to improve typesafety
24#include "constexp_p.h"
Private interface between Parser (constexp.y) and Lexer (constexp.l).
25}
26
27%{
28
29#include "constexp.h"
30#include "cppvalue.h"
31#include "ce_parse.hpp" // generated header file
32#include "message.h"
33#include "debug.h"
34
35#define YY_NO_INPUT 1
36#define YY_NO_UNISTD_H 1
38[[maybe_unused]] static const char *stateToString(int state);
39
40static int yyread(char *buf,int max_size,yyscan_t yyscanner);
41
42#undef YY_INPUT
43#define YY_INPUT(buf,result,max_size) result=yyread(buf,max_size,yyscanner);
44
45// otherwise the filename would be the name of the converted file (*.cpp instead of *.l)
46static inline const char *getLexerFILE() {return __FILE__;}
47#define LEX_NO_INPUT_FILENAME
48#include "doxygen_lex.h"
yyguts_t * yyscan_t
Definition code.l:24
static int yyread(char *buf, int max_size, yyscan_t yyscanner)
Definition constexp.l:110
static const char * stateToString(int state)
static const char * getLexerFILE()
Definition constexp.l:48
50%}
51
52CONSTSUFFIX ([uU][lL]?[lL]?)|([lL][lL]?[uU]?)
53
54
55%%
56
57"?" { return TOK_QUESTIONMARK; }
58":" { return TOK_COLON; }
59"||" { return TOK_OR; }
60"&&" { return TOK_AND; }
61"|" { return TOK_BITWISEOR; }
62"^" { return TOK_BITWISEXOR; }
63"&" { return TOK_AMPERSAND; }
64"!=" { return TOK_NOTEQUAL; }
65"==" { return TOK_EQUAL; }
66"<" { return TOK_LESSTHAN; }
67">" { return TOK_GREATERTHAN; }
68"<=" { return TOK_LESSTHANOREQUALTO; }
69">=" { return TOK_GREATERTHANOREQUALTO; }
70"<<" { return TOK_SHIFTLEFT; }
71">>" { return TOK_SHIFTRIGHT; }
72"+" { return TOK_PLUS; }
73"-" { return TOK_MINUS; }
74"*" { return TOK_STAR; }
75"/" { return TOK_DIVIDE; }
76"%" { return TOK_MOD; }
77"~" { return TOK_TILDE; }
78"!" { return TOK_NOT; }
79"(" { return TOK_LPAREN; }
80")" { return TOK_RPAREN; }
81"'"(([^\'\n\r\\‍]+)|(\\‍(([ntvbrfa\\?'\"])|([0-9]+)|([xX][0-9a-fA-F]+))))"'" {
82 yyextra->strToken=yytext;
83 return TOK_CHARACTER;
84 }
850[0-7]*{CONSTSUFFIX}? { yyextra->strToken=yytext;
86 return TOK_OCTALINT;
87 }
88[1-9][0-9]*{CONSTSUFFIX}? { yyextra->strToken=yytext;
89 return TOK_DECIMALINT;
90 }
91(0x|0X)[0-9a-fA-F]+{CONSTSUFFIX}? { yyextra->strToken=yytext+2;
92 return TOK_HEXADECIMALINT;
93 }
94(0b|0B)[01]+{CONSTSUFFIX}? { yyextra->strToken=yytext+2;
95 return TOK_BINARYINT;
96 }
97(([0-9]+\.[0-9]*)|([0-9]*\.[0-9]+))([eE]([\-\+])?[0-9]+)?([fFlL])? {
98 yyextra->strToken=yytext; return TOK_FLOAT;
99 }
100([0-9]+[eE])([\-\+])?[0-9]+([fFlL])? {
101 yyextra->strToken=yytext; return TOK_FLOAT;
102 }
103.
104\n
105
106%%
107
108static int yyread(char *buf,int max_size,yyscan_t yyscanner)
109{
110 struct yyguts_t *yyg = static_cast<struct yyguts_t*>(yyscanner);
111 int c=0;
112 while( c < max_size && yyextra->inputString[yyextra->inputPosition] )
113 {
114 *buf = yyextra->inputString[yyextra->inputPosition++] ;
115 c++; buf++;
116 }
117 return c;
118}
119
121{
128{
129 constexpYYlex_init_extra(&p->constexpYY_extra, &p->yyscanner);
130}
131
133{
134 constexpYYlex_destroy(p->yyscanner);
135}
136
137bool ConstExpressionParser::parse(const char *fileName,int lineNr,const std::string &s, const std::string &orgStr)
138{
139 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
140
141#ifdef FLEX_DEBUG
142 constexpYYset_debug(Debug::isFlagSet(Debug::Lex_constexp)?1:0,p->yyscanner);
143#endif
144
145 yyextra->constExpFileName = fileName;
146 yyextra->constExpLineNr = lineNr;
147 yyextra->orgString = orgStr;
148 yyextra->inputString = s;
149 yyextra->inputPosition = 0;
150 constexpYYrestart( yyin, p->yyscanner );
151
152 DebugLex debugLex(Debug::Lex_constexp, __FILE__, fileName);
153 //printf("Expression: '%s'\n",qPrint(s));
154
155 constexpYYparse(p->yyscanner);
156
157 //printf("Result: %ld\n",(long)g_resultValue);
158 bool result = static_cast<long>(yyextra->resultValue)!=0;
159
160 return result;
161}
162
163extern "C" {
164 int constexpYYwrap(yyscan_t /* yyscanner */) { return 1; }
165}
167#include "constexp.l.h"
std::unique_ptr< Private > p
Definition constexp.h:34
bool parse(const char *fileName, int line, const std::string &expression, const std::string &orgExpression)
Definition constexp.l:139
@ Lex_constexp
Definition debug.h:56
static bool isFlagSet(const DebugMask mask)
Definition debug.cpp:132
static int yyread(yyscan_t yyscanner, char *buf, int max_size)
Definition code.l:3971
int constexpYYwrap(yyscan_t)
Definition constexp.l:166
int constexpYYparse(yyscan_t)
struct constexpYY_state constexpYY_extra
Definition constexp.l:125