2 * This is the lexical analyzer of openstranded's script parser
4 * Copyright (C) 2008-2009 Hermann Walth
6 * This file is part of OpenStranded
8 * OpenStranded is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
13 * OpenStranded is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with OpenStranded. If not, see <http://www.gnu.org/licenses/>.
25 #define STRBUF_INITSIZE 16
28 IDENTIFIER [a-zA-Z_][a-zA-Z0-9_]*
37 int strcount, strsize;
41 yylval.val.string = (char*) malloc (strlen (yytext));
42 strcpy (yylval.val.string, yytext + 1);
49 strsize = STRBUF_INITSIZE;
50 strbuf = (char*) malloc (strsize);
55 yylval.type = S2S_STRING_T;
56 yylval.val.string = realloc (strbuf, strcount + 1);
57 yylval.val.string[strcount] = '\0';
62 strbuf[strcount++] = yytext[0];
63 if (strcount >= strsize)
64 strbuf = realloc (strbuf, strsize += STRBUF_INITSIZE);
75 <LINECOMMENT>(\n|\|) {
83 <LINECOMMENT,BLOCKCOMMENT>(.|\n) {}
85 (\&\&)|(and) return AND;
86 (\|\|)|(or) return OR;
93 yylval.val.string = (char*) malloc (strlen (yytext) + 1);
94 strcpy (yylval.val.string, yytext);
98 {INTEGERNUM}?\.{INTEGERNUM} {
99 yylval.type = S2S_FLOAT_T;
100 yylval.val.fnum = atof (yytext);
105 yylval.type = S2S_INT_T;
106 yylval.val.num = atol (yytext);
112 (\!=|\<\>) return NEQ;