|
1 /****************************************************************************** |
|
2 * |
|
3 * |
|
4 * |
|
5 * |
|
6 * Copyright (C) 1997-2008 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 |
|
19 %{ |
|
20 |
|
21 #include "constexp.h" |
|
22 #include "cppvalue.h" |
|
23 #include "ce_parse.h" // generated header file |
|
24 |
|
25 #define YY_NEVER_INTERACTIVE 1 |
|
26 |
|
27 QCString g_strToken; |
|
28 CPPValue g_resultValue; |
|
29 int g_constExpLineNr; |
|
30 QCString g_constExpFileName; |
|
31 |
|
32 static const char *g_inputString; |
|
33 static int g_inputPosition; |
|
34 |
|
35 #undef YY_INPUT |
|
36 #define YY_INPUT(buf,result,max_size) result=yyread(buf,max_size); |
|
37 |
|
38 static int yyread(char *buf,int max_size) |
|
39 { |
|
40 int c=0; |
|
41 while( c < max_size && g_inputString[g_inputPosition] ) |
|
42 { |
|
43 *buf = g_inputString[g_inputPosition++] ; |
|
44 c++; buf++; |
|
45 } |
|
46 return c; |
|
47 } |
|
48 |
|
49 %} |
|
50 |
|
51 CONSTSUFFIX ([uU][lL]?[lL]?)|([lL][lL]?[uU]?) |
|
52 |
|
53 %option nounput |
|
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 g_strToken=yytext; |
|
83 return TOK_CHARACTER; |
|
84 } |
|
85 0[0-7]*{CONSTSUFFIX}? { g_strToken=yytext; |
|
86 return TOK_OCTALINT; |
|
87 } |
|
88 [1-9][0-9]*{CONSTSUFFIX}? { g_strToken=yytext; |
|
89 return TOK_DECIMALINT; |
|
90 } |
|
91 (0x|0X)[0-9a-fA-F]+{CONSTSUFFIX}? { g_strToken=yytext+2; |
|
92 return TOK_HEXADECIMALINT; |
|
93 } |
|
94 (([0-9]+\.[0-9]*)|([0-9]*\.[0-9]+))([eE]([\-\+])?[0-9]+)?([fFlL])? { |
|
95 g_strToken=yytext; return TOK_FLOAT; |
|
96 } |
|
97 ([0-9]+[eE])([\-\+])?[0-9]+([fFlL])? { |
|
98 g_strToken=yytext; return TOK_FLOAT; |
|
99 } |
|
100 . |
|
101 \n |
|
102 |
|
103 %% |
|
104 |
|
105 bool parseCppExpression(const char *fileName,int lineNr,const QCString &s) |
|
106 { |
|
107 //printf("Expression: `%s'\n",s.data()); |
|
108 g_constExpFileName = fileName; |
|
109 g_constExpLineNr = lineNr; |
|
110 g_inputString = s; |
|
111 g_inputPosition = 0; |
|
112 cppExpYYrestart( cppExpYYin ); |
|
113 cppExpYYparse(); |
|
114 //printf("Result: %ld\n",(long)g_resultValue); |
|
115 return (long)g_resultValue!=0; |
|
116 } |
|
117 |
|
118 extern "C" { |
|
119 int cppExpYYwrap() { return 1; } |
|
120 } |