-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcomment.l
More file actions
39 lines (29 loc) · 749 Bytes
/
comment.l
File metadata and controls
39 lines (29 loc) · 749 Bytes
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
%{
/*Executing comments using states*/
/*Rules without conditonal state specification will be executed in any state (this is correct) */
/*Simple scanner which scans for identifiers, constants and mathematical operators*/
#include<stdlib.h>
#include<stdio.h>
%}
number [0-9]+
id [a-zA-Z][a-zA-Z0-9]*
op [-|+|*|/|^|=]
%option noyywrap
%s COMMENT
%s PROGRAM
%%
"/*" {printf(" Comment initiated ");BEGIN COMMENT;}
<COMMENT>"*/" {printf("Comment closed "); BEGIN PROGRAM;}
<COMMENT>(.)* {printf("Inside comment");}
"BEGIN" printf(" Section-begin ");
"END" return 1;
{op} printf(" Math-operator ");
{number} printf(" Constant ");
{id} printf(" Identifier ");
%%
int main()
{
if(yylex()==1)
printf("\nSection-end\n");
return 0;
}