-
Notifications
You must be signed in to change notification settings - Fork 0
/
lexer.l
97 lines (73 loc) · 2.17 KB
/
lexer.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
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
94
95
96
%{
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "sds.h"
extern void yyerror(char const* msg);
//#ifndef YYSTYPE
// #define YYSTYPE char*
//#endif
#include "parser.h"
extern int yyparse();
int line=1;
%}
%option yylineno
%x COMMENT
%%
<INITIAL>"/*" { BEGIN(COMMENT); }
<COMMENT>"*/" { BEGIN(INITIAL); }
<COMMENT>\n { line++; }
<COMMENT>. { ; }
<INITIAL>"program" { return(PROGRAM); }
<INITIAL>"data" { return(DATA); }
<INITIAL>"procedure" { return(PROCEDURE); }
<INITIAL>"division" { return(DIVISION); }
<INITIAL>"get" { return(GET); }
<INITIAL>"set" { return(SET); }
<INITIAL>"put" { return(PUT); }
<INITIAL>"to" { return(TO); }
<INITIAL>"execute" { return(EXECUTE); }
<INITIAL>"repeat" { return(REPEAT); }
<INITIAL>"either" { return(EITHER); }
<INITIAL>"both" { return(BOTH); }
<INITIAL>"neither" { return(NEITHER); }
<INITIAL>"lt" { return(LT); }
<INITIAL>"le" { return(LE); }
<INITIAL>"gt" { return(GT); }
<INITIAL>"ge" { return(GE); }
<INITIAL>"ne" { return(NE); }
<INITIAL>"eq" { return(EQ); }
<INITIAL>"not" { return(NOT); }
<INITIAL>"nor" { return(NOR); }
<INITIAL>"and" { return(AND); }
<INITIAL>"or" { return(OR); }
<INITIAL>"+" { return(ADD); }
<INITIAL>"-" { return(SUB); }
<INITIAL>"*" { return(MUL); }
<INITIAL>"/" { return(DIV); }
<INITIAL>"{" { return(SECTION_OPEN); }
<INITIAL>"}" { return(SECTION_CLOSE); }
<INITIAL>"(" { return(LEFTPAREN); }
<INITIAL>")" { return(RIGHTPAREN); }
<INITIAL>"integer" { return(INTEGER); }
<INITIAL>"float" { return(FLOAT); }
<INITIAL>"char" { return(CHAR); }
<INITIAL>"unsigned" { return(UNSIGNED); }
<INITIAL>"end" { return(END); }
<INITIAL>"," { return(SEMICOLON); }
<INITIAL>":" { return(COLON); }
<INITIAL>";" { return(COMMANDEND); }
[0-9]*|[0-9]*\.[0-9]* { yylval.string = sdsnew(yytext); return(NUMBER); }
[a-zA-Z][a-zA-Z0-9]* {
if(strlen(yytext) > 20) {
yyerror("not good to use a long ident!\n");
}
yylval.string = sdsnew(yytext);
return(ID);
}
\'(\\.|[^\\'\n])*\' { yylval.string = sdsnew(yytext); return(STRING); }
[ \t] ;
[\n] {
line++;
}
%%