-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscanner.l
More file actions
94 lines (72 loc) · 1.95 KB
/
scanner.l
File metadata and controls
94 lines (72 loc) · 1.95 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
%{
//Inserção das bibliotecas necessárias
#include <stdio.h>
#include "y.tab.h"
#include <stdlib.h>
#include "mytable.h"
//Declarando as assinaturas das funções e criando variaveis globais
extern void yyerror(const char *);
static void comment(void);
int yylineno ;
%}
L [a-zA-Z_]
A [a-zA-Z_0-9]
D [0-9]
NZ [1-9]
UNDER (_)
WS [ \t\v\n\f]
%%
"/*" { comment(); }
"//".* { /* consume //-comment */ }
{NZ}{D}* { yylval.intval = strdup(yytext);return(NUMBER); }
"int" { yylval.intval = strdup(yytext);return(INT); }
"char" { yylval.intval = strdup(yytext);return(CHAR); }
"if" { return(IF); }
"else" { return(ELSE); }
"and" { return(AND); }
"not" { return(NOT); }
"while" { return WHILE;}
"return" { return RETURN; }
"or" { return(OR); }
"(" { return PAR_OPEN; }
")" { return PAR_CLOSE; }
";" { return SEMICOLON; }
"{" { return CB_OPEN; }
"}" { return CB_CLOSE; }
"+" { return PLUS; }
"-" { return MINUS; }
"*" { return ASTERISK; }
"/" { return SLASH; }
"=" { return ASSIGNMENT; }
"<=" { return LESS_EQUAL; }
"<" { return LESS; }
">=" { return MORE_EQUAL; }
">" { return MORE; }
"==" { return EQUAL; }
"!=" { return NOT_EQUAL; }
"," { return COMMA;}
"'" {return QUOT;}
{UNDER}{L} { yylval.charval = yytext[1];
return LITERAL_C ; }
{L}{A}* { yylval.symp = symlook(yytext);
return(ID); }
{WS} { if( *yytext == '\n' ){yylineno++;} }
. { yyerror("Undefiend keyword"); }
%%
int yywrap(void){
return 1;
}
static void comment(void){
int c;
while ((c = input()) != 0)
if (c == '*')
{
while ((c = input()) == '*')
;
if (c == '/')
return;
if (c == 0)
break;
}
yyerror("unterminated comment");
}