-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLexicalRules.lex
More file actions
87 lines (63 loc) · 3.23 KB
/
LexicalRules.lex
File metadata and controls
87 lines (63 loc) · 3.23 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
%using QUT.Gppg;
%using MiNICompiler.Enums;
%namespace GardensPoint
IntValue 0|([1-9]+[0-9]*)
DoubleValue (([0-9]|[1-9]+[0-9]*)\.[0-9]+)
BoolValue true|false
Ident [a-zA-Z][a-zA-Z0-9]*
String \"(\\.|[^"\\\n])*\"
Comment \/\/.*(\n|\r\n)
%%
"program" { return (int)Tokens.Program; }
"write" { return (int)Tokens.Write; }
"read" { return (int)Tokens.Read; }
"int" { yylval.type=VarType.Int; return (int)Tokens.Int; }
"double" { yylval.type=VarType.Double; return (int)Tokens.Double; }
"bool" { yylval.type=VarType.Bool; return (int)Tokens.Bool; }
"if" { return (int)Tokens.If; }
"else" { return (int)Tokens.Else; }
"while" { return (int)Tokens.While; }
"return" { return (int)Tokens.Return; }
{IntValue} { yylval.value=yytext; return (int)Tokens.IntValue; }
{DoubleValue} { yylval.value=yytext; return (int)Tokens.DoubleValue; }
{BoolValue} { yylval.value=yytext; return (int)Tokens.BoolValue; }
{Ident} { yylval.value=yytext; return (int)Tokens.Identificator; }
{String} { yylval.value=yytext; return (int)Tokens.String; }
"=" { return (int)Tokens.Assign; }
"&&" { yylval.logicalOp=LogicalOperator.And; return (int)Tokens.LogicalOperator; }
"||" { yylval.logicalOp=LogicalOperator.Or; return (int)Tokens.LogicalOperator; }
"==" { yylval.relationalOp=RelationalOperator.Equal; return (int)Tokens.RelationalOperator; }
"!=" { yylval.relationalOp=RelationalOperator.NotEqual; return (int)Tokens.RelationalOperator; }
">" { yylval.relationalOp=RelationalOperator.Bigger; return (int)Tokens.RelationalOperator; }
">=" { yylval.relationalOp=RelationalOperator.BiggerOrEqual; return (int)Tokens.RelationalOperator; }
"<" { yylval.relationalOp=RelationalOperator.Smaller; return (int)Tokens.RelationalOperator; }
"<=" { yylval.relationalOp=RelationalOperator.SmallerOrEqual; return (int)Tokens.RelationalOperator; }
"+" { yylval.additiveOp=AdditiveOperator.Add; return (int)Tokens.AdditiveOperator; }
"-" { yylval.additiveOp=AdditiveOperator.Sub; return (int)Tokens.Minus;/*Równie¿ minus unarny*/ }
"*" { yylval.multiplicativeOp=MultiplicativeOperator.Multi; return (int)Tokens.MultiplicativeOperator; }
"/" { yylval.multiplicativeOp=MultiplicativeOperator.Div; return (int)Tokens.MultiplicativeOperator; }
"|" { yylval.bitwiseOp=BitwiseOperator.Or; return (int)Tokens.BitwiseOperator; }
"&" { yylval.bitwiseOp=BitwiseOperator.And; return (int)Tokens.BitwiseOperator; }
"!" { yylval.unaryOp=UnaryOperator.LogNeg; return (int)Tokens.UnaryOperator; }
"~" { yylval.unaryOp=UnaryOperator.BitNeg; return (int)Tokens.UnaryOperator; }
"{" { return (int)Tokens.OpenBrace; }
"}" { return (int)Tokens.CloseBrace; }
"(" { return (int)Tokens.OpenParenthesis; }
")" { return (int)Tokens.CloseParenthesis; }
";" { return (int)Tokens.StatementTerminator; }
<<EOF>> { return (int)Tokens.Eof; }
{Comment} { }
" " { }
"\t" { }
"\r\n" { }
"\n" { }
. { return (int)Tokens.Error; }
%{
yylloc = new LexLocation(tokLin, tokCol, tokELin, tokECol);
%}
%%
public override void yyerror(string format, params object[] args)
{
Console.WriteLine("Line " + yylloc.StartLine + ": syntax error");
base.yyerror(format, args);
}