-
Notifications
You must be signed in to change notification settings - Fork 0
/
kurs.txt
193 lines (174 loc) · 5.62 KB
/
kurs.txt
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
%scaner_name myfirstscaner
%codes_type codes
%ident_name Id
%idents {[:Letter:]|[:letter:]|_}{[:Letter:]|[:letter:]|_|[:digits:]}
%class_members
" __int128 int_value;
__int128 fract_part;
size_t exponent;
int num_of_digits;
int sign_of_degree;
bool is_float;
__float128 build_float();"
%token_fields
"unsigned __int128 int_val; __float128 float_val;"
%codes
Int, Float, False,
Char, String, Void,
If, Const, ElseIf,
Else, EndIf, For,
While, Repeat, Until,
Exit, Continue, Return,
Read, Print, Kw_Int,
Kw_float, Kw_bool, Kw_char,
Kw_string, Kw_void, Var,
Kw_array, Proto, Func,
Equal, Plus, Minus,
Multiplication, Division, Module,
LessThan, MoreThan, LessOrEqual,
MoreOrEqual, Unequal, FractDiv,
LogicalOr, LogicarNor, LogicalNot,
LogicalAnd, LogicalNAnd, LXor,
LNXor, BitXor, BitOr,
BNXor, BNor, BitAnd,
BinaryAnd, BitLeftShift, BirRightShift,
FractPow, Openif_block, endif_block,
Open_round, Close_round, Dim_size,
Cond_op, Semicolon, Comma,
after_label, Open_square, Close_square,
Colon, ColonAssign, PlusColonAssign,
MinusColonAssign, MultColonAssign, SlashColonAssign,
SlashDotColonAssign, TwoMultColonAssign, TwoMultDotColonAssign,
PercColonAssign, AmpColonAssign, TilAmpColonAssign,
LShiftColAssign, RShiftColAssign, PipColAssign,
TilPipColAssign, CirColAssign, TilCirColAssign,
TwoPipColAssign, NTwoPipColAssign, TwoCirColAssign,
NTwoCirColAssign, TwoColAssign, NTwoColAssign,
True
%impl_additions "
#include <quadmath>
size_t digit2int(char32_t ch)
{
size_t v = ch - U'0';
return (v<=9)? v:(v&0b1101'1111) - 7;
};
__float128 myfirstscaner::build_float()
{
__float128 num;
num = int_value + fract_part*powq(10, num_of_digits);
num = num*powq(10, sign_of_degree*exponent);
return num;}"
%keywords
"var" : Var,
"int" : Kw_int,
"float" : Kw_float,
"bool" : Kw_bool,
"char" : Kw_char,
"string" : Kw_string,
"void" : Kw_void,
"array" : Kw_array,
"true" : True,
"false" : False,
"proto" : Proto,
"func" : Func,
"const" : Const,
"if" : If,
"elif" : ElseIf,
"else" : Else,
"endif" : EndIf,
"for" : For,
"while" : While,
"repeat" : Repeat,
"until" : Until,
"exit" : Exit,
"continue" : Continue,
"return" : Return,
"read" : Read,
"print" : Print
%delimiters
"=" : Equal,
"+" : Plus,
"-" : Minus,
"*" : Multiplication,
"/" : Division,
"%" : Module,
"<" : LessThan,
">" : MoreThan,
"<=" : LessOrEqual,
">=" : MoreOrEqual,
"!=" : Unequal,
"/." : FractDiv,
"||" : LogicalOr,
"!||" : LogicalNor,
"!" : LogicalNot,
"&&" : LogicalAnd,
"!&&" : LogicalNAnd,
"^^" : LXor,
"!^^" : LNXor,
"^" : BitXor,
"|" : BitOr,
"~^" : BNXor,
"~|" : BNor,
"&" : BitAnd,
"~&" : BinaryAnd,
"<<" : BitLeftShift,
">>" : BirRightShift,
"**." : FractPow,
"{" : Openif_block,
"}" : endif_block,
"(" : Open_round,
")" : Close_round,
"#" : Dim_size,
"?" : cond_op,
";" : Semicolon,
"," : Comma,
"::" : after_label,
"[" : Open_square,
"]" : Close_square,
":" : Colon,
":=" : ColonAssign,
"+:=" : PlusColonAssign,
"-:=" : MinusColonAssign,
"*:=" : MultColonAssign,
"/:=" : SlashColonAssign,
"/.:=" : SlashDotColonAssign,
"**:=" : TwoMultColonAssign,
"**.:=" : TwoMultDotColonAssign,
"%:=" : PercColonAssign,
"&:=" : AmpColonAssign,
"~&:=" : TilAmpColonAssign,
"<<:=" : LShiftColAssign,
">>:=" : RShiftColAssign,
"|:=" : PipColAssign,
"~|:=" : TilPipColAssign,
"^:=" : CirColAssign,
"~^:=" : TilCirColAssign,
"||:=" : TwoPipColAssign,
"!||:=" : NTwoPipColAssign,
"^^:=" : TwoCirColAssign,
"!^^:=" : NTwoCirColAssign,
"&&:=" : TwoColAssign,
"!&&:=" : NTwoColAssign
%numbers "int_value = 0; fract_part = 0; exponent = 0; num_of_digits = 0; is_float = false" : "if(is_float)
{
token.code = Float;
token.float_val = build_value();
}
else
{
token.code = Int;
token.int_val = int_value;
}"
%action SetFlag "is_float = true;"
%action AddDecNumb "int_value = int_value*10 + digit2int(ch);"
%action AddBinNumb "int_value = (int_value << 1) + digit2int(ch);"
%action AddOctNumb "int_value = (int_value << 3) + digit2int(ch);"
%action AddHexNumb "int_value = (int_value << 4) + digit2int(ch);"
%action AddToDegre "exponent = exponent*10 + digit2int(ch);"
%action AddDecToFract "fract_part = fract_part*10 + digit2int(ch); ++num_of_digits;"
%action WhatSign "sign_of_degree = (ch == U'+')?1:(-1);"
{[:digits:]$AddDecNumb('?[:digits:]$AddDecNumb)*(.$SetFlag[:digits:]$AddDecToFract('?[:digits:]$AddDecToFract)*)
?((E|e)$SetFlag(\+|-)$WhatSign?[:digits:]$AddToDegre('?[:digits:]$AddToDegre)*)?
|0o[:odigits:]$AddOctNumb('?[:odigits:]$AddOctNumb)*|
0(b|B)[:bdigits:]$AddBinNumb('?[:bdigits:]$AddBinNumb)*|
0(x|X)[:xdigits:]$AddHexNumb('?[:xdigits:]$AddHexNumb)*}