-
Notifications
You must be signed in to change notification settings - Fork 1
/
lexical.l
59 lines (40 loc) · 1.42 KB
/
lexical.l
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
%{
/* defination */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <ctype.h>
#include "parser.tab.h"
/* prints grammar violation message */
extern void yyerror(const char *);
%}
delim [ \t\r\v\f\n]
ws {delim}+
letter [A-Za-z]
digit [0-9]
id {letter}({letter}|{digit})*
number {digit}+(\.{digit}+)?([eE][+\-]?{digit}+)?
/* pattern actions/Rules */
%%
{ws} { ; }
"**" {strcpy(yylval.arithP, yytext); return ARITHP;}
"//" {strcpy(yylval.arithD, yytext); return ARITHD;}
{number} {strcpy(yylval.num , yytext); return NUM;}
[-+/*=,;(){}%] {return yytext[0];}
"==" |
"!=" |
">" |
">=" |
"<" |
"<=" {strcpy(yylval.relo, yytext); return RELOP;}
"if" {return IF;}
"else" {return ELSE;}
"while" {return WHILE;}
"for" {return FOR;}
"in" {return IN;}
"range" {return RANGE;}
{id} {strcpy(yylval.id , yytext); return ID;}
. {printf("Error occured ...\n");}
%%
/* User Code Segment */