-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmc.lex
102 lines (82 loc) · 2.91 KB
/
mc.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
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
97
98
99
100
101
%{
bool verb = false;
void verbose(string token){
if(verb){
cout << token;
}
return;
}
%}
%option noyywrap
%s QuoteSC
digit [0-9]
virgule \.{digit}+
nombre {digit}+{virgule}?
identifier [a-zA-Z][_a-zA-Z0-9]*
newline \n|\r|\f
%%
return {verbose("RETURN");return(RETURN);};
for {verbose("FOR");return(FOR);};
end/\ *{newline} {verbose("END");return(END);};
end {verbose("EXEND");return(EXEND);};
if {verbose("IF");return(IF);};
elseif {verbose("ELSEIF");return(ELSEIF);};
else {verbose("ELSE");return(ELSE);};
while {verbose("WHILE");return(WHILE);};
function {verbose("FUNCTION");return(FUNCTION);};
\ {BEGIN(INITIAL);
if(in_matrix>0){
verbose("MSPACE");return(MSPACE);
}
}
\%[^\n\r\f]* {BEGIN(INITIAL);}
{nombre} {BEGIN(QuoteSC);verbose("NBRE");yylval.source = yytext;return(NBRE);}
{identifier} {BEGIN(QuoteSC);verbose("ID");
yylval.source = yytext;
if(yylval.source.compare("class")==0){
yylval.source += "_reserved";
}
return(ID);}
\[/[^=;\n\t\f]*]\ *=[^=] {BEGIN(INITIAL);verbose("LD");return(LD);}
\]/\ *=[^=] {BEGIN(INITIAL);verbose("RD");return(RD);}
- {BEGIN(INITIAL);verbose("-");return('-');}
\+ {BEGIN(INITIAL);verbose("+");return('+');}
\* {BEGIN(INITIAL);verbose("*");return('*');}
\.\* {BEGIN(INITIAL);verbose("TIMES");return(TIMES);}
\/ {BEGIN(INITIAL);verbose("/");return('/');}
\\ {BEGIN(INITIAL);verbose("\\");return('\\');}
\.\/ {BEGIN(INITIAL);verbose("DEVIDE");return(DIVIDE);}
\.\\ {BEGIN(INITIAL);verbose("LDEVIDE");return(LDIVIDE);}
\( {BEGIN(INITIAL);verbose("(");return('(');}
\) {BEGIN(INITIAL);verbose(")");return(')');}
\} {BEGIN(INITIAL);verbose("}");return('}');}
\{ {BEGIN(INITIAL);verbose("{");return('{');}
\^ {BEGIN(INITIAL);verbose("^");return('^');}
\.\^ {BEGIN(INITIAL);verbose("POWER");return(POWER);}
: {BEGIN(INITIAL);verbose(":");return(':');}
;\ |; {BEGIN(INITIAL);verbose(";");return(';');}
,\ |, {BEGIN(INITIAL);verbose(",");return(',');}
\[ {BEGIN(INITIAL);verbose("[");return('[');}
\] {BEGIN(QuoteSC);verbose("]");return(']');}
== {BEGIN(INITIAL);verbose("EQ");return(EQ);}
~= {BEGIN(INITIAL);verbose("NE");return(NE);}
\< {BEGIN(INITIAL);verbose("<");return('<');}
\> {BEGIN(INITIAL);verbose(">");return('>');}
\<= {BEGIN(INITIAL);verbose("LE");return(LE);}
\>= {BEGIN(INITIAL);verbose("GE");return(GE);}
\| {BEGIN(INITIAL);verbose("|");return('|');}
& {BEGIN(INITIAL);verbose("&");return('&');}
\|\| {BEGIN(INITIAL);verbose("LOR");return(LOR);}
&& {BEGIN(INITIAL);verbose("LAND");return(LAND);}
= {BEGIN(INITIAL);verbose("=");return('=');}
{newline} {BEGIN(INITIAL);
no_line++;
ostringstream oss;
oss <<"NEWLINE\n" <<no_line <<"> ";
verbose(oss.str());return(NEWLINE);}
\.' {BEGIN(QuoteSC);verbose("TRANSPOSE");return(TRANSPOSE);}
' {BEGIN(QuoteSC);verbose("CTRANSPOSE");return(CTRANSPOSE);}
~ {BEGIN(INITIAL);verbose("~");return('~');}
@ {BEGIN(INITIAL);verbose("@");return('@');}
<INITIAL>'[^'\r\f\n]*' { yylval.source = yytext;verbose("TEXT"); return(TEXT);};
%%