1 /******************************************************************************
6 * Copyright (C) 1997-2015 by Dimitri van Heesch.
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.
14 * Documents produced by Doxygen are derivative works derived from the
15 * input used in their production; they are not affected by this license.
18 %option never-interactive
19 %option prefix="constexpYY"
21 %option reentrant bison-bridge
22 %option extra-type="struct constexpYY_state *"
25 // forward declare yyscan_t to improve typesafety
26 #include "constexp_p.h"
33 #include "ce_parse.hpp" // generated header file
37 #define YY_NO_UNISTD_H 1
39 #define USE_STATE2STRING 0
42 static const char *stateToString(int state);
45 static yy_size_t yyread(char *buf,yy_size_t max_size,yyscan_t yyscanner);
48 #define YY_INPUT(buf,result,max_size) result=yyread(buf,max_size,yyscanner);
52 CONSTSUFFIX ([uU][lL]?[lL]?)|([lL][lL]?[uU]?)
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;
85 0[0-7]*{CONSTSUFFIX}? { yyextra->strToken=yytext;
88 [1-9][0-9]*{CONSTSUFFIX}? { yyextra->strToken=yytext;
89 return TOK_DECIMALINT;
91 (0x|0X)[0-9a-fA-F]+{CONSTSUFFIX}? { yyextra->strToken=yytext+2;
92 return TOK_HEXADECIMALINT;
94 (0b|0B)[01]+{CONSTSUFFIX}? { yyextra->strToken=yytext+2;
97 (([0-9]+\.[0-9]*)|([0-9]*\.[0-9]+))([eE]([\-\+])?[0-9]+)?([fFlL])? {
98 yyextra->strToken=yytext; return TOK_FLOAT;
100 ([0-9]+[eE])([\-\+])?[0-9]+([fFlL])? {
101 yyextra->strToken=yytext; return TOK_FLOAT;
108 static yy_size_t yyread(char *buf,yy_size_t max_size,yyscan_t yyscanner)
110 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
112 while( c < max_size && yyextra->inputString[yyextra->inputPosition] )
114 *buf = yyextra->inputString[yyextra->inputPosition++] ;
120 struct ConstExpressionParser::Private
123 struct constexpYY_state constexpYY_extra;
127 ConstExpressionParser::ConstExpressionParser()
130 constexpYYlex_init_extra(&p->constexpYY_extra, &p->yyscanner);
133 ConstExpressionParser::~ConstExpressionParser()
135 constexpYYlex_destroy(p->yyscanner);
139 bool ConstExpressionParser::parse(const char *fileName,int lineNr,const std::string &s)
141 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
144 constexpYYset_debug(1,p->yyscanner);
147 yyextra->constExpFileName = fileName;
148 yyextra->constExpLineNr = lineNr;
149 yyextra->inputString = s;
150 yyextra->inputPosition = 0;
151 constexpYYrestart( yyin, p->yyscanner );
153 printlex(yy_flex_debug, true, __FILE__, fileName);
154 //printf("Expression: '%s'\n",qPrint(s));
156 constexpYYparse(p->yyscanner);
158 //printf("Result: %ld\n",(long)g_resultValue);
159 printlex(yy_flex_debug, false, __FILE__, fileName);
160 bool result = (long)yyextra->resultValue!=0;
166 int constexpYYwrap(yyscan_t yyscanner) { return 1; }
170 #include "constexp.l.h"