-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlexer.lex
66 lines (62 loc) · 959 Bytes
/
lexer.lex
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
%option noinput
%option nounput
%option noyywrap
%{
#include<iostream>
#include<cstring>
#include"matrix.hpp"
#include<vector>
#include<string>
#include<cstring>
#include"parser.tab.hpp"
%}
%%
exit {
return exit_tok;
}
clear {
return clear_tok;
}
ls {
return ls_tok;
}
pwd {
return pwd_tok;
}
chusername {
return chusername_tok;
}
matlab {
return matlab_tok;
}
[a-zA-Z][a-zA-Z0-9]* {
if (strlen(yytext) == 1){
// Matrix variable name can only be one upper letter
yylval.string_type = new std::string(yytext);
return id_matrix_tok;
}else{
yylval.s = yytext;
return id_tok;
}
}
(-)[a-zA-Z]+ {
yylval.s = yytext;
return ls_flags_tok;
}
([0-9]|[1-9][0-9]+) {
yylval.int_type = atoi(yytext);
return num_tok;
}
([0-9]|[1-9][0-9]+)(\.([0-9]+))? {
yylval.double_type = atof(yytext);
return d_num_tok;
}
[(),%+=[\];*/\n-] {
return *yytext;
}
[ \t] {}
. {
std::cerr << "Unknown token: " << *yytext << std::endl;
exit(EXIT_FAILURE);
}
%%