/*
 * scanner.fl
 *
 * MathMap
 *
 * Copyright (C) 1997-2007 Mark Probst
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

%{
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <glib.h>

#include "mathmap.h"
#include "exprtree.h"
#include "builtins.h"
#include "parser.h"
#include "jump.h"
%}

%option noyywrap

%%

filter                      return T_FILTER;
function                    { sprintf(error_string, "`function' is a reserved keyword"); JUMP(1); }
lambda                      { sprintf(error_string, "`lambda' is a reserved keyword"); JUMP(1); }
float			    return T_FLOAT_TYPE;
int			    return T_INT_TYPE;
bool			    return T_BOOL_TYPE;
color			    return T_COLOR_TYPE;
gradient		    return T_GRADIENT_TYPE;
curve			    return T_CURVE_TYPE;
image			    return T_IMAGE_TYPE;
if                          return T_IF;
then                        return T_THEN;
else                        return T_ELSE;
end                         return T_END;
while                       return T_WHILE;
do                          return T_DO;
for                         return T_FOR;
xor                         return T_XOR;
[a-zA-Z_][a-zA-Z0-9_]*      {
				yylval.ident = strdup(yytext);
				return T_IDENT;
	                    }
\"[^\"\n]*\"                {
				yylval.ident = strdup(yytext + 1);
				yylval.ident[yyleng - 2] = '\0';
				return T_STRING;
			    }
[0-9]+                      { yylval.exprtree = make_int_number(atoi(yytext)); return T_INT; }
[0-9]*\.[0-9]+              { yylval.exprtree = make_float_number(g_ascii_strtod(yytext, NULL)); return T_FLOAT; }
"=="                        return T_EQUAL;
"<="                        return T_LESSEQUAL;
">="                        return T_GREATEREQUAL;
"!="                        return T_NOTEQUAL;
"||"                        return T_OR;
"&&"                        return T_AND;
"::"                        return T_CONVERT;
\.\.                        return T_RANGE;
[-<>!,()+*/%=;^:\[\]]       return yytext[0];
#.*                         ;
[ \t\n]                     {
				char *p = yytext;

				while ((p = strchr(p, '\n')) != 0)
				{
				    ++scanner_line_num;
				    ++p;
				}
			    }

%%

void
scanFromString (char *string)
{
    yy_scan_string(string);
}

void
endScanningFromString (void)
{
    yy_delete_buffer(YY_CURRENT_BUFFER);
}
