%{
#include <string.h>

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

%option noyywrap

%%

if                          return T_IF;
then                        return T_THEN;
else                        return T_ELSE;
end                         return T_END;
while                       return T_WHILE;
do                          return T_DO;
[a-zA-Z_][a-zA-Z0-9_]*      {
				builtin *theBuiltin = builtin_with_name(yytext);

				if (theBuiltin != 0)
				{
				   yylval.builtin = theBuiltin;
				   return T_BUILTIN;
				}
				else
				{
				    strncpy(yylval.ident, yytext, MAX_IDENT_LENGTH);
				    yylval.ident[MAX_IDENT_LENGTH] = 0;
				    return T_IDENT;
				}
	                    }
[0-9]+                      { yylval.exprtree = make_number(atof(yytext)); return T_NUMBER; }
[0-9]*\.[0-9]+              { yylval.exprtree = make_number(atof(yytext)); return T_NUMBER; }
"=="                        return T_EQUAL;
"<="                        return T_LESSEQUAL;
">="                        return T_GREATEREQUAL;
"!="                        return T_NOTEQUAL;
"||"                        return T_OR;
"&&"                        return T_AND;
[-<>!,()+*/%=;]             return yytext[0];
#.*                         ;
[ \t\n]                     ;

%%

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

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