Warning, /games/kmuddy/libs/flex-input.lex is written in an unsupported language. File is not indexed.
0001 %option noyywrap
0002 %option nounput
0003 %{
0004 /*
0005 Copyright 2005-2011 Tomas Mecir <kmuddy@kmuddy.com>
0006 Copyright 2005 Alex Bache <alexbache@ntlworld.com>
0007
0008 This program is free software; you can redistribute it and/or
0009 modify it under the terms of the GNU General Public License as
0010 published by the Free Software Foundation; either version 2 of
0011 the License, or (at your option) any later version.
0012
0013 This program is distributed in the hope that it will be useful,
0014 but WITHOUT ANY WARRANTY; without even the implied warranty of
0015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0016 GNU General Public License for more details.
0017
0018 You should have received a copy of the GNU General Public License
0019 along with this program. If not, see <http://www.gnu.org/licenses/>.
0020 */
0021 #include "cvalue.h"
0022 #include "bison-input.tab.hpp"
0023
0024 void yyerror(char *);
0025
0026 using namespace std;
0027
0028 // Use global variables from Bison module
0029 extern const char *source;
0030 extern bool new_source;
0031 extern bool token_error;
0032 %}
0033
0034 DIGIT [0-9]
0035 LETTER [A-Za-z_]
0036 SPACE [ ]
0037
0038 %%
0039
0040 if (new_source)
0041 {
0042 // cout << "Switching to new buffer\n";
0043 // cout.flush();
0044
0045 yy_delete_buffer(YY_CURRENT_BUFFER);
0046 yy_switch_to_buffer(yy_scan_string(source));
0047 new_source = false;
0048 }
0049
0050
0051 {DIGIT}+ {
0052 // Integer
0053 yylval.int_val = atoi(yytext);
0054 return INTEGER;
0055 }
0056
0057 {DIGIT}+"."{DIGIT}+ {
0058 // Double
0059 yylval.double_val = QString(yytext).toDouble();
0060 return DOUBLE_V;
0061 }
0062
0063 ${LETTER}({LETTER}|{DIGIT})* {
0064 // variable name
0065 yylval.string_val = strdup(yytext+1);
0066 return STRING_V;
0067 }
0068 ${DIGIT}+ {
0069 // variable name looking like $number
0070 yylval.string_val = strdup(yytext+1);
0071 return STRING_V;
0072 }
0073
0074 {LETTER}({LETTER}|{DIGIT})*{SPACE}*\( {
0075 // Function name
0076 // strip the parenthesis
0077 yytext[yyleng-1] = '\0';
0078 int len = yyleng-2;
0079 // strip the spaces too
0080 for (; len >= 0; --len)
0081 if (yytext[len] == ' ')
0082 yytext[len] = '\0';
0083 else
0084 break;
0085 yylval.string_val = strdup(yytext);
0086 return FUNCTION_NAME;
0087 }
0088
0089 \"[^"]*\" {
0090 // String literal
0091 yytext[yyleng-1] = '\0';
0092
0093 yylval.string_val = strdup(yytext+1);
0094 return STRING_LITERAL;
0095 }
0096
0097 "(int)" { return INT_TYPECAST; }
0098 "(double)" { return DOUBLE_TYPECAST; }
0099 "(string)" { return STRING_TYPECAST; }
0100
0101 "&&" { return AND; }
0102 "||" { return OR; }
0103 ">" { return GT; }
0104 ">=" { return GE; }
0105 "<" { return LT; }
0106 "<=" { return LE; }
0107 "==" { return EQ; }
0108 "!=" { return NE; }
0109
0110 [-+*/()\.,!] { return *yytext; }
0111
0112 [ \t\n] ;
0113
0114 . { token_error = true; yyterminate(); }
0115
0116 %%