Website Summary Files Commits Branches @commit @diff @stats
path: root / demo / bison / calc / lexer.lex
blob: 164c04b03e6d836eaa615b20ddae471f1fac37c5 (plain) (blame)
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
/* Expression calculator */

%{
#include "parser.tab.h"
#include <stdlib.h>
int current_line = 0;
#define YY_NO_UNISTD_H
%}

digit   [0-9]
number  [1-9]{digit}*
fnumber {digit}+"."{digit}*

%%

{number}|{fnumber}      { yylval = atof(yytext); return NUMBER; }
"+"     { return PLUS; }
"-"     { return MINUS; }
"*"     { return MULT; }
"/"     { return DIV; }
"("     { return '('; }
")"     { return ')'; }
[ \t]   {       }
\n      { ++current_line; }

%%

int yywrap()
{
    return 1;
}