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