-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscanner.l
More file actions
66 lines (58 loc) · 2.32 KB
/
scanner.l
File metadata and controls
66 lines (58 loc) · 2.32 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
%{
using namespace std;
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <stdlib.h>
#include <utility>
#include "parser.tab.h"
extern int errors;
extern void yyerror(const char *);
char linebuf[500];
int lineno = 1;
%}
%option noyywrap yylineno
%%
\n.* { strcpy(linebuf, yytext+1); /* save the next line */
lineno++;
yyless(1);/* give back all but the \n to rescan */}
[0-9]+ { yylval.int_value = atoll(yytext); return(NUMBER); }
\([^)]*[)\n] { /* ignore comments */ }
":=" { return(ASSIGN); }
"=" { return(EQ); }
"<>" { return(NEQ); }
"<" { return(LESS); }
">" { return(GREATER); }
"<=" { return(LESSEQ); }
">=" { return(GREATEREQ); }
"[" { return *yytext; }
"]" { return *yytext; }
"+" { return *yytext; }
"/" { return *yytext; }
"*" { return *yytext; }
"%" { return *yytext; }
"-" { return *yytext; }
";" { return *yytext; }
"VAR" { return(VAR); }
"BEGIN" { return(BEGiN); }
"END" { return(END); }
"IF" { return(IF); }
"THEN" { return(THEN); }
"ELSE" { return(ELSE); }
"ENDIF" { return(ENDIF); }
"WHILE" { return(WHILE); }
"DO" { return(DO); }
"ENDWHILE" { return(ENDWHILE); }
"FOR" { return(FOR); }
"FROM" { return(FROM); }
"TO" { return(TO); }
"ENDFOR" { return(ENDFOR); }
"DOWNTO" { return(DOWNTO); }
"READ" { return(READ); }
"WRITE" { return(WRITE); }
[_a-z]+ { yylval.id = (char *) strdup(yytext); return(PIDIDENTIFIER);}
[ \t]+ { /* eat up whitespace */ }
. { cerr<<"Error: Unknown character "<< yytext <<endl; yyerror(" "); errors++;}
[_a-z0-9^&)(}{!@#$]+ { cerr<<"Error: Wrong variable name"<<endl; yyerror(" "); errors++;}
%%