Skip to content

Commit 4f8ac7e

Browse files
author
root
committed
Lex program for a simple calculator
1 parent 9d08f1d commit 4f8ac7e

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

scal.l

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
%{
2+
/*Lex program for a simple calculator */
3+
4+
#include "y.tab.h"
5+
#include<stdlib.h>
6+
#include<stdio.h>
7+
8+
int yylineno;
9+
10+
%}
11+
12+
13+
number [0-9]+
14+
op [-|+|*|/]
15+
16+
%%
17+
18+
" " ;
19+
[\n] return END;
20+
{op} return *yytext;
21+
\% return *yytext;
22+
\^ return *yytext;
23+
{number} {
24+
yylval.val=atoi(yytext);
25+
return NUMBER;
26+
}
27+
[\(\)] return *yytext;
28+
. yyerror("ERROR");
29+
%%

0 commit comments

Comments
 (0)