%{

#include "calc.tab.h"
#include <math.h>
#include <stdio.h>
#define calcwrap() (1)
#define calcerror(s) do {fprintf(stderr,"%s\n",s);} while(0)
#ifndef calclval
#define calclval yylval
YYSTYPE yylval;
#endif

%}

%%
([0-9]+|([0-9]*\.[0-9]+)([eE][-+]?[0-9]+)?) { /* number */
  calclval.dval = atof(calctext); return NUMBER;
}

[ \t]	;		                   /* ignore white space */

[a-zA-Z][a-zA-Z_0-9]*","?[a-zA-Z._0-9]* {  /* variable */
  calclval.string = (char *)strdup( calctext );
  return VAR;
}

@[a-zA-Z]* {                              /* function */
  calclval.string = (char *)strdup( &calctext[1] );
  return FUNCTION;
}

"$"	 { return 0;                      /* end of input */ }

\n	 { return 0;                      /* no more input, bub */ }

[-+/*\^%\(\)] { return calctext[0];        /* operators are returned literally */ }

.        { calcerror("Unrecognized character"); }

%%

