| 1 |
unit CellG; |
| 2 |
|
| 3 |
interface |
| 4 |
|
| 5 |
uses |
| 6 |
SysUtils; |
| 7 |
|
| 8 |
const |
| 9 |
_aI = 1; |
| 10 |
_aS = 2; |
| 11 |
_Read = 3; |
| 12 |
_Print = 4; |
| 13 |
_Println = 5; |
| 14 |
_If = 6; |
| 15 |
_Else = 7; |
| 16 |
_For = 8; |
| 17 |
_While = 9; |
| 18 |
_Do = 10; |
| 19 |
_I = 11; |
| 20 |
_S = 12; |
| 21 |
_V = 13; |
| 22 |
_Return = 14; |
| 23 |
_Break = 15; |
| 24 |
_ReadS = 16; |
| 25 |
_end_KeyWd = 17; |
| 26 |
|
| 27 |
_Plus = 18; |
| 28 |
_Plus2 = 19; |
| 29 |
_Minus = 20; |
| 30 |
_Minus2 = 21; |
| 31 |
_Mult = 22; |
| 32 |
_Div = 23; |
| 33 |
_Equal = 24; |
| 34 |
_Comma = 25; |
| 35 |
_Semicolon = 26; |
| 36 |
_Lparen = 27; |
| 37 |
_Rparen = 28; |
| 38 |
_Lbrace = 29; |
| 39 |
_Rbrace = 30; |
| 40 |
_Lbracket = 31; |
| 41 |
_Rbracket = 32; |
| 42 |
_Equal2 = 33; |
| 43 |
_Lss = 34; |
| 44 |
_Gtr = 35; |
| 45 |
_LssEq = 36; |
| 46 |
_GtrEq = 37; |
| 47 |
_NotEq = 38; |
| 48 |
_Ex = 39; |
| 49 |
_DQ = 40; |
| 50 |
_Period = 41; |
| 51 |
_end_Sym = 42; |
| 52 |
|
| 53 |
intID = 41; |
| 54 |
arrI = 42; |
| 55 |
arrS = 43; |
| 56 |
funID = 44; |
| 57 |
parI = 45; |
| 58 |
strID = 46; |
| 59 |
parS = 47; |
| 60 |
|
| 61 |
Id = 51; |
| 62 |
Num = 52; |
| 63 |
Moji = 53; |
| 64 |
nul = 54; |
| 65 |
end_Token = 55; |
| 66 |
|
| 67 |
others = 61; |
| 68 |
digit = 62; |
| 69 |
letter = 63; |
| 70 |
space = 64; |
| 71 |
tab = 65; |
| 72 |
cr1 = 66; |
| 73 |
dollar = 67; |
| 74 |
at = 68; |
| 75 |
|
| 76 |
MaxName = 20; |
| 77 |
MaxTable = 200; |
| 78 |
MaxModule = 50; |
| 79 |
MaxLevel = 20; |
| 80 |
firstAddr = 3; |
| 81 |
|
| 82 |
type |
| 83 |
TcClass = record |
| 84 |
small: Char; |
| 85 |
big: Char; |
| 86 |
result: integer; |
| 87 |
end; |
| 88 |
|
| 89 |
TToken = class |
| 90 |
public |
| 91 |
kind: integer; |
| 92 |
Id: string; |
| 93 |
value: integer; |
| 94 |
end; |
| 95 |
|
| 96 |
TRaddr = record |
| 97 |
level: integer; |
| 98 |
addr: integer; |
| 99 |
end; |
| 100 |
|
| 101 |
TModule = class |
| 102 |
public |
| 103 |
name: string; |
| 104 |
index: integer; |
| 105 |
number: integer; |
| 106 |
constructor Create(n: string; i, s: integer); overload; |
| 107 |
constructor Create(n: string); overload; |
| 108 |
end; |
| 109 |
|
| 110 |
TTable = class |
| 111 |
public |
| 112 |
name: string; |
| 113 |
kind: integer; |
| 114 |
Raddr: TRaddr; |
| 115 |
constructor Create(const Id: string; const k, l, a: integer); overload; |
| 116 |
constructor Create(const Id: string); overload; |
| 117 |
function toString: string; virtual; |
| 118 |
end; |
| 119 |
|
| 120 |
TTableArray = class(TTable) |
| 121 |
public |
| 122 |
jigen: integer; |
| 123 |
gyou: integer; |
| 124 |
retu: integer; |
| 125 |
constructor Create(const Id: string; const k, l, a, j, g, r: integer); |
| 126 |
function toString: string; override; |
| 127 |
end; |
| 128 |
|
| 129 |
TTableFunc = class(TTable) |
| 130 |
public |
| 131 |
modori: integer; |
| 132 |
parIs: integer; |
| 133 |
parSs: integer; |
| 134 |
constructor Create(const Id: string; const k, l, a, m, pi, ps: integer); |
| 135 |
function toString: string; override; |
| 136 |
end; |
| 137 |
|
| 138 |
TKari = class |
| 139 |
public |
| 140 |
name: string; |
| 141 |
md: string; |
| 142 |
sahen: integer; |
| 143 |
tI: integer; |
| 144 |
lcI: integer; |
| 145 |
scI: integer; |
| 146 |
pi: integer; |
| 147 |
ps: integer; |
| 148 |
cI: integer; |
| 149 |
tf: Boolean; |
| 150 |
constructor Create(n, m: string; s, t, lc, sc, pi, ps, c: integer; |
| 151 |
f: Boolean); |
| 152 |
end; |
| 153 |
|
| 154 |
TCellG = class |
| 155 |
private |
| 156 |
nameTable: array [0 .. MaxTable] of TTable; |
| 157 |
funcTable: array [0 .. MaxTable div 2] of TTable; |
| 158 |
moduleTable: array [0 .. MaxModule] of TModule; |
| 159 |
kariTable: array [0 .. MaxTable div 4] of TKari; |
| 160 |
tIndex: integer; |
| 161 |
fIndex: integer; |
| 162 |
tfIndex: integer; |
| 163 |
mIndex: integer; |
| 164 |
kIndex: integer; |
| 165 |
kan: integer; |
| 166 |
localAddr: integer; |
| 167 |
slocalAddr: integer; |
| 168 |
level: integer; |
| 169 |
index: array [0 .. MaxLevel] of integer; |
| 170 |
addr: array [0 .. MaxLevel] of integer; |
| 171 |
saddr: array [0 .. MaxLevel] of integer; |
| 172 |
BufferedReader: TextFile; |
| 173 |
c: Char; |
| 174 |
line: string; |
| 175 |
lineIndex: integer; |
| 176 |
errorLine: string; |
| 177 |
cr: integer; |
| 178 |
lastT: TToken; |
| 179 |
mojiretu: string; |
| 180 |
key: array [0 .. _end_Sym] of string; |
| 181 |
public |
| 182 |
pTable: Boolean; |
| 183 |
e: integer; |
| 184 |
exe: integer; |
| 185 |
constructor Create(p: Boolean); |
| 186 |
destructor Destroy; override; |
| 187 |
function open(const f: TFileName; cellV: TObject): Boolean; |
| 188 |
procedure closeFile; |
| 189 |
procedure blockBegin; |
| 190 |
procedure blockEnd; |
| 191 |
procedure setTable(t: TTable); |
| 192 |
procedure setModule(Id: string); |
| 193 |
procedure setKariTable(Id, m: string; s, tI, lc, pi, ps, c: integer); |
| 194 |
procedure setScI(c: integer); |
| 195 |
function moduleName: string; |
| 196 |
function tableInt(const Id: string): integer; |
| 197 |
procedure initKey; |
| 198 |
procedure setFunc(t: TTable); |
| 199 |
function tablePstr(Id: string): integer; |
| 200 |
function tableString(Id: string): integer; |
| 201 |
function tableA1int(const Id: string; const n: integer): integer; |
| 202 |
function tableA2int(const Id: string; const x, v: integer): integer; |
| 203 |
function tableA1str(Id: string; n: integer): integer; |
| 204 |
function tableA2str(Id: string; x, v: integer): integer; |
| 205 |
function tableFunc(const Id: string; const c, mm: integer): integer; |
| 206 |
function tablePint(const Id: string): integer; |
| 207 |
procedure endPar; |
| 208 |
procedure changeT(t, k: integer; x: Boolean); |
| 209 |
function searchT(const Id: string): integer; |
| 210 |
function searchF(const Id: string; m: integer): integer; |
| 211 |
function searchFModule(m, Id: string): integer; |
| 212 |
procedure checkKari(Id: string); |
| 213 |
procedure checkKan; |
| 214 |
function tAddr(const n: integer): TRaddr; |
| 215 |
function bLevel: integer; |
| 216 |
function funcParIs: integer; |
| 217 |
function funcParSs: integer; |
| 218 |
function fModori(n: integer): integer; |
| 219 |
function funcModori: integer; |
| 220 |
function pKazuI(const n: integer): integer; |
| 221 |
function pKazuS(n: integer): integer; |
| 222 |
function tKind(const n: integer): integer; |
| 223 |
function hairetu(const n: integer): TRaddr; |
| 224 |
function numAddr: integer; |
| 225 |
function snumAddr: integer; |
| 226 |
function nextTIndex: integer; |
| 227 |
function checkGet(t: TToken; const k: integer): TToken; |
| 228 |
function jigen(const i: integer): integer; |
| 229 |
function checkIn(const n: string): Boolean; |
| 230 |
procedure error(const er: string); |
| 231 |
procedure shokika; |
| 232 |
function nextChar: Char; |
| 233 |
function makeToken: TToken; |
| 234 |
function cClass(c: Char): integer; |
| 235 |
end; |
| 236 |
|
| 237 |
function hyouji(const k: integer): string; |
| 238 |
|
| 239 |
const |
| 240 |
fClass: array [0 .. 25] of TcClass = ((small: #$09; big: #$09; result: tab), |
| 241 |
(small: #13; big: #13; result: cr1), (small: ' '; big: ' '; result: space), |
| 242 |
(small: '!'; big: '!'; result: _Ex), (small: '"'; big: '"'; result: _DQ), |
| 243 |
(small: '$'; big: '$'; result: dollar), (small: '('; big: '('; |
| 244 |
result: _Lparen), (small: ')'; big: ')'; result: _Rparen), (small: '*'; |
| 245 |
big: '*'; result: _Mult), (small: '+'; big: '+'; result: _Plus), |
| 246 |
(small: ','; big: ','; result: _Comma), (small: '-'; big: '-'; |
| 247 |
result: _Minus), (small: '.'; big: '.'; result: _Period), (small: '/'; |
| 248 |
big: '/'; result: _Div), (small: '0'; big: '9'; result: digit), (small: ';'; |
| 249 |
big: ';'; result: _Semicolon), (small: '<'; big: '<'; result: _Lss), |
| 250 |
(small: '='; big: '='; result: _Equal), (small: '>'; big: '>'; |
| 251 |
result: _Gtr), (small: '@'; big: '@'; result: at), (small: 'A'; big: 'Z'; |
| 252 |
result: letter), (small: '['; big: '['; result: _Lbracket), (small: ']'; |
| 253 |
big: ']'; result: _Rbracket), (small: 'a'; big: 'z'; result: letter), |
| 254 |
(small: '{'; big: '{'; result: _Lbrace), (small: '}'; big: '}'; |
| 255 |
result: _Rbrace)); |
| 256 |
|
| 257 |
implementation |
| 258 |
|
| 259 |
uses cellV; |
| 260 |
|
| 261 |
const |
| 262 |
MaxMoji = 200; |
| 263 |
|
| 264 |
var |
| 265 |
_cellV: TCellV; |
| 266 |
|
| 267 |
function hyouji(const k: integer): string; |
| 268 |
begin |
| 269 |
case k of |
| 270 |
intID: |
| 271 |
result := 'intID'; |
| 272 |
strID: |
| 273 |
result := 'strID'; |
| 274 |
arrI: |
| 275 |
result := 'arrI'; |
| 276 |
funID: |
| 277 |
result := 'funID'; |
| 278 |
parI: |
| 279 |
result := 'parI'; |
| 280 |
parS: |
| 281 |
result := 'parS'; |
| 282 |
_I: |
| 283 |
result := 'I'; |
| 284 |
_S: |
| 285 |
result := 'S'; |
| 286 |
_V: |
| 287 |
result := 'V'; |
| 288 |
else |
| 289 |
result := IntToStr(k); |
| 290 |
end; |
| 291 |
end; |
| 292 |
|
| 293 |
{ TTable } |
| 294 |
|
| 295 |
constructor TTable.Create(const Id: string; const k, l, a: integer); |
| 296 |
begin |
| 297 |
inherited Create; |
| 298 |
name := Id; |
| 299 |
kind := k; |
| 300 |
Raddr.level := l; |
| 301 |
Raddr.addr := a; |
| 302 |
end; |
| 303 |
|
| 304 |
constructor TTable.Create(const Id: string); |
| 305 |
begin |
| 306 |
inherited Create; |
| 307 |
name := Id; |
| 308 |
end; |
| 309 |
|
| 310 |
function TTable.toString: string; |
| 311 |
begin |
| 312 |
result := name + ' : ' + hyouji(kind) + ' : ' + IntToStr(Raddr.level) + |
| 313 |
IntToStr(Raddr.addr); |
| 314 |
end; |
| 315 |
|
| 316 |
{ TTableArray } |
| 317 |
|
| 318 |
constructor TTableArray.Create(const Id: string; |
| 319 |
const k, l, a, j, g, r: integer); |
| 320 |
begin |
| 321 |
inherited Create(Id, k, l, a); |
| 322 |
jigen := j; |
| 323 |
gyou := g; |
| 324 |
retu := r; |
| 325 |
end; |
| 326 |
|
| 327 |
function TTableArray.toString: string; |
| 328 |
begin |
| 329 |
result := inherited toString + ' : ' + IntToStr(jigen) + '����: ' + |
| 330 |
IntToStr(gyou) + IntToStr(retu) + '��'; |
| 331 |
end; |
| 332 |
|
| 333 |
{ TCellG } |
| 334 |
|
| 335 |
function TCellG.bLevel: integer; |
| 336 |
begin |
| 337 |
result := level; |
| 338 |
end; |
| 339 |
|
| 340 |
procedure TCellG.blockBegin; |
| 341 |
begin |
| 342 |
if level = -1 then |
| 343 |
begin |
| 344 |
localAddr := firstAddr; |
| 345 |
slocalAddr := 0; |
| 346 |
tIndex := 0; |
| 347 |
inc(level); |
| 348 |
end |
| 349 |
else if level = MaxLevel - 1 then |
| 350 |
error('�u���b�N���[��������') |
| 351 |
else |
| 352 |
begin |
| 353 |
index[level] := tIndex; |
| 354 |
addr[level] := localAddr; |
| 355 |
saddr[level] := slocalAddr; |
| 356 |
localAddr := firstAddr; |
| 357 |
slocalAddr := 0; |
| 358 |
inc(level); |
| 359 |
end; |
| 360 |
end; |
| 361 |
|
| 362 |
procedure TCellG.blockEnd; |
| 363 |
var |
| 364 |
i, j: integer; |
| 365 |
begin |
| 366 |
if pTable = true then |
| 367 |
begin |
| 368 |
Writeln('--level : ' + IntToStr(level) + '--'); |
| 369 |
if level = 0 then |
| 370 |
i := 1 |
| 371 |
else |
| 372 |
i := index[level - 1] + 1; |
| 373 |
for j := i to tIndex do |
| 374 |
Writeln(nameTable[j].toString); |
| 375 |
for j := tfIndex to fIndex do |
| 376 |
begin |
| 377 |
if fIndex = 0 then |
| 378 |
break; |
| 379 |
Writeln(funcTable[j].toString); |
| 380 |
end; |
| 381 |
Writeln; |
| 382 |
end; |
| 383 |
if level = 0 then |
| 384 |
dec(level) |
| 385 |
else |
| 386 |
begin |
| 387 |
dec(level); |
| 388 |
for i := index[level] + 1 to tIndex do |
| 389 |
nameTable[i].Free; |
| 390 |
tIndex := index[level]; |
| 391 |
localAddr := addr[level]; |
| 392 |
slocalAddr := saddr[level]; |
| 393 |
end; |
| 394 |
end; |
| 395 |
|
| 396 |
function TCellG.checkGet(t: TToken; const k: integer): TToken; |
| 397 |
begin |
| 398 |
if t.kind <> k then |
| 399 |
begin |
| 400 |
error('��������������-' + key[k]); |
| 401 |
result := t; |
| 402 |
end |
| 403 |
else |
| 404 |
result := makeToken; |
| 405 |
end; |
| 406 |
|
| 407 |
function TCellG.checkIn(const n: string): Boolean; |
| 408 |
var |
| 409 |
i, j: integer; |
| 410 |
begin |
| 411 |
if Length(n) = 0 then |
| 412 |
result := true |
| 413 |
else |
| 414 |
begin |
| 415 |
result := false; |
| 416 |
for i := 1 to Length(n) do |
| 417 |
begin |
| 418 |
j := cClass(n[i]); |
| 419 |
if j <> digit then |
| 420 |
begin |
| 421 |
result := true; |
| 422 |
break; |
| 423 |
end; |
| 424 |
end; |
| 425 |
end; |
| 426 |
end; |
| 427 |
|
| 428 |
procedure TCellG.closeFile; |
| 429 |
begin |
| 430 |
try |
| 431 |
System.closeFile(BufferedReader); |
| 432 |
except |
| 433 |
on EInOutError do |
| 434 |
Writeln('�t�@�C������������������'); |
| 435 |
end; |
| 436 |
end; |
| 437 |
|
| 438 |
constructor TCellG.Create(p: Boolean); |
| 439 |
begin |
| 440 |
inherited Create; |
| 441 |
pTable := p; |
| 442 |
lastT := TToken.Create; |
| 443 |
initKey; |
| 444 |
shokika; |
| 445 |
end; |
| 446 |
|
| 447 |
destructor TCellG.Destroy; |
| 448 |
begin |
| 449 |
lastT.Free; |
| 450 |
nameTable[0].Free; |
| 451 |
moduleTable[0].Free; |
| 452 |
inherited; |
| 453 |
end; |
| 454 |
|
| 455 |
procedure TCellG.endPar; |
| 456 |
var |
| 457 |
i, pi, ps: integer; |
| 458 |
begin |
| 459 |
with funcTable[tfIndex] as TTableFunc do |
| 460 |
begin |
| 461 |
pi := parIs; |
| 462 |
ps := parSs; |
| 463 |
end; |
| 464 |
if (pi = 0) and (ps = 0) then |
| 465 |
Exit; |
| 466 |
for i := tfIndex + 1 to tfIndex + pi + ps do |
| 467 |
begin |
| 468 |
if funcTable[i].kind = parI then |
| 469 |
begin |
| 470 |
funcTable[i].Raddr.addr := -pi; |
| 471 |
dec(pi); |
| 472 |
end |
| 473 |
else |
| 474 |
begin |
| 475 |
funcTable[i].Raddr.addr := -ps; |
| 476 |
dec(ps); |
| 477 |
end; |
| 478 |
end; |
| 479 |
end; |
| 480 |
|
| 481 |
procedure TCellG.error(const er: string); |
| 482 |
begin |
| 483 |
inc(e); |
| 484 |
Writeln(IntToStr(cr) + ' : ' + errorLine + ' : ' + er + '�B'); |
| 485 |
errorLine := ''; |
| 486 |
end; |
| 487 |
|
| 488 |
function TCellG.fModori(n: integer): integer; |
| 489 |
begin |
| 490 |
result := (funcTable[n - tIndex] as TTableFunc).modori; |
| 491 |
end; |
| 492 |
|
| 493 |
function TCellG.funcParIs: integer; |
| 494 |
begin |
| 495 |
result := (funcTable[tfIndex] as TTableFunc).parIs; |
| 496 |
end; |
| 497 |
|
| 498 |
function TCellG.hairetu(const n: integer): TRaddr; |
| 499 |
begin |
| 500 |
with nameTable[n] as TTableArray do |
| 501 |
begin |
| 502 |
result.level := gyou; |
| 503 |
result.addr := retu; |
| 504 |
end; |
| 505 |
end; |
| 506 |
|
| 507 |
procedure TCellG.initKey; |
| 508 |
begin |
| 509 |
key[_aI] := 'aI'; |
| 510 |
key[_Print] := 'print'; |
| 511 |
key[_Println] := 'println'; |
| 512 |
key[_Read] := 'read'; |
| 513 |
key[_ReadS] := 'reads'; |
| 514 |
key[_If] := 'if'; |
| 515 |
key[_Else] := 'else'; |
| 516 |
key[_For] := 'for'; |
| 517 |
key[_While] := 'while'; |
| 518 |
key[_Do] := 'do'; |
| 519 |
key[_I] := 'i'; |
| 520 |
key[_S] := 's'; |
| 521 |
key[_V] := 'v'; |
| 522 |
key[_Return] := 'return'; |
| 523 |
key[_Break] := 'break'; |
| 524 |
key[_end_KeyWd] := 'dummy1'; |
| 525 |
key[_Plus] := '+'; |
| 526 |
key[_Minus] := '-'; |
| 527 |
key[_Mult] := '*'; |
| 528 |
key[_Equal] := '='; |
| 529 |
key[_Comma] := ','; |
| 530 |
key[_Semicolon] := ':'; |
| 531 |
key[_Lparen] := '('; |
| 532 |
key[_Rparen] := ')'; |
| 533 |
key[_Lbrace] := '{'; |
| 534 |
key[_Rbrace] := '}'; |
| 535 |
key[_Lbracket] := '['; |
| 536 |
key[_Rbracket] := ']'; |
| 537 |
key[_Lss] := '<'; |
| 538 |
key[_Gtr] := '>'; |
| 539 |
key[_LssEq] := '<='; |
| 540 |
key[_GtrEq] := '>='; |
| 541 |
key[_NotEq] := '!='; |
| 542 |
key[_Ex] := '!'; |
| 543 |
key[_end_Sym] := 'dummy2'; |
| 544 |
end; |
| 545 |
|
| 546 |
function TCellG.jigen(const i: integer): integer; |
| 547 |
begin |
| 548 |
result := TTableArray(nameTable[i]).jigen; |
| 549 |
end; |
| 550 |
|
| 551 |
function TCellG.makeToken: TToken; |
| 552 |
var |
| 553 |
i: integer; |
| 554 |
cc, k: integer; |
| 555 |
Num: integer; |
| 556 |
temp: TToken; |
| 557 |
Id: string; |
| 558 |
begin |
| 559 |
temp := TToken.Create; |
| 560 |
while true do |
| 561 |
begin |
| 562 |
k := lastT.kind; |
| 563 |
if k <> nul then |
| 564 |
begin |
| 565 |
if k < _end_Sym then |
| 566 |
errorLine := errorLine + key[lastT.kind] |
| 567 |
else if k = CellG.Num then |
| 568 |
errorLine := errorLine + IntToStr(lastT.value) |
| 569 |
else if k = CellG.Id then |
| 570 |
errorLine := errorLine + lastT.Id; |
| 571 |
end; |
| 572 |
cc := cClass(c); |
| 573 |
while (cc = space) or (cc = cr1) or (cc = tab) do |
| 574 |
begin |
| 575 |
if (cc = space) or (cc = tab) then |
| 576 |
errorLine := errorLine + c; |
| 577 |
if cc = cr1 then |
| 578 |
begin |
| 579 |
inc(cr); |
| 580 |
errorLine := ''; |
| 581 |
end; |
| 582 |
c := nextChar; |
| 583 |
cc := cClass(c); |
| 584 |
end; |
| 585 |
case cc of |
| 586 |
digit: |
| 587 |
begin |
| 588 |
Num := 0; |
| 589 |
while cc = digit do |
| 590 |
begin |
| 591 |
Num := 10 * Num + StrToInt(c); |
| 592 |
c := nextChar; |
| 593 |
cc := cClass(c); |
| 594 |
end; |
| 595 |
temp.kind := CellG.Num; |
| 596 |
temp.value := Num; |
| 597 |
break; |
| 598 |
end; |
| 599 |
letter, others: |
| 600 |
begin |
| 601 |
Id := ''; |
| 602 |
while (cc = letter) or (cc = digit) or (cc = others) do |
| 603 |
begin |
| 604 |
if Length(Id) < MaxName then |
| 605 |
Id := Id + c; |
| 606 |
c := nextChar; |
| 607 |
cc := cClass(c); |
| 608 |
end; |
| 609 |
if Length(Id) >= MaxName then |
| 610 |
error('���O������������'); |
| 611 |
for i := 0 to _end_KeyWd do |
| 612 |
if CompareText(Id, key[i]) = 0 then |
| 613 |
begin |
| 614 |
temp.kind := i; |
| 615 |
temp.Id := Id; |
| 616 |
lastT.Free; |
| 617 |
lastT := temp; |
| 618 |
result := temp; |
| 619 |
Exit; |
| 620 |
end; |
| 621 |
temp.kind := CellG.Id; |
| 622 |
temp.Id := Id; |
| 623 |
break; |
| 624 |
end; |
| 625 |
_Equal: |
| 626 |
begin |
| 627 |
c := nextChar; |
| 628 |
if c = '=' then |
| 629 |
begin |
| 630 |
temp.kind := _Equal2; |
| 631 |
c := nextChar; |
| 632 |
end |
| 633 |
else |
| 634 |
temp.kind := _Equal; |
| 635 |
break; |
| 636 |
end; |
| 637 |
_Ex: |
| 638 |
begin |
| 639 |
c := nextChar; |
| 640 |
if c = '=' then |
| 641 |
begin |
| 642 |
temp.kind := _NotEq; |
| 643 |
c := nextChar; |
| 644 |
end |
| 645 |
else |
| 646 |
temp.kind := _Ex; |
| 647 |
break; |
| 648 |
end; |
| 649 |
_Lss: |
| 650 |
begin |
| 651 |
c := nextChar; |
| 652 |
if c = '=' then |
| 653 |
begin |
| 654 |
temp.kind := _LssEq; |
| 655 |
c := nextChar; |
| 656 |
end |
| 657 |
else |
| 658 |
temp.kind := _Lss; |
| 659 |
break; |
| 660 |
end; |
| 661 |
_Gtr: |
| 662 |
begin |
| 663 |
c := nextChar; |
| 664 |
if c = '=' then |
| 665 |
begin |
| 666 |
temp.kind := _GtrEq; |
| 667 |
c := nextChar; |
| 668 |
end |
| 669 |
else |
| 670 |
temp.kind := _Gtr; |
| 671 |
break; |
| 672 |
end; |
| 673 |
_Plus: |
| 674 |
begin |
| 675 |
c := nextChar; |
| 676 |
if c = '+' then |
| 677 |
begin |
| 678 |
temp.kind := _Plus2; |
| 679 |
c := nextChar; |
| 680 |
end |
| 681 |
else |
| 682 |
temp.kind := _Plus; |
| 683 |
break; |
| 684 |
end; |
| 685 |
_Minus: |
| 686 |
begin |
| 687 |
c := nextChar; |
| 688 |
if c = '-' then |
| 689 |
begin |
| 690 |
temp.kind := _Minus2; |
| 691 |
c := nextChar; |
| 692 |
end |
| 693 |
else |
| 694 |
temp.kind := _Minus; |
| 695 |
break; |
| 696 |
end; |
| 697 |
at: |
| 698 |
begin |
| 699 |
c := nextChar; |
| 700 |
cc := cClass(c); |
| 701 |
while cc <> at do |
| 702 |
begin |
| 703 |
errorLine := errorLine + c; |
| 704 |
c := nextChar; |
| 705 |
cc := cClass(c); |
| 706 |
end; |
| 707 |
c := nextChar; |
| 708 |
continue; |
| 709 |
end; |
| 710 |
_DQ: |
| 711 |
begin |
| 712 |
i := 1; |
| 713 |
mojiretu := ''; |
| 714 |
repeat |
| 715 |
if i < MaxMoji then |
| 716 |
mojiretu := mojiretu + c; |
| 717 |
inc(i); |
| 718 |
c := nextChar; |
| 719 |
cc := cClass(c); |
| 720 |
until (cc = _DQ) or (cc = _Rbrace) or (cc = _Semicolon); |
| 721 |
if (cc = _Rbrace) or (cc = _Semicolon) then |
| 722 |
begin |
| 723 |
error('"�������������B'); |
| 724 |
temp.kind := cc; |
| 725 |
lastT := temp; |
| 726 |
result := temp; |
| 727 |
Exit; |
| 728 |
end; |
| 729 |
if i >= MaxMoji then |
| 730 |
begin |
| 731 |
error('����������������'); |
| 732 |
i := MaxName - 1; |
| 733 |
end; |
| 734 |
mojiretu := mojiretu + '"'; |
| 735 |
temp.kind := Moji; |
| 736 |
temp.Id := Copy(mojiretu, 2, i - 2); |
| 737 |
c := nextChar; |
| 738 |
break; |
| 739 |
end; |
| 740 |
dollar: |
| 741 |
begin |
| 742 |
checkKan; |
| 743 |
temp.kind := dollar; |
| 744 |
break; |
| 745 |
end; |
| 746 |
else |
| 747 |
temp.kind := cc; |
| 748 |
c := nextChar; |
| 749 |
break; |
| 750 |
end; |
| 751 |
end; |
| 752 |
lastT.Free; |
| 753 |
lastT := temp; |
| 754 |
result := temp; |
| 755 |
end; |
| 756 |
|
| 757 |
function TCellG.nextChar: Char; |
| 758 |
begin |
| 759 |
if lineIndex > Length(line) then |
| 760 |
begin |
| 761 |
if Eof(BufferedReader) = true then |
| 762 |
begin |
| 763 |
Writeln(IntToStr(cr) + ':�t�@�C���I���A$�������������B' + IntToStr(e), |
| 764 |
'�G���[����:' + IntToStr(e + 1)); |
| 765 |
System.closeFile(BufferedReader); |
| 766 |
raise EInOutError.Create('error'); |
| 767 |
end; |
| 768 |
lineIndex := 1; |
| 769 |
try |
| 770 |
Readln(BufferedReader, line); |
| 771 |
except |
| 772 |
Writeln(IntToStr(cr) + '�����s�����������������B' + ' : ' + IntToStr(e), |
| 773 |
'�G���[����:' + IntToStr(e + 1)); |
| 774 |
raise; |
| 775 |
end; |
| 776 |
result := #13; |
| 777 |
end |
| 778 |
else |
| 779 |
begin |
| 780 |
result := line[lineIndex]; |
| 781 |
inc(lineIndex); |
| 782 |
end; |
| 783 |
end; |
| 784 |
|
| 785 |
function TCellG.numAddr: integer; |
| 786 |
begin |
| 787 |
result := localAddr; |
| 788 |
end; |
| 789 |
|
| 790 |
function TCellG.snumAddr: integer; |
| 791 |
begin |
| 792 |
result := slocalAddr; |
| 793 |
end; |
| 794 |
|
| 795 |
function TCellG.open(const f: TFileName; cellV: TObject): Boolean; |
| 796 |
begin |
| 797 |
_cellV := cellV as TCellV; |
| 798 |
if FileExists(f) = false then |
| 799 |
begin |
| 800 |
result := false; |
| 801 |
Exit; |
| 802 |
end; |
| 803 |
try |
| 804 |
AssignFile(BufferedReader, f); |
| 805 |
Reset(BufferedReader); |
| 806 |
Readln(BufferedReader, line); |
| 807 |
lineIndex := 1; |
| 808 |
c := nextChar; |
| 809 |
lastT.kind := nul; |
| 810 |
result := true; |
| 811 |
except |
| 812 |
on EInOutError do |
| 813 |
begin |
| 814 |
Writeln('�t�@�C�����J��������'); |
| 815 |
result := false; |
| 816 |
end; |
| 817 |
end; |
| 818 |
end; |
| 819 |
|
| 820 |
function TCellG.pKazuI(const n: integer): integer; |
| 821 |
begin |
| 822 |
result := (funcTable[n - tIndex] as TTableFunc).parIs; |
| 823 |
end; |
| 824 |
|
| 825 |
function TCellG.searchF(const Id: string; m: integer): integer; |
| 826 |
var |
| 827 |
i, j: integer; |
| 828 |
begin |
| 829 |
i := moduleTable[m].index; |
| 830 |
result := 0; |
| 831 |
for j := 0 to moduleTable[m].number - 1 do |
| 832 |
if funcTable[i + j].name = Id then |
| 833 |
result := i + j + tIndex; |
| 834 |
end; |
| 835 |
|
| 836 |
function TCellG.searchT(const Id: string): integer; |
| 837 |
var |
| 838 |
i: integer; |
| 839 |
begin |
| 840 |
result := 0; |
| 841 |
nameTable[0].name := Id; |
| 842 |
for i := tIndex downto 0 do |
| 843 |
if Id = nameTable[i].name then |
| 844 |
begin |
| 845 |
result := i; |
| 846 |
break; |
| 847 |
end; |
| 848 |
if result = 0 then |
| 849 |
result := searchF(Id, mIndex); |
| 850 |
end; |
| 851 |
|
| 852 |
procedure TCellG.setFunc(t: TTable); |
| 853 |
begin |
| 854 |
if fIndex < (MaxTable div 2) then |
| 855 |
begin |
| 856 |
inc(fIndex); |
| 857 |
funcTable[fIndex] := t; |
| 858 |
inc(moduleTable[mIndex].number); |
| 859 |
end |
| 860 |
else |
| 861 |
error('����������������'); |
| 862 |
end; |
| 863 |
|
| 864 |
procedure TCellG.setModule(Id: string); |
| 865 |
begin |
| 866 |
inc(mIndex); |
| 867 |
if mIndex < MaxModule then |
| 868 |
moduleTable[mIndex] := TModule.Create(Id, fIndex + 1, 0) |
| 869 |
else |
| 870 |
error('���W���[��������������'); |
| 871 |
end; |
| 872 |
|
| 873 |
procedure TCellG.setTable(t: TTable); |
| 874 |
begin |
| 875 |
if tIndex < MaxTable then |
| 876 |
begin |
| 877 |
inc(tIndex); |
| 878 |
nameTable[tIndex] := t; |
| 879 |
end |
| 880 |
else |
| 881 |
error('����������������'); |
| 882 |
end; |
| 883 |
|
| 884 |
function TCellG.tableA1int(const Id: string; const n: integer): integer; |
| 885 |
begin |
| 886 |
setTable(TTableArray.Create(Id, arrI, level, localAddr, 1, 0, n)); |
| 887 |
inc(localAddr, n); |
| 888 |
result := tIndex; |
| 889 |
end; |
| 890 |
|
| 891 |
function TCellG.tableA2int(const Id: string; const x, v: integer): integer; |
| 892 |
begin |
| 893 |
setTable(TTableArray.Create(Id, arrI, level, localAddr, 2, x, v)); |
| 894 |
inc(localAddr, x * v); |
| 895 |
result := tIndex; |
| 896 |
end; |
| 897 |
|
| 898 |
function TCellG.tableFunc(const Id: string; const c, mm: integer): integer; |
| 899 |
begin |
| 900 |
setFunc(TTableFunc.Create(Id, funID, level, c, mm, 0, 0)); |
| 901 |
tfIndex := fIndex; |
| 902 |
result := fIndex + tIndex; |
| 903 |
end; |
| 904 |
|
| 905 |
function TCellG.tableInt(const Id: string): integer; |
| 906 |
begin |
| 907 |
setTable(TTable.Create(Id, intID, level, localAddr)); |
| 908 |
inc(localAddr); |
| 909 |
result := tIndex; |
| 910 |
end; |
| 911 |
|
| 912 |
function TCellG.tableString(Id: string): integer; |
| 913 |
begin |
| 914 |
setTable(TTable.Create(Id, strID, level, slocalAddr)); |
| 915 |
inc(slocalAddr); |
| 916 |
result := tIndex; |
| 917 |
end; |
| 918 |
|
| 919 |
function TCellG.tablePint(const Id: string): integer; |
| 920 |
begin |
| 921 |
setFunc(TTable.Create(Id, parI, level, 0)); |
| 922 |
inc((funcTable[tfIndex] as TTableFunc).parIs); |
| 923 |
result := fIndex + tIndex; |
| 924 |
end; |
| 925 |
|
| 926 |
function TCellG.tablePstr(Id: string): integer; |
| 927 |
begin |
| 928 |
setFunc(TTable.Create(Id, parS, level, 0)); |
| 929 |
inc((funcTable[tfIndex] as TTableFunc).parSs); |
| 930 |
result := fIndex + tIndex; |
| 931 |
end; |
| 932 |
|
| 933 |
function TCellG.tAddr(const n: integer): TRaddr; |
| 934 |
begin |
| 935 |
if n > tIndex then |
| 936 |
result := funcTable[n - tIndex].Raddr |
| 937 |
else |
| 938 |
result := nameTable[n].Raddr; |
| 939 |
end; |
| 940 |
|
| 941 |
function TCellG.tKind(const n: integer): integer; |
| 942 |
begin |
| 943 |
if n = 0 then |
| 944 |
result := 0 |
| 945 |
else if n > tIndex then |
| 946 |
result := funcTable[n - tIndex].kind |
| 947 |
else |
| 948 |
result := nameTable[n].kind; |
| 949 |
end; |
| 950 |
|
| 951 |
function TCellG.cClass(c: Char): integer; |
| 952 |
var |
| 953 |
small, big, m: integer; |
| 954 |
begin |
| 955 |
result := others; |
| 956 |
small := 0; |
| 957 |
big := High(fClass); |
| 958 |
while small <= big do |
| 959 |
begin |
| 960 |
m := (small + big) div 2; |
| 961 |
if c < fClass[m].small then |
| 962 |
big := m - 1 |
| 963 |
else if c > fClass[m].big then |
| 964 |
small := m + 1 |
| 965 |
else |
| 966 |
begin |
| 967 |
result := fClass[m].result; |
| 968 |
break; |
| 969 |
end; |
| 970 |
end; |
| 971 |
end; |
| 972 |
|
| 973 |
procedure TCellG.changeT(t, k: integer; x: Boolean); |
| 974 |
var |
| 975 |
i: integer; |
| 976 |
s: TTable; |
| 977 |
begin |
| 978 |
s := nameTable[t]; |
| 979 |
if s.kind = k then |
| 980 |
Exit; |
| 981 |
s.kind := k; |
| 982 |
if x = true then |
| 983 |
i := level - 1 |
| 984 |
else |
| 985 |
i := level; |
| 986 |
if k = intID then |
| 987 |
begin |
| 988 |
if i = s.Raddr.level then |
| 989 |
begin |
| 990 |
s.Raddr.addr := localAddr; |
| 991 |
inc(localAddr); |
| 992 |
dec(slocalAddr); |
| 993 |
end |
| 994 |
else |
| 995 |
begin |
| 996 |
s.Raddr.level := addr[s.Raddr.level]; |
| 997 |
inc(addr[s.Raddr.level]); |
| 998 |
dec(saddr[s.Raddr.level]); |
| 999 |
end; |
| 1000 |
end |
| 1001 |
else if k = strID then |
| 1002 |
begin |
| 1003 |
if i = s.Raddr.level then |
| 1004 |
begin |
| 1005 |
s.Raddr.addr := slocalAddr; |
| 1006 |
inc(slocalAddr); |
| 1007 |
dec(localAddr); |
| 1008 |
end |
| 1009 |
else |
| 1010 |
begin |
| 1011 |
s.Raddr.level := saddr[s.Raddr.level]; |
| 1012 |
inc(saddr[s.Raddr.level]); |
| 1013 |
dec(addr[s.Raddr.level]); |
| 1014 |
end; |
| 1015 |
end; |
| 1016 |
end; |
| 1017 |
|
| 1018 |
function TCellG.moduleName: string; |
| 1019 |
begin |
| 1020 |
result := moduleTable[mIndex].name; |
| 1021 |
end; |
| 1022 |
|
| 1023 |
function TCellG.nextTIndex: integer; |
| 1024 |
begin |
| 1025 |
result := tIndex + 1; |
| 1026 |
end; |
| 1027 |
|
| 1028 |
function TCellG.searchFModule(m, Id: string): integer; |
| 1029 |
var |
| 1030 |
i: integer; |
| 1031 |
begin |
| 1032 |
result := -1; |
| 1033 |
moduleTable[0].name := m; |
| 1034 |
for i := mIndex downto 0 do |
| 1035 |
if m = moduleTable[i].name then |
| 1036 |
result := i; |
| 1037 |
if result >= 0 then |
| 1038 |
result := searchF(Id, result); |
| 1039 |
end; |
| 1040 |
|
| 1041 |
function TCellG.pKazuS(n: integer): integer; |
| 1042 |
begin |
| 1043 |
result := (funcTable[n - tIndex] as TTableFunc).parSs; |
| 1044 |
end; |
| 1045 |
|
| 1046 |
function TCellG.funcModori: integer; |
| 1047 |
begin |
| 1048 |
result := (funcTable[tfIndex] as TTableFunc).modori; |
| 1049 |
end; |
| 1050 |
|
| 1051 |
procedure TCellG.setKariTable(Id, m: string; s, tI, lc, pi, ps, c: integer); |
| 1052 |
begin |
| 1053 |
if kIndex < (MaxTable div 4) then |
| 1054 |
begin |
| 1055 |
inc(kIndex); |
| 1056 |
kariTable[kIndex] := TKari.Create(Id, m, s, tI, lc, 0, pi, ps, c, false); |
| 1057 |
end |
| 1058 |
else |
| 1059 |
error('�������������`������������') |
| 1060 |
end; |
| 1061 |
|
| 1062 |
procedure TCellG.shokika; |
| 1063 |
var |
| 1064 |
i: integer; |
| 1065 |
begin |
| 1066 |
for i := 0 to tIndex do |
| 1067 |
nameTable[i].Free; |
| 1068 |
for i := 0 to fIndex do |
| 1069 |
funcTable[i].Free; |
| 1070 |
for i := 0 to kIndex do |
| 1071 |
kariTable[i].Free; |
| 1072 |
for i := 0 to mIndex do |
| 1073 |
moduleTable[i].Free; |
| 1074 |
kan := -1; |
| 1075 |
tIndex := 0; |
| 1076 |
tfIndex := 0; |
| 1077 |
|
| 1078 |
localAddr := 0; |
| 1079 |
slocalAddr := 0; |
| 1080 |
e := 0; |
| 1081 |
errorLine := ''; |
| 1082 |
|
| 1083 |
level := -1; |
| 1084 |
kIndex := -1; |
| 1085 |
fIndex := 0; |
| 1086 |
mIndex := -1; |
| 1087 |
cr := 1; |
| 1088 |
nameTable[0] := TTable.Create; |
| 1089 |
moduleTable[0] := TModule.Create; |
| 1090 |
end; |
| 1091 |
|
| 1092 |
procedure TCellG.checkKari(Id: string); |
| 1093 |
var |
| 1094 |
i: integer; |
| 1095 |
s: string; |
| 1096 |
procedure main; |
| 1097 |
var |
| 1098 |
j: integer; |
| 1099 |
begin |
| 1100 |
j := (funcTable[tfIndex] as TTableFunc).modori; |
| 1101 |
if j = _V then |
| 1102 |
if kariTable[i].sahen <> 0 then |
| 1103 |
error('�����o�������������������������������B') |
| 1104 |
else if j = _I then |
| 1105 |
begin |
| 1106 |
case kariTable[i].sahen of |
| 1107 |
strID: |
| 1108 |
begin |
| 1109 |
changeT(kariTable[i].tI, intID, true); |
| 1110 |
_cellV.backPatchL(kariTable[i].lcI, kariTable[i].tI, 0); |
| 1111 |
_cellV.changeS(kariTable[i].scI, 0); |
| 1112 |
end; |
| 1113 |
parS: |
| 1114 |
error('�����o�������^�����v���������B'); |
| 1115 |
end; |
| 1116 |
end |
| 1117 |
else if j = _S then |
| 1118 |
case kariTable[i].sahen of |
| 1119 |
intID: |
| 1120 |
begin |
| 1121 |
changeT(kariTable[i].tI, strID, true); |
| 1122 |
_cellV.backPatchL(kariTable[i].lcI, kariTable[i].tI, 1); |
| 1123 |
_cellV.changeS(kariTable[i].scI, 1); |
| 1124 |
end; |
| 1125 |
arrI, parI: |
| 1126 |
error('�����o�������^�����v���������B'); |
| 1127 |
end; |
| 1128 |
if (funcTable[tfIndex] as TTableFunc).parIs <> kariTable[i].pi then |
| 1129 |
error('�����o����������(I)�����������������B'); |
| 1130 |
if (funcTable[tfIndex] as TTableFunc).parSs <> kariTable[i].ps then |
| 1131 |
error('�����o����������(S)�����������������B'); |
| 1132 |
_cellV.backCal(kariTable[i].cI, level - 1, funcTable[tfIndex].Raddr.addr); |
| 1133 |
kariTable[i].tf := true; |
| 1134 |
inc(kan); |
| 1135 |
end; |
| 1136 |
|
| 1137 |
begin |
| 1138 |
if kIndex = -1 then |
| 1139 |
Exit; |
| 1140 |
s := moduleTable[mIndex].name; |
| 1141 |
for i := kIndex downto 0 do |
| 1142 |
if kariTable[i].tf = false then |
| 1143 |
if (Id = kariTable[i].name) and (s = kariTable[i].md) then |
| 1144 |
main; |
| 1145 |
end; |
| 1146 |
|
| 1147 |
function TCellG.funcParSs: integer; |
| 1148 |
begin |
| 1149 |
result := (funcTable[tfIndex] as TTableFunc).parSs; |
| 1150 |
end; |
| 1151 |
|
| 1152 |
procedure TCellG.checkKan; |
| 1153 |
begin |
| 1154 |
if kan < kIndex then |
| 1155 |
error('���`��������������������������'); |
| 1156 |
end; |
| 1157 |
|
| 1158 |
procedure TCellG.setScI(c: integer); |
| 1159 |
begin |
| 1160 |
if kIndex > -1 then |
| 1161 |
kariTable[kIndex].scI := c; |
| 1162 |
end; |
| 1163 |
|
| 1164 |
function TCellG.tableA1str(Id: string; n: integer): integer; |
| 1165 |
begin |
| 1166 |
setTable(TTableArray.Create(Id, arrS, level, slocalAddr, 1, 0, n)); |
| 1167 |
inc(slocalAddr, n); |
| 1168 |
result := tIndex; |
| 1169 |
end; |
| 1170 |
|
| 1171 |
function TCellG.tableA2str(Id: string; x, v: integer): integer; |
| 1172 |
begin |
| 1173 |
setTable(TTableArray.Create(Id, arrS, level, slocalAddr, 2, x, v)); |
| 1174 |
inc(slocalAddr, x * v); |
| 1175 |
result := tIndex; |
| 1176 |
end; |
| 1177 |
|
| 1178 |
{ TTableFunc } |
| 1179 |
|
| 1180 |
constructor TTableFunc.Create(const Id: string; |
| 1181 |
const k, l, a, m, pi, ps: integer); |
| 1182 |
begin |
| 1183 |
inherited Create(Id, k, l, a); |
| 1184 |
modori := m; |
| 1185 |
parIs := pi; |
| 1186 |
parIs := ps; |
| 1187 |
end; |
| 1188 |
|
| 1189 |
function TTableFunc.toString: string; |
| 1190 |
begin |
| 1191 |
result := (inherited toString) + ' : ' + hyouji(modori) + ' : ' + |
| 1192 |
IntToStr(parIs) + 'pI' + ' : ' + IntToStr(parSs) + 'pS'; |
| 1193 |
end; |
| 1194 |
|
| 1195 |
{ TModule } |
| 1196 |
|
| 1197 |
constructor TModule.Create(n: string; i, s: integer); |
| 1198 |
begin |
| 1199 |
inherited Create; |
| 1200 |
name := n; |
| 1201 |
index := i; |
| 1202 |
number := s; |
| 1203 |
end; |
| 1204 |
|
| 1205 |
constructor TModule.Create(n: string); |
| 1206 |
begin |
| 1207 |
inherited Create; |
| 1208 |
name := n; |
| 1209 |
end; |
| 1210 |
|
| 1211 |
{ TKari } |
| 1212 |
|
| 1213 |
constructor TKari.Create(n, m: string; s, t, lc, sc, pi, ps, c: integer; |
| 1214 |
f: Boolean); |
| 1215 |
begin |
| 1216 |
inherited Create; |
| 1217 |
name := n; |
| 1218 |
md := m; |
| 1219 |
sahen := s; |
| 1220 |
tI := t; |
| 1221 |
lcI := lc; |
| 1222 |
scI := sc; |
| 1223 |
self.pi := pi; |
| 1224 |
self.ps := ps; |
| 1225 |
cI := c; |
| 1226 |
tf := f; |
| 1227 |
end; |
| 1228 |
|
| 1229 |
end. |