aboutsummaryrefslogtreecommitdiffstats
path: root/c_parser/src/c_lexer.flex
blob: 670ec2b3d0c16c376ef4278efcd8e0b9812f1854 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
%option noyywrap

%{
// Avoid error "error: fileno was not declared in this scope"
extern "C" int fileno(FILE *stream);

#include "c_parser.tab.hpp"

%}

%%
[*]             { return T_TIMES; }
[+]             { return T_PLUS; }
[/]             { return T_DIVIDE; }
[-]             { return T_MINUS; }

[(]             { return T_LBRACKET; }
[)]             { return T_RBRACKET; }

log             { return T_LOG;   }
exp             { return T_EXP; }
sqrt            { return T_SQRT; }

[-]?[0-9]+([.][0-9]*)? { yylval.number=strtod(yytext, 0); return T_NUMBER; }
[a-z]+          { yylval.string=new std::string(yytext); return T_VARIABLE; }

[ \t\r\n]+		{;}

.               { fprintf(stderr, "Invalid token\n"); exit(1); }
%%

void yyerror (char const *s)
{
  fprintf (stderr, "Parse error : %s\n", s);
  exit(1);
}