| 1 |
unit CellK; |
| 2 |
|
| 3 |
interface |
| 4 |
|
| 5 |
uses CellG, CellV; |
| 6 |
|
| 7 |
type |
| 8 |
TCellK = class |
| 9 |
private |
| 10 |
_cellG: TCellG; |
| 11 |
_cellV: TCellV; |
| 12 |
token: TToken; |
| 13 |
retIS: Boolean; |
| 14 |
loop: Boolean; |
| 15 |
forex: Boolean; |
| 16 |
con: Boolean; |
| 17 |
saIndex: integer; |
| 18 |
saCode: integer; |
| 19 |
sahen: integer; |
| 20 |
breCode: integer; |
| 21 |
shift: integer; |
| 22 |
ident: string; |
| 23 |
public |
| 24 |
constructor Create(v: TCellV; g: TCellG); |
| 25 |
function compile: Boolean; |
| 26 |
procedure _module; |
| 27 |
procedure _block_body; |
| 28 |
procedure _block; |
| 29 |
procedure _function; |
| 30 |
procedure _array; |
| 31 |
procedure _statement; |
| 32 |
procedure _condition; |
| 33 |
procedure _expression; |
| 34 |
procedure _expression1; |
| 35 |
procedure _expression2; |
| 36 |
procedure _term; |
| 37 |
procedure _factor; |
| 38 |
procedure _Sa; |
| 39 |
function hairetu(const ti: integer): Boolean; |
| 40 |
procedure checkKata(t: integer); |
| 41 |
procedure shokika; |
| 42 |
end; |
| 43 |
|
| 44 |
implementation |
| 45 |
|
| 46 |
{ TCellK } |
| 47 |
|
| 48 |
procedure TCellK._block_body; |
| 49 |
begin |
| 50 |
while true do |
| 51 |
case token.kind of |
| 52 |
CellG._aI: |
| 53 |
_array; |
| 54 |
CellG._Rbrace, CellG.dollar: |
| 55 |
break; |
| 56 |
CellG._I, CellG._S, CellG._V: |
| 57 |
break; |
| 58 |
else |
| 59 |
_statement; |
| 60 |
end; |
| 61 |
end; |
| 62 |
|
| 63 |
function TCellK.compile: Boolean; |
| 64 |
begin |
| 65 |
_cellG.shokika; |
| 66 |
_cellV.shokika; |
| 67 |
shokika; |
| 68 |
token := _cellG.makeToken; |
| 69 |
while token.kind <> CellG.dollar do |
| 70 |
_module; |
| 71 |
result := _cellG.e < 1; |
| 72 |
end; |
| 73 |
|
| 74 |
constructor TCellK.Create(v: TCellV; g: TCellG); |
| 75 |
begin |
| 76 |
inherited Create; |
| 77 |
shokika; |
| 78 |
_cellV := v; |
| 79 |
_cellG := g; |
| 80 |
end; |
| 81 |
|
| 82 |
procedure TCellK._module; |
| 83 |
var |
| 84 |
backP: integer; |
| 85 |
backP1, backP2: integer; |
| 86 |
begin |
| 87 |
if token.kind = CellG.Id then |
| 88 |
_cellG.setModule(token.Id) |
| 89 |
else |
| 90 |
_cellG.error('���W���[����������������'); |
| 91 |
token := _cellG.checkGet(_cellG.makeToken, CellG._Lbrace); |
| 92 |
backP1 := _cellV.genCodeP(CellV.ict, 0); |
| 93 |
backP2 := _cellV.genCodeP(CellV.ics, 0); |
| 94 |
_cellG.blockBegin; |
| 95 |
_block_body; |
| 96 |
while (token.kind = CellG._I) or (token.kind = CellG._S) or |
| 97 |
(token.kind = CellG._V) do |
| 98 |
begin |
| 99 |
backP := _cellV.genCodeP(CellV.jmp, 0); |
| 100 |
_function; |
| 101 |
_cellV.backPatchJ(backP); |
| 102 |
_block_body; |
| 103 |
end; |
| 104 |
_cellV.backPatch(backP1, backP2); |
| 105 |
_cellG.blockEnd; |
| 106 |
token := _cellG.checkGet(token, CellG._Rbrace); |
| 107 |
end; |
| 108 |
|
| 109 |
procedure TCellK._array; |
| 110 |
var |
| 111 |
v: integer; |
| 112 |
Id: string; |
| 113 |
begin |
| 114 |
token := _cellG.makeToken; |
| 115 |
while true do |
| 116 |
begin |
| 117 |
if token.kind = CellG.Id then |
| 118 |
begin |
| 119 |
Id := token.Id; |
| 120 |
token := _cellG.checkGet(_cellG.makeToken, CellG._Lbracket); |
| 121 |
if token.kind = CellG.Num then |
| 122 |
begin |
| 123 |
v := token.value; |
| 124 |
token := _cellG.makeToken; |
| 125 |
if token.kind = CellG._Rbracket then |
| 126 |
begin |
| 127 |
_cellG.tableA1int(Id, v); |
| 128 |
token := _cellG.makeToken; |
| 129 |
end |
| 130 |
else if token.kind = CellG._Ex then |
| 131 |
begin |
| 132 |
token := _cellG.makeToken; |
| 133 |
if token.kind = CellG.Num then |
| 134 |
begin |
| 135 |
_cellG.tableA2int(Id, v, token.value); |
| 136 |
token := _cellG.checkGet(_cellG.makeToken, CellG._Rbracket); |
| 137 |
end |
| 138 |
else |
| 139 |
begin |
| 140 |
_cellG.error('����������������'); |
| 141 |
Exit; |
| 142 |
end; |
| 143 |
end |
| 144 |
else |
| 145 |
begin |
| 146 |
_cellG.error('���O������������'); |
| 147 |
Exit; |
| 148 |
end; |
| 149 |
end; |
| 150 |
end; |
| 151 |
if token.kind = CellG._Comma then |
| 152 |
begin |
| 153 |
token := _cellG.makeToken; |
| 154 |
continue; |
| 155 |
end |
| 156 |
else if token.kind = CellG._Semicolon then |
| 157 |
begin |
| 158 |
token := _cellG.makeToken; |
| 159 |
Exit; |
| 160 |
end |
| 161 |
else |
| 162 |
begin |
| 163 |
_cellG.error('; or , ������������'); |
| 164 |
Exit; |
| 165 |
end; |
| 166 |
end; |
| 167 |
end; |
| 168 |
|
| 169 |
procedure TCellK._block; |
| 170 |
var |
| 171 |
backP1, backP2: integer; |
| 172 |
begin |
| 173 |
token := _cellG.checkGet(token, CellG._Lbrace); |
| 174 |
backP1 := _cellV.genCodeP(CellV.ict, 0); |
| 175 |
backP2 := _cellV.genCodeP(CellV.ics, 0); |
| 176 |
_block_body; |
| 177 |
_cellV.backPatch(backP1, backP2); |
| 178 |
_cellG.blockEnd; |
| 179 |
if token.kind = CellG.dollar then |
| 180 |
_cellG.error('}������������') |
| 181 |
else |
| 182 |
token := _cellG.makeToken; |
| 183 |
end; |
| 184 |
|
| 185 |
procedure TCellK._function; |
| 186 |
var |
| 187 |
f: integer; |
| 188 |
s: string; |
| 189 |
err, x: Boolean; |
| 190 |
begin |
| 191 |
s := ''; |
| 192 |
f := token.kind; |
| 193 |
x := f = CellG._V; |
| 194 |
token := _cellG.makeToken; |
| 195 |
if token.kind = CellG.Id then |
| 196 |
begin |
| 197 |
s := token.Id; |
| 198 |
token := _cellG.makeToken; |
| 199 |
_cellG.tableFunc(s, _cellV.nextCode, f); |
| 200 |
end |
| 201 |
else |
| 202 |
_cellG.error('������������������'); |
| 203 |
token := _cellG.checkGet(token, CellG._Lparen); |
| 204 |
_cellG.blockBegin; |
| 205 |
err := false; |
| 206 |
if token.kind = CellG._Rparen then |
| 207 |
token := _cellG.makeToken |
| 208 |
else |
| 209 |
while true do |
| 210 |
begin |
| 211 |
f := token.kind; |
| 212 |
if (f = CellG._I) or (f = CellG._S) then |
| 213 |
begin |
| 214 |
token := _cellG.makeToken; |
| 215 |
if token.kind = CellG.Id then |
| 216 |
begin |
| 217 |
if f = CellG._I then |
| 218 |
begin |
| 219 |
_cellG.tablePint(token.Id); |
| 220 |
end |
| 221 |
else |
| 222 |
begin |
| 223 |
_cellG.tablePstr(token.Id); |
| 224 |
end; |
| 225 |
token := _cellG.makeToken; |
| 226 |
end |
| 227 |
else |
| 228 |
begin |
| 229 |
_cellG.error('������������������'); |
| 230 |
end; |
| 231 |
if token.kind = CellG._Comma then |
| 232 |
begin |
| 233 |
token := _cellG.makeToken; |
| 234 |
continue; |
| 235 |
end |
| 236 |
else if token.kind = CellG._Rparen then |
| 237 |
begin |
| 238 |
_cellG.endPar; |
| 239 |
token := _cellG.makeToken; |
| 240 |
break; |
| 241 |
end |
| 242 |
else |
| 243 |
begin |
| 244 |
_cellG.error(',or)������������'); |
| 245 |
err := true; |
| 246 |
break; |
| 247 |
end; |
| 248 |
end |
| 249 |
else |
| 250 |
begin |
| 251 |
_cellG.error('SorI������������'); |
| 252 |
err := true; |
| 253 |
break; |
| 254 |
end; |
| 255 |
end; |
| 256 |
if err = true then |
| 257 |
while (token.kind <> CellG._Lbrace) and (token.kind <> CellG._Rbrace) and |
| 258 |
(token.kind <> CellG._Semicolon) do |
| 259 |
begin |
| 260 |
if token.kind = CellG._Rbrace then |
| 261 |
begin |
| 262 |
_cellG.error('{ ������������'); |
| 263 |
_cellG.blockEnd; |
| 264 |
token := _cellG.makeToken; |
| 265 |
Exit; |
| 266 |
end; |
| 267 |
token := _cellG.makeToken; |
| 268 |
end; |
| 269 |
if (err = false) and (s <> '') then |
| 270 |
_cellG.checkKari(s); |
| 271 |
_block; |
| 272 |
if x = true then |
| 273 |
begin |
| 274 |
_cellV.genCodeRV; |
| 275 |
retIS := true; |
| 276 |
end; |
| 277 |
if retIS = false then |
| 278 |
_cellG.error('return��������������'); |
| 279 |
retIS := false; |
| 280 |
end; |
| 281 |
|
| 282 |
procedure TCellK._expression; |
| 283 |
var |
| 284 |
sa, saI, saC: integer; |
| 285 |
s, ti: integer; |
| 286 |
begin |
| 287 |
_expression1; |
| 288 |
if token.kind <> CellG._Equal then |
| 289 |
Exit; |
| 290 |
if sahen = 0 then |
| 291 |
_cellG.error('�������������������������B'); |
| 292 |
s := shift; |
| 293 |
saI := saIndex; |
| 294 |
saC := saCode; |
| 295 |
if sahen = -1 then |
| 296 |
if shift = 2 then |
| 297 |
begin |
| 298 |
ti := _cellG.tableString(ident); |
| 299 |
sahen := CellG.strID; |
| 300 |
_cellV.backPatchL(saC, ti, 1); |
| 301 |
s := 2; |
| 302 |
end |
| 303 |
else |
| 304 |
begin |
| 305 |
ti := _cellG.tableInt(ident); |
| 306 |
sahen := CellG.intID; |
| 307 |
_cellV.backPatchL(saC, ti, 0); |
| 308 |
s := 1; |
| 309 |
end; |
| 310 |
shift := 0; |
| 311 |
sa := sahen; |
| 312 |
token := _cellG.makeToken; |
| 313 |
_expression; |
| 314 |
if (sa <> -1) and (s <> shift) then |
| 315 |
if ((sa = CellG.intID) or (sa = CellG.strID)) and (sa <> CellG.arrI) and |
| 316 |
(sa <> CellG.arrS) then |
| 317 |
if shift = 2 then |
| 318 |
begin |
| 319 |
_cellG.changeT(saI, strID, false); |
| 320 |
_cellV.backPatchL(saC, saI, 1); |
| 321 |
end |
| 322 |
else |
| 323 |
begin |
| 324 |
_cellG.changeT(saI, intID, false); |
| 325 |
_cellV.backPatchL(saC, saI, 0); |
| 326 |
end |
| 327 |
else |
| 328 |
_cellG.error('�^�����v��������'); |
| 329 |
if s <> shift then |
| 330 |
if (s = 1) and (con = true) then |
| 331 |
shift := 1; |
| 332 |
sa := sahen; |
| 333 |
if (token.kind = CellG._Rparen) or (token.kind = CellG._Semicolon) then |
| 334 |
begin |
| 335 |
if (shift = 2) or ((shift = 0) and (s = 2)) then |
| 336 |
ti := _cellV.genCodeO(CellV.sls) |
| 337 |
else |
| 338 |
ti := _cellV.genCodeO(CellV.sld); |
| 339 |
ident := ''; |
| 340 |
sa := 0; |
| 341 |
end |
| 342 |
else if (shift = 2) or ((shift = 0) and (s = 2)) then |
| 343 |
ti := _cellV.genCodeO(CellV.sds) |
| 344 |
else |
| 345 |
ti := _cellV.genCodeO(CellV.sid); |
| 346 |
if sahen = 0 then |
| 347 |
_cellG.setScI(ti); |
| 348 |
sahen := sa; |
| 349 |
saIndex := 0; |
| 350 |
saCode := 0; |
| 351 |
con := false; |
| 352 |
end; |
| 353 |
|
| 354 |
procedure TCellK._statement; |
| 355 |
var |
| 356 |
tk, tIndex, backP1, backP2, backP3, backP4, breTaihi: integer; |
| 357 |
i: integer; |
| 358 |
begin |
| 359 |
while true do |
| 360 |
begin |
| 361 |
case token.kind of |
| 362 |
CellG._Lbrace: |
| 363 |
begin |
| 364 |
_cellG.blockBegin; |
| 365 |
_cellV.genCodeP(CellV.dit, _cellG.bLevel); |
| 366 |
_block; |
| 367 |
_cellV.genCodeP(CellV.dik, _cellG.bLevel + 1); |
| 368 |
break; |
| 369 |
end; |
| 370 |
CellG.Id: |
| 371 |
begin |
| 372 |
_expression; |
| 373 |
token := _cellG.checkGet(token, CellG._Semicolon); |
| 374 |
shift := 0; |
| 375 |
break; |
| 376 |
end; |
| 377 |
CellG._Read, CellG._ReadS: |
| 378 |
begin |
| 379 |
i := token.kind; |
| 380 |
token := _cellG.makeToken; |
| 381 |
if token.kind <> CellG.Id then |
| 382 |
begin |
| 383 |
_cellG.error('���O������������'); |
| 384 |
token := _cellG.makeToken; |
| 385 |
continue; |
| 386 |
end; |
| 387 |
tIndex := _cellG.searchT(token.Id); |
| 388 |
tk := _cellG.tKind(tIndex); |
| 389 |
if (tk = CellG.strID) or (tk = CellG.parS) or |
| 390 |
((tk = 0) and (i = CellG._ReadS)) then |
| 391 |
begin |
| 392 |
if tk = 0 then |
| 393 |
tIndex := _cellG.tableString(token.Id); |
| 394 |
_cellV.genCodeT(CellV.las, tIndex); |
| 395 |
token := _cellG.makeToken; |
| 396 |
_cellV.genCodeO(CellV.ins); |
| 397 |
_cellV.genCodeO(CellV.sds); |
| 398 |
end |
| 399 |
else if (tk = CellG.arrI) or (tk = CellG.parI) or (tk = CellG.intID) |
| 400 |
or (tk = intID) or ((tk = 0) and (i = CellG._Read)) then |
| 401 |
begin |
| 402 |
if tk = 0 then |
| 403 |
tIndex := _cellG.tableInt(token.Id); |
| 404 |
_cellV.genCodeT(CellV.lda, tIndex); |
| 405 |
if tk = CellG.arrI then |
| 406 |
if hairetu(tIndex) = false then |
| 407 |
continue |
| 408 |
else |
| 409 |
token := _cellG.makeToken; |
| 410 |
_cellV.genCodeO(CellV.ini); |
| 411 |
_cellV.genCodeO(CellV.sid); |
| 412 |
end |
| 413 |
else |
| 414 |
begin |
| 415 |
_cellG.error('������������������'); |
| 416 |
token := _cellG.makeToken; |
| 417 |
continue; |
| 418 |
end; |
| 419 |
token := _cellG.checkGet(token, CellG._Semicolon); |
| 420 |
break; |
| 421 |
end; |
| 422 |
CellG._Print, CellG._Println: |
| 423 |
begin |
| 424 |
tk := token.kind; |
| 425 |
repeat |
| 426 |
token := _cellG.makeToken; |
| 427 |
if (token.kind = CellG._Semicolon) or (token.kind = CellG._Rbrace) |
| 428 |
then |
| 429 |
break; |
| 430 |
_expression; |
| 431 |
if shift = 2 then |
| 432 |
_cellV.genCodeO(CellV.prs) |
| 433 |
else |
| 434 |
_cellV.genCodeO(CellV.prt); |
| 435 |
shift := 0; |
| 436 |
until token.kind <> CellG._Comma; |
| 437 |
if tk = CellG._Println then |
| 438 |
_cellV.genCodeO(CellV.prl); |
| 439 |
token := _cellG.checkGet(token, CellG._Semicolon); |
| 440 |
break; |
| 441 |
end; |
| 442 |
CellG._If: |
| 443 |
begin |
| 444 |
token := _cellG.checkGet(_cellG.makeToken, CellG._Lparen); |
| 445 |
_expression; |
| 446 |
if con = false then |
| 447 |
_cellG.error('���������K�v�����B'); |
| 448 |
con := false; |
| 449 |
shift := 0; |
| 450 |
token := _cellG.checkGet(token, CellG._Rparen); |
| 451 |
backP1 := _cellV.genCodeP(CellV.jpc, 0); |
| 452 |
_statement; |
| 453 |
if token.kind = CellG._Else then |
| 454 |
begin |
| 455 |
backP2 := _cellV.genCodeP(CellV.jmp, 0); |
| 456 |
_cellV.backPatchJ(backP1); |
| 457 |
token := _cellG.makeToken; |
| 458 |
_statement; |
| 459 |
_cellV.backPatchJ(backP2); |
| 460 |
end |
| 461 |
else |
| 462 |
_cellV.backPatchJ(backP1); |
| 463 |
break; |
| 464 |
end; |
| 465 |
CellG._For: |
| 466 |
begin |
| 467 |
token := _cellG.checkGet(_cellG.makeToken, CellG._Lparen); |
| 468 |
shift := 1; |
| 469 |
_expression; |
| 470 |
token := _cellG.checkGet(token, CellG._Semicolon); |
| 471 |
backP2 := _cellV.nextCode; |
| 472 |
_expression; |
| 473 |
if con = false then |
| 474 |
_cellG.error('���������K�v����'); |
| 475 |
con := false; |
| 476 |
token := _cellG.checkGet(token, CellG._Semicolon); |
| 477 |
backP1 := _cellV.genCodeP(CellV.jpc, 0); |
| 478 |
backP3 := _cellV.genCodeP(CellV.jmp, 0); |
| 479 |
backP4 := _cellV.nextCode; |
| 480 |
forex := true; |
| 481 |
_expression; |
| 482 |
forex := false; |
| 483 |
shift := 0; |
| 484 |
_cellV.genCodeP(CellV.jmp, backP2); |
| 485 |
token := _cellG.checkGet(token, CellG._Rparen); |
| 486 |
_cellV.backPatchJ(backP3); |
| 487 |
loop := true; |
| 488 |
breTaihi := breCode; |
| 489 |
breCode := 0; |
| 490 |
_statement; |
| 491 |
_cellV.genCodeP(CellV.jmp, backP4); |
| 492 |
_cellV.backPatchJ(backP1); |
| 493 |
_cellV.backBreak(breCode); |
| 494 |
loop := false; |
| 495 |
breCode := breTaihi; |
| 496 |
break; |
| 497 |
end; |
| 498 |
CellG._While: |
| 499 |
begin |
| 500 |
token := _cellG.checkGet(_cellG.makeToken, CellG._Lparen); |
| 501 |
backP2 := _cellV.nextCode; |
| 502 |
_expression; |
| 503 |
if con = false then |
| 504 |
_cellG.error('���������K�v����'); |
| 505 |
con := false; |
| 506 |
shift := 0; |
| 507 |
token := _cellG.checkGet(token, CellG._Rparen); |
| 508 |
backP1 := _cellV.genCodeP(CellV.jpc, 0); |
| 509 |
loop := true; |
| 510 |
breTaihi := breCode; |
| 511 |
breCode := 0; |
| 512 |
_statement; |
| 513 |
_cellV.genCodeP(CellV.jmp, backP2); |
| 514 |
_cellV.backPatchJ(backP1); |
| 515 |
_cellV.backBreak(breCode); |
| 516 |
loop := false; |
| 517 |
breCode := breTaihi; |
| 518 |
break; |
| 519 |
end; |
| 520 |
CellG._Do: |
| 521 |
begin |
| 522 |
backP1 := _cellV.nextCode; |
| 523 |
token := _cellG.makeToken; |
| 524 |
loop := true; |
| 525 |
breTaihi := breCode; |
| 526 |
_statement; |
| 527 |
if token.kind <> CellG._While then |
| 528 |
begin |
| 529 |
_cellG.error('while������������'); |
| 530 |
continue; |
| 531 |
end |
| 532 |
else |
| 533 |
token := _cellG.makeToken; |
| 534 |
token := _cellG.checkGet(token, CellG._Lparen); |
| 535 |
_expression; |
| 536 |
if con = false then |
| 537 |
_cellG.error('���������K�v����'); |
| 538 |
con := false; |
| 539 |
shift := 0; |
| 540 |
token := _cellG.checkGet(token, CellG._Rparen); |
| 541 |
backP2 := _cellV.genCodeP(CellV.jpc, 0); |
| 542 |
_cellV.genCodeP(CellV.jmp, backP1); |
| 543 |
_cellV.backPatchJ(backP2); |
| 544 |
_cellV.backBreak(breCode); |
| 545 |
loop := false; |
| 546 |
breCode := breTaihi; |
| 547 |
token := _cellG.checkGet(token, CellG._Semicolon); |
| 548 |
break; |
| 549 |
end; |
| 550 |
CellG._Return: |
| 551 |
begin |
| 552 |
token := _cellG.makeToken; |
| 553 |
tk := _cellG.funcModori; |
| 554 |
if tk <> CellG._V then |
| 555 |
begin |
| 556 |
if (token.kind = CellG._Semicolon) or (token.kind = CellG._Rbrace) |
| 557 |
then |
| 558 |
begin |
| 559 |
_cellG.error('�����l������������'); |
| 560 |
continue; |
| 561 |
end; |
| 562 |
if tk = CellG._S then |
| 563 |
shift := 2 |
| 564 |
else |
| 565 |
shift := 1; |
| 566 |
_expression; |
| 567 |
shift := 0; |
| 568 |
end; |
| 569 |
retIS := true; |
| 570 |
_cellV.genCodeR; |
| 571 |
token := _cellG.checkGet(token, CellG._Semicolon); |
| 572 |
break; |
| 573 |
end; |
| 574 |
CellG._Break: |
| 575 |
begin |
| 576 |
if loop = true then |
| 577 |
breCode := _cellV.genCodeP(CellV.jmp, breCode) |
| 578 |
else |
| 579 |
_cellG.error('���[�v�O����'); |
| 580 |
token := _cellG.checkGet(_cellG.makeToken, CellG._Semicolon); |
| 581 |
break; |
| 582 |
end; |
| 583 |
CellG._Rbrace, CellG.dollar: |
| 584 |
continue; |
| 585 |
else |
| 586 |
token := _cellG.makeToken; |
| 587 |
end; |
| 588 |
end; |
| 589 |
end; |
| 590 |
|
| 591 |
procedure TCellK._condition; |
| 592 |
var |
| 593 |
k: integer; |
| 594 |
begin |
| 595 |
_expression; |
| 596 |
k := token.kind; |
| 597 |
token := _cellG.makeToken; |
| 598 |
_expression; |
| 599 |
case k of |
| 600 |
CellG._Equal2: |
| 601 |
_cellV.genCodeO(CellV.eql); |
| 602 |
CellG._NotEq: |
| 603 |
_cellV.genCodeO(CellV.neq); |
| 604 |
CellG._Lss: |
| 605 |
_cellV.genCodeO(CellV.lss); |
| 606 |
CellG._Gtr: |
| 607 |
_cellV.genCodeO(CellV.gtr); |
| 608 |
CellG._LssEq: |
| 609 |
_cellV.genCodeO(CellV.leq); |
| 610 |
CellG._GtrEq: |
| 611 |
_cellV.genCodeO(CellV.geq); |
| 612 |
else |
| 613 |
_cellG.error('����������������������'); |
| 614 |
end; |
| 615 |
end; |
| 616 |
|
| 617 |
procedure TCellK._term; |
| 618 |
var |
| 619 |
k: integer; |
| 620 |
x: Boolean; |
| 621 |
begin |
| 622 |
_factor; |
| 623 |
while (token.kind = CellG._Mult) or (token.kind = CellG._Div) do |
| 624 |
begin |
| 625 |
k := token.kind; |
| 626 |
token := _cellG.makeToken; |
| 627 |
if (shift = 2) and (k = CellG._Mult) then |
| 628 |
begin |
| 629 |
x := true; |
| 630 |
shift := 1; |
| 631 |
end |
| 632 |
else |
| 633 |
x := false; |
| 634 |
_factor; |
| 635 |
if x = true then |
| 636 |
shift := 2; |
| 637 |
if shift = 1 then |
| 638 |
begin |
| 639 |
if k = CellG._Mult then |
| 640 |
_cellV.genCodeO(CellV._mul) |
| 641 |
else |
| 642 |
_cellV.genCodeO(CellV._Div); |
| 643 |
end |
| 644 |
else if k = CellG._Mult then |
| 645 |
_cellV.genCodeO(CellV.mus) |
| 646 |
else |
| 647 |
_cellV.genCodeO(CellV.dis); |
| 648 |
sahen := 0; |
| 649 |
end; |
| 650 |
end; |
| 651 |
|
| 652 |
procedure TCellK._factor; |
| 653 |
var |
| 654 |
i, k, tIndex, pi, ps: integer; |
| 655 |
sa, saI, saC: integer; |
| 656 |
s, t: string; |
| 657 |
p: TRaddr; |
| 658 |
begin |
| 659 |
if token.kind = CellG.Num then |
| 660 |
begin |
| 661 |
checkKata(1); |
| 662 |
_cellV.genCodeV(CellV.lit, token.value); |
| 663 |
token := _cellG.makeToken; |
| 664 |
end |
| 665 |
else if token.kind = CellG.Moji then |
| 666 |
begin |
| 667 |
checkKata(2); |
| 668 |
_cellV.genCodeS(CellV.lis, token.Id); |
| 669 |
token := _cellG.makeToken; |
| 670 |
end |
| 671 |
else if token.kind = CellG._Lparen then |
| 672 |
begin |
| 673 |
token := _cellG.makeToken; |
| 674 |
_expression; |
| 675 |
token := _cellG.checkGet(token, CellG._Rparen); |
| 676 |
end |
| 677 |
else if (token.kind = CellG._Plus) or (token.kind = CellG._Minus) then |
| 678 |
begin |
| 679 |
checkKata(1); |
| 680 |
k := token.kind; |
| 681 |
token := _cellG.makeToken; |
| 682 |
_factor; |
| 683 |
if k = CellG._Minus then |
| 684 |
_cellV.genCodeO(CellV.neg); |
| 685 |
end |
| 686 |
else if token.kind = CellG.Id then |
| 687 |
begin |
| 688 |
tIndex := _cellG.searchT(token.Id); |
| 689 |
k := _cellG.tKind(tIndex); |
| 690 |
case k of |
| 691 |
CellG.funID, 0: |
| 692 |
begin |
| 693 |
s := _cellG.moduleName; |
| 694 |
t := token.Id; |
| 695 |
if k = 0 then |
| 696 |
begin |
| 697 |
token := _cellG.makeToken; |
| 698 |
if (token.kind <> CellG._Period) and (token.kind <> CellG._Lparen) |
| 699 |
then |
| 700 |
begin |
| 701 |
if token.kind = CellG._Equal then |
| 702 |
begin |
| 703 |
sahen := -1; |
| 704 |
ident := t; |
| 705 |
saIndex := _cellG.nextTIndex; |
| 706 |
saCode := _cellV.genCodeT(CellV.lda, 0); |
| 707 |
end |
| 708 |
else |
| 709 |
_cellG.error('��������������������'); |
| 710 |
Exit; |
| 711 |
end |
| 712 |
else if token.kind = CellG._Period then |
| 713 |
begin |
| 714 |
token := _cellG.makeToken; |
| 715 |
if token.kind <> CellG.Id then |
| 716 |
begin |
| 717 |
_cellG.error('���O������������'); |
| 718 |
Exit; |
| 719 |
end; |
| 720 |
s := t; |
| 721 |
t := token.Id; |
| 722 |
tIndex := _cellG.searchFModule(s, t); |
| 723 |
token := _cellG.makeToken; |
| 724 |
end; |
| 725 |
end |
| 726 |
else |
| 727 |
token := _cellG.makeToken; |
| 728 |
pi := 0; |
| 729 |
ps := 0; |
| 730 |
sa := sahen; |
| 731 |
saI := saIndex; |
| 732 |
saC := saCode; |
| 733 |
token := _cellG.checkGet(token, CellG._Lparen); |
| 734 |
if token.kind <> CellG._Rparen then |
| 735 |
begin |
| 736 |
i := shift; |
| 737 |
shift := 0; |
| 738 |
while true do |
| 739 |
begin |
| 740 |
_expression; |
| 741 |
if shift = 1 then |
| 742 |
inc(pi) |
| 743 |
else |
| 744 |
inc(ps); |
| 745 |
shift := 0; |
| 746 |
if token.kind = CellG._Comma then |
| 747 |
begin |
| 748 |
token := _cellG.makeToken; |
| 749 |
continue; |
| 750 |
end; |
| 751 |
token := _cellG.checkGet(token, CellG._Rparen); |
| 752 |
break; |
| 753 |
end; |
| 754 |
shift := i; |
| 755 |
end |
| 756 |
else |
| 757 |
token := _cellG.makeToken; |
| 758 |
if tIndex = 0 then |
| 759 |
begin |
| 760 |
i := _cellV.genCodeC(0, 0); |
| 761 |
if sa = -1 then |
| 762 |
sa := CellG.intID; |
| 763 |
_cellG.setKariTable(t, s, sa, saI, saC, pi, ps, i); |
| 764 |
sahen := 0; |
| 765 |
Exit; |
| 766 |
end; |
| 767 |
if _cellG.pKazuI(tIndex) <> pi then |
| 768 |
_cellG.error('��������������������(I)'); |
| 769 |
if _cellG.pKazuS(tIndex) <> ps then |
| 770 |
_cellG.error('��������������������(S)'); |
| 771 |
i := _cellG.fModori(tIndex); |
| 772 |
if i = CellG._S then |
| 773 |
checkKata(2) |
| 774 |
else if i = CellG._I then |
| 775 |
checkKata(1) |
| 776 |
else |
| 777 |
checkKata(0); |
| 778 |
p := _cellG.tAddr(tIndex); |
| 779 |
_cellV.genCodeC(p.level, p.addr); |
| 780 |
sahen := 0; |
| 781 |
end; |
| 782 |
else |
| 783 |
sahen := k; |
| 784 |
saIndex := tIndex; |
| 785 |
_Sa; |
| 786 |
i := token.kind; |
| 787 |
if (i = CellG._Plus2) or (i = CellG._Minus2) then |
| 788 |
begin |
| 789 |
sahen := 0; |
| 790 |
token := _cellG.makeToken; |
| 791 |
if (k = CellG.intID) or (k = CellG.parI) or (k = CellG.arrI) then |
| 792 |
begin |
| 793 |
if k = CellG.arrI then |
| 794 |
begin |
| 795 |
if (token.kind = CellG._Rparen) and (forex = true) then |
| 796 |
if i = CellG._Plus2 then |
| 797 |
_cellV.genCodeO(CellV._inc) |
| 798 |
else |
| 799 |
_cellV.genCodeO(CellV._dec) |
| 800 |
else if i = CellG._Plus2 then |
| 801 |
_cellV.genCodeO(CellV.lin) |
| 802 |
else |
| 803 |
_cellV.genCodeO(CellV.lde); |
| 804 |
end |
| 805 |
else |
| 806 |
begin |
| 807 |
if (token.kind <> CellG._Rparen) or (forex = false) then |
| 808 |
_cellV.genCodeT(CellV.lod, tIndex); |
| 809 |
_cellV.genCodeT(CellV.lda, tIndex); |
| 810 |
if i = CellG._Plus2 then |
| 811 |
_cellV.genCodeO(CellV.lin) |
| 812 |
else |
| 813 |
_cellV.genCodeO(CellV.lde); |
| 814 |
end; |
| 815 |
end |
| 816 |
else |
| 817 |
_cellG.error('�^����������������'); |
| 818 |
end; |
| 819 |
end; |
| 820 |
end |
| 821 |
else |
| 822 |
_cellG.error('����������������������'); |
| 823 |
end; |
| 824 |
|
| 825 |
function TCellK.hairetu(const ti: integer): Boolean; |
| 826 |
var |
| 827 |
i, j, sa: integer; |
| 828 |
begin |
| 829 |
sa := sahen; |
| 830 |
token := _cellG.checkGet(_cellG.makeToken, CellG._Lbracket); |
| 831 |
_expression; |
| 832 |
if token.kind = CellG._Rbracket then |
| 833 |
begin |
| 834 |
token := _cellG.makeToken; |
| 835 |
i := 1; |
| 836 |
j := CellV.adv; |
| 837 |
end |
| 838 |
else if token.kind = CellG._Ex then |
| 839 |
begin |
| 840 |
token := _cellG.makeToken; |
| 841 |
_expression; |
| 842 |
token := _cellG.checkGet(token, CellG._Rbracket); |
| 843 |
i := 2; |
| 844 |
j := CellV.arr; |
| 845 |
end |
| 846 |
else |
| 847 |
begin |
| 848 |
_cellG.error(']or! ������������'); |
| 849 |
shift := 0; |
| 850 |
result := false; |
| 851 |
Exit; |
| 852 |
end; |
| 853 |
sahen := sa; |
| 854 |
_cellV.genCodeA(j, _cellG.hairetu(ti)); |
| 855 |
if _cellG.jigen(ti) <> i then |
| 856 |
begin |
| 857 |
_cellG.error('�z�������������v��������'); |
| 858 |
result := false; |
| 859 |
end |
| 860 |
else |
| 861 |
result := true; |
| 862 |
end; |
| 863 |
|
| 864 |
procedure TCellK._expression1; |
| 865 |
var |
| 866 |
k, s: integer; |
| 867 |
begin |
| 868 |
_expression2; |
| 869 |
k := token.kind; |
| 870 |
if (k <> CellG._Equal2) and (k <> CellG._NotEq) and (k <> CellG._Lss) and |
| 871 |
(k <> CellG._Gtr) and (k <> CellG._LssEq) and (k <> CellG._GtrEq) then |
| 872 |
Exit; |
| 873 |
sahen := 0; |
| 874 |
s := shift; |
| 875 |
shift := 0; |
| 876 |
token := _cellG.makeToken; |
| 877 |
_expression2; |
| 878 |
if s <> shift then |
| 879 |
_cellG.error('���r�����������^�����v���������B'); |
| 880 |
if (s = 2) and ((k <> CellG._Equal2) or (k <> CellG._NotEq)) then |
| 881 |
begin |
| 882 |
_cellG.error('�������������r�������������B'); |
| 883 |
Exit; |
| 884 |
end; |
| 885 |
case k of |
| 886 |
CellG._Equal2: |
| 887 |
if s = 2 then |
| 888 |
_cellV.genCodeO(CellV.eqs) |
| 889 |
else |
| 890 |
_cellV.genCodeO(CellV.eql); |
| 891 |
CellG._NotEq: |
| 892 |
if s = 2 then |
| 893 |
_cellV.genCodeO(CellV.nes) |
| 894 |
else |
| 895 |
_cellV.genCodeO(CellV.neq); |
| 896 |
CellG._Lss: |
| 897 |
_cellV.genCodeO(CellV.lss); |
| 898 |
CellG._Gtr: |
| 899 |
_cellV.genCodeO(CellV.gtr); |
| 900 |
CellG._LssEq: |
| 901 |
_cellV.genCodeO(CellV.leq); |
| 902 |
CellG._GtrEq: |
| 903 |
_cellV.genCodeO(CellV.geq); |
| 904 |
end; |
| 905 |
con := true; |
| 906 |
end; |
| 907 |
|
| 908 |
procedure TCellK._expression2; |
| 909 |
var |
| 910 |
k: integer; |
| 911 |
begin |
| 912 |
_term; |
| 913 |
k := token.kind; |
| 914 |
while (token.kind = CellG._Plus) or (token.kind = CellG._Minus) do |
| 915 |
begin |
| 916 |
token := _cellG.makeToken; |
| 917 |
_term; |
| 918 |
if shift = 1 then |
| 919 |
if k = CellG._Plus then |
| 920 |
_cellV.genCodeO(CellV._add) |
| 921 |
else |
| 922 |
_cellV.genCodeO(CellV._sub) |
| 923 |
else if k = CellG._Plus then |
| 924 |
_cellV.genCodeO(CellV.ads) |
| 925 |
else |
| 926 |
_cellV.genCodeO(CellV.sus); |
| 927 |
end; |
| 928 |
end; |
| 929 |
|
| 930 |
procedure TCellK.checkKata(t: integer); |
| 931 |
begin |
| 932 |
if shift = 0 then |
| 933 |
shift := t |
| 934 |
else if t <> shift then |
| 935 |
_cellG.error('�^�����v���������B'); |
| 936 |
end; |
| 937 |
|
| 938 |
procedure TCellK._Sa; |
| 939 |
begin |
| 940 |
case sahen of |
| 941 |
CellG.intID, CellG.parI: |
| 942 |
begin |
| 943 |
checkKata(1); |
| 944 |
token := _cellG.makeToken; |
| 945 |
if token.kind = CellG._Equal then |
| 946 |
saCode := _cellV.genCodeT(CellV.lda, saIndex) |
| 947 |
else if (token.kind <> CellG._Plus2) and (token.kind <> CellG._Minus2) |
| 948 |
then |
| 949 |
_cellV.genCodeT(CellV.lod, saIndex); |
| 950 |
end; |
| 951 |
CellG.strID, CellG.parS: |
| 952 |
begin |
| 953 |
checkKata(2); |
| 954 |
token := _cellG.makeToken; |
| 955 |
if token.kind = CellG._Equal then |
| 956 |
saCode := _cellV.genCodeT(CellV.las, saIndex) |
| 957 |
else if (token.kind <> CellG._Plus2) or (token.kind <> CellG._Minus2) |
| 958 |
then |
| 959 |
_cellV.genCodeT(CellV.los, saIndex); |
| 960 |
end; |
| 961 |
CellG.arrI: |
| 962 |
begin |
| 963 |
checkKata(1); |
| 964 |
_cellV.genCodeT(CellV.lda, saIndex); |
| 965 |
if hairetu(saIndex) = true then |
| 966 |
if (token.kind <> CellG._Equal2) and (token.kind <> CellG._Plus2) and |
| 967 |
(token.kind <> CellG._Minus2) then |
| 968 |
_cellV.genCodeO(CellV.lod); |
| 969 |
shift := 1; |
| 970 |
end; |
| 971 |
CellG.arrS: |
| 972 |
begin |
| 973 |
checkKata(2); |
| 974 |
_cellV.genCodeT(CellV.lda, saIndex); |
| 975 |
if hairetu(saIndex) = true then |
| 976 |
if (token.kind <> CellG._Equal2) and (token.kind <> CellG._Plus2) and |
| 977 |
(token.kind <> CellG._Minus2) then |
| 978 |
_cellV.genCodeO(CellV.lds); |
| 979 |
shift := 2; |
| 980 |
end; |
| 981 |
end; |
| 982 |
end; |
| 983 |
|
| 984 |
procedure TCellK.shokika; |
| 985 |
begin |
| 986 |
con := false; |
| 987 |
saIndex := 0; |
| 988 |
saCode := 0; |
| 989 |
breCode := 0; |
| 990 |
retIS := false; |
| 991 |
loop := false; |
| 992 |
shift := 0; |
| 993 |
sahen := -1; |
| 994 |
ident := ''; |
| 995 |
forex := false; |
| 996 |
end; |
| 997 |
|
| 998 |
end. |