ratio

cli rational number calculator
git clone git://jb55.com/ratio
Log | Files | Refs | README | LICENSE

lexer.l (487B)


      1 %option noyywrap
      2 
      3 %{
      4 #include <stdio.h>
      5 #include <gmp.h>
      6 
      7 #define YY_DECL int yylex()
      8 
      9 #include "parser.tab.h"
     10 
     11 %}
     12 
     13 %%
     14 
     15 [ \t]	; // ignore all whitespace
     16 [0-9]+		{
     17   mpz_t i; mpz_init(i);
     18   mpq_init(yylval.rval);
     19   mpz_set_str(i, yytext, 10);
     20   mpq_set_z(yylval.rval, i);
     21   return T_RATIO;
     22 }
     23 \n		    {return T_NEWLINE;}
     24 "+"		    {return T_PLUS;}
     25 "-"		    {return T_MINUS;}
     26 "*"		    {return T_MULTIPLY;}
     27 "/"		    {return T_DIVIDE;}
     28 "("		    {return T_LEFT;}
     29 ")"		    {return T_RIGHT;}
     30 
     31 %%