constexp.l 3.71 KB
Newer Older
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1 2
/******************************************************************************
 *
3
 * 
Dimitri van Heesch's avatar
Dimitri van Heesch committed
4 5
 *
 *
Dimitri van Heesch's avatar
Dimitri van Heesch committed
6
 * Copyright (C) 1997-2014 by Dimitri van Heesch.
Dimitri van Heesch's avatar
Dimitri van Heesch committed
7 8 9 10 11 12 13
 *
 * Permission to use, copy, modify, and distribute this software and its
 * documentation under the terms of the GNU General Public License is hereby 
 * granted. No representations are made about the suitability of this software 
 * for any purpose. It is provided "as is" without express or implied warranty.
 * See the GNU General Public License for more details.
 *
Dimitri van Heesch's avatar
Dimitri van Heesch committed
14 15
 * Documents produced by Doxygen are derivative works derived from the
 * input used in their production; they are not affected by this license.
Dimitri van Heesch's avatar
Dimitri van Heesch committed
16 17 18 19 20 21 22 23
 *
 */

%{

#include "constexp.h"  
#include "cppvalue.h"
#include "ce_parse.h" // generated header file
24
#include "message.h"
Dimitri van Heesch's avatar
Dimitri van Heesch committed
25 26

#define YY_NEVER_INTERACTIVE 1
27
#define YY_NO_INPUT 1
Dimitri van Heesch's avatar
Dimitri van Heesch committed
28
  
29 30 31 32
QCString    g_strToken;  
CPPValue    g_resultValue;
int         g_constExpLineNr;
QCString    g_constExpFileName;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
33

34 35
static const char *g_inputString;
static int         g_inputPosition;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
36 37 38 39 40 41 42

#undef  YY_INPUT
#define YY_INPUT(buf,result,max_size) result=yyread(buf,max_size);

static int yyread(char *buf,int max_size)
{
  int c=0;
43
  while( c < max_size && g_inputString[g_inputPosition] )
Dimitri van Heesch's avatar
Dimitri van Heesch committed
44
  {
45
    *buf = g_inputString[g_inputPosition++] ;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
46 47 48 49 50 51 52
    c++; buf++;
  }
  return c;
}

%}

53
CONSTSUFFIX ([uU][lL]?[lL]?)|([lL][lL]?[uU]?)
Dimitri van Heesch's avatar
Dimitri van Heesch committed
54

55 56
%option nounput

Dimitri van Heesch's avatar
Dimitri van Heesch committed
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
%%

"?"				   { return TOK_QUESTIONMARK; }
":"				   { return TOK_COLON; }
"||"				   { return TOK_OR; }
"&&"				   { return TOK_AND; }
"|"				   { return TOK_BITWISEOR; }
"^"				   { return TOK_BITWISEXOR; }
"&"				   { return TOK_AMPERSAND; }
"!="            		   { return TOK_NOTEQUAL; }
"=="            		   { return TOK_EQUAL; }
"<"             		   { return TOK_LESSTHAN; }
">"             		   { return TOK_GREATERTHAN; }
"<="            		   { return TOK_LESSTHANOREQUALTO; }
">="            		   { return TOK_GREATERTHANOREQUALTO; }
"<<"            		   { return TOK_SHIFTLEFT; }
">>"            		   { return TOK_SHIFTRIGHT; }
"+"             		   { return TOK_PLUS; }
"-"             		   { return TOK_MINUS; }
"*"             		   { return TOK_STAR; }
"/"             		   { return TOK_DIVIDE; }
"%"             		   { return TOK_MOD; }
"~"             		   { return TOK_TILDE; }
"!"             		   { return TOK_NOT; }
"("             		   { return TOK_LPAREN; }
")"             		   { return TOK_RPAREN; }
"'"(([^\'\n\r\\]+)|(\\(([ntvbrfa\\?'\"])|([0-9]+)|([xX][0-9a-fA-F]+))))"'"   { 
84
                                     g_strToken=yytext;  
Dimitri van Heesch's avatar
Dimitri van Heesch committed
85 86
				     return TOK_CHARACTER; 
				   }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
87
0[0-7]*{CONSTSUFFIX}?              { g_strToken=yytext; 
Dimitri van Heesch's avatar
Dimitri van Heesch committed
88 89
  				     return TOK_OCTALINT; 
				   }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
90
[1-9][0-9]*{CONSTSUFFIX}?          { g_strToken=yytext; 
Dimitri van Heesch's avatar
Dimitri van Heesch committed
91 92
  				     return TOK_DECIMALINT; 
				   }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
93
(0x|0X)[0-9a-fA-F]+{CONSTSUFFIX}?  { g_strToken=yytext+2; 
94 95
                                     return TOK_HEXADECIMALINT; 
                                   }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
96
(([0-9]+\.[0-9]*)|([0-9]*\.[0-9]+))([eE]([\-\+])?[0-9]+)?([fFlL])? { 
97
                                     g_strToken=yytext; return TOK_FLOAT; 
Dimitri van Heesch's avatar
Dimitri van Heesch committed
98 99
                                   }
([0-9]+[eE])([\-\+])?[0-9]+([fFlL])? { 
100
                                     g_strToken=yytext; return TOK_FLOAT; 
Dimitri van Heesch's avatar
Dimitri van Heesch committed
101 102 103 104 105 106
			           }
.				   
\n

%%

107
bool parseconstexp(const char *fileName,int lineNr,const QCString &s)
Dimitri van Heesch's avatar
Dimitri van Heesch committed
108
{
109
  printlex(yy_flex_debug, TRUE, __FILE__, fileName);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
110
  //printf("Expression: `%s'\n",s.data());
111 112 113 114
  g_constExpFileName = fileName;
  g_constExpLineNr = lineNr;
  g_inputString = s;
  g_inputPosition = 0;
115 116
  constexpYYrestart( constexpYYin );
  constexpYYparse();
117
  //printf("Result: %ld\n",(long)g_resultValue);
118
  printlex(yy_flex_debug, FALSE, __FILE__, fileName);
119
  return (long)g_resultValue!=0;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
120 121 122
}

extern "C" {
123
  int constexpYYwrap() { return 1; }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
124
}