Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /trunk/CellG.pas

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4 - (hide annotations) (download) (as text)
Thu Apr 6 08:50:57 2017 UTC (7 years ago) by yamat0jp
File MIME type: text/x-pascal
File size: 27824 byte(s)
begin

end;
省きました
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 yamat0jp 4 Id: string;
93 yamat0jp 2 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 yamat0jp 4 constructor Create(const Id: string; const k, l, a: integer); overload;
116     constructor Create(const Id: string); overload;
117 yamat0jp 2 function toString: string; virtual;
118     end;
119    
120     TTableArray = class(TTable)
121     public
122     jigen: integer;
123     gyou: integer;
124     retu: integer;
125 yamat0jp 4 constructor Create(const Id: string; const k, l, a, j, g, r: integer);
126 yamat0jp 2 function toString: string; override;
127     end;
128    
129     TTableFunc = class(TTable)
130     public
131     modori: integer;
132     parIs: integer;
133     parSs: integer;
134 yamat0jp 4 constructor Create(const Id: string; const k, l, a, m, pi, ps: integer);
135 yamat0jp 2 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 yamat0jp 4 pi: integer;
147     ps: integer;
148 yamat0jp 2 cI: integer;
149     tf: Boolean;
150 yamat0jp 4 constructor Create(n, m: string; s, t, lc, sc, pi, ps, c: integer;
151     f: Boolean);
152 yamat0jp 2 end;
153    
154     TCellG = class
155     private
156 yamat0jp 4 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 yamat0jp 2 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 yamat0jp 4 index: array [0 .. MaxLevel] of integer;
170     addr: array [0 .. MaxLevel] of integer;
171     saddr: array [0 .. MaxLevel] of integer;
172 yamat0jp 2 BufferedReader: TextFile;
173     c: Char;
174     line: string;
175     lineIndex: integer;
176     errorLine: string;
177     cr: integer;
178     lastT: TToken;
179     mojiretu: string;
180 yamat0jp 4 key: array [0 .. _end_Sym] of string;
181 yamat0jp 2 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 yamat0jp 4 procedure setModule(Id: string);
193     procedure setKariTable(Id, m: string; s, tI, lc, pi, ps, c: integer);
194 yamat0jp 2 procedure setScI(c: integer);
195     function moduleName: string;
196 yamat0jp 4 function tableInt(const Id: string): integer;
197 yamat0jp 2 procedure initKey;
198     procedure setFunc(t: TTable);
199 yamat0jp 4 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 yamat0jp 2 procedure endPar;
208     procedure changeT(t, k: integer; x: Boolean);
209 yamat0jp 4 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 yamat0jp 2 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 yamat0jp 4 function hyouji(const k: integer): string;
238 yamat0jp 2
239     const
240 yamat0jp 4 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 yamat0jp 2
257     implementation
258    
259 yamat0jp 4 uses cellV;
260 yamat0jp 2
261     const
262     MaxMoji = 200;
263    
264     var
265     _cellV: TCellV;
266 yamat0jp 4
267 yamat0jp 2 function hyouji(const k: integer): string;
268     begin
269     case k of
270 yamat0jp 4 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 yamat0jp 2 else
289 yamat0jp 4 result := IntToStr(k);
290 yamat0jp 2 end;
291     end;
292    
293     { TTable }
294    
295 yamat0jp 4 constructor TTable.Create(const Id: string; const k, l, a: integer);
296 yamat0jp 2 begin
297 yamat0jp 4 inherited Create;
298     name := Id;
299     kind := k;
300     Raddr.level := l;
301     Raddr.addr := a;
302 yamat0jp 2 end;
303    
304 yamat0jp 4 constructor TTable.Create(const Id: string);
305 yamat0jp 2 begin
306 yamat0jp 4 inherited Create;
307     name := Id;
308 yamat0jp 2 end;
309    
310     function TTable.toString: string;
311     begin
312 yamat0jp 4 result := name + ' : ' + hyouji(kind) + ' : ' + IntToStr(Raddr.level) +
313     IntToStr(Raddr.addr);
314 yamat0jp 2 end;
315    
316     { TTableArray }
317    
318 yamat0jp 4 constructor TTableArray.Create(const Id: string;
319     const k, l, a, j, g, r: integer);
320 yamat0jp 2 begin
321 yamat0jp 4 inherited Create(Id, k, l, a);
322     jigen := j;
323     gyou := g;
324     retu := r;
325 yamat0jp 2 end;
326    
327     function TTableArray.toString: string;
328     begin
329 yamat0jp 4 result := inherited toString + ' : ' + IntToStr(jigen) + '����: ' +
330     IntToStr(gyou) + IntToStr(retu) + '��';
331 yamat0jp 2 end;
332    
333     { TCellG }
334    
335     function TCellG.bLevel: integer;
336     begin
337 yamat0jp 4 result := level;
338 yamat0jp 2 end;
339    
340     procedure TCellG.blockBegin;
341     begin
342     if level = -1 then
343     begin
344 yamat0jp 4 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 yamat0jp 2 begin
353 yamat0jp 4 index[level] := tIndex;
354     addr[level] := localAddr;
355     saddr[level] := slocalAddr;
356     localAddr := firstAddr;
357     slocalAddr := 0;
358     inc(level);
359 yamat0jp 2 end;
360     end;
361    
362     procedure TCellG.blockEnd;
363     var
364     i, j: integer;
365     begin
366     if pTable = true then
367     begin
368 yamat0jp 4 Writeln('--level : ' + IntToStr(level) + '--');
369 yamat0jp 2 if level = 0 then
370 yamat0jp 4 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 yamat0jp 2 begin
377     if fIndex = 0 then
378 yamat0jp 4 break;
379     Writeln(funcTable[j].toString);
380 yamat0jp 2 end;
381 yamat0jp 4 Writeln;
382 yamat0jp 2 end;
383     if level = 0 then
384 yamat0jp 4 dec(level)
385     else
386 yamat0jp 2 begin
387 yamat0jp 4 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 yamat0jp 2 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 yamat0jp 4 error('��������������-' + key[k]);
401     result := t;
402     end
403     else
404     result := makeToken;
405 yamat0jp 2 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 yamat0jp 4 result := true
413     else
414 yamat0jp 2 begin
415 yamat0jp 4 result := false;
416     for i := 1 to Length(n) do
417 yamat0jp 2 begin
418 yamat0jp 4 j := cClass(n[i]);
419 yamat0jp 2 if j <> digit then
420     begin
421 yamat0jp 4 result := true;
422     break;
423 yamat0jp 2 end;
424     end;
425     end;
426     end;
427    
428     procedure TCellG.closeFile;
429     begin
430     try
431 yamat0jp 4 System.closeFile(BufferedReader);
432 yamat0jp 2 except
433 yamat0jp 4 on EInOutError do
434     Writeln('�t�@�C������������������');
435 yamat0jp 2 end;
436     end;
437    
438     constructor TCellG.Create(p: Boolean);
439     begin
440 yamat0jp 4 inherited Create;
441     pTable := p;
442     lastT := TToken.Create;
443     initKey;
444     shokika;
445 yamat0jp 2 end;
446    
447     destructor TCellG.Destroy;
448     begin
449 yamat0jp 4 lastT.Free;
450     nameTable[0].Free;
451     moduleTable[0].Free;
452     inherited;
453 yamat0jp 2 end;
454    
455     procedure TCellG.endPar;
456     var
457 yamat0jp 4 i, pi, ps: integer;
458 yamat0jp 2 begin
459     with funcTable[tfIndex] as TTableFunc do
460     begin
461 yamat0jp 4 pi := parIs;
462     ps := parSs;
463 yamat0jp 2 end;
464 yamat0jp 4 if (pi = 0) and (ps = 0) then
465     Exit;
466     for i := tfIndex + 1 to tfIndex + pi + ps do
467 yamat0jp 2 begin
468     if funcTable[i].kind = parI then
469     begin
470 yamat0jp 4 funcTable[i].Raddr.addr := -pi;
471     dec(pi);
472     end
473     else
474 yamat0jp 2 begin
475 yamat0jp 4 funcTable[i].Raddr.addr := -ps;
476     dec(ps);
477 yamat0jp 2 end;
478     end;
479     end;
480    
481     procedure TCellG.error(const er: string);
482     begin
483 yamat0jp 4 inc(e);
484     Writeln(IntToStr(cr) + ' : ' + errorLine + ' : ' + er + '�B');
485     errorLine := '';
486 yamat0jp 2 end;
487    
488     function TCellG.fModori(n: integer): integer;
489     begin
490 yamat0jp 4 result := (funcTable[n - tIndex] as TTableFunc).modori;
491 yamat0jp 2 end;
492    
493     function TCellG.funcParIs: integer;
494     begin
495 yamat0jp 4 result := (funcTable[tfIndex] as TTableFunc).parIs;
496 yamat0jp 2 end;
497    
498     function TCellG.hairetu(const n: integer): TRaddr;
499     begin
500     with nameTable[n] as TTableArray do
501     begin
502 yamat0jp 4 result.level := gyou;
503     result.addr := retu;
504 yamat0jp 2 end;
505     end;
506    
507     procedure TCellG.initKey;
508     begin
509 yamat0jp 4 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 yamat0jp 2 end;
545    
546     function TCellG.jigen(const i: integer): integer;
547     begin
548 yamat0jp 4 result := TTableArray(nameTable[i]).jigen;
549 yamat0jp 2 end;
550    
551     function TCellG.makeToken: TToken;
552     var
553     i: integer;
554     cc, k: integer;
555 yamat0jp 4 Num: integer;
556 yamat0jp 2 temp: TToken;
557 yamat0jp 4 Id: string;
558 yamat0jp 2 begin
559 yamat0jp 4 temp := TToken.Create;
560 yamat0jp 2 while true do
561     begin
562 yamat0jp 4 k := lastT.kind;
563 yamat0jp 2 if k <> nul then
564     begin
565     if k < _end_Sym then
566 yamat0jp 4 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 yamat0jp 2 end;
572 yamat0jp 4 cc := cClass(c);
573     while (cc = space) or (cc = cr1) or (cc = tab) do
574 yamat0jp 2 begin
575 yamat0jp 4 if (cc = space) or (cc = tab) then
576     errorLine := errorLine + c;
577 yamat0jp 2 if cc = cr1 then
578     begin
579 yamat0jp 4 inc(cr);
580     errorLine := '';
581 yamat0jp 2 end;
582 yamat0jp 4 c := nextChar;
583     cc := cClass(c);
584 yamat0jp 2 end;
585     case cc of
586 yamat0jp 4 digit:
587 yamat0jp 2 begin
588 yamat0jp 4 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 yamat0jp 2 end;
599 yamat0jp 4 letter, others:
600 yamat0jp 2 begin
601 yamat0jp 4 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 yamat0jp 2 end;
625 yamat0jp 4 _Equal:
626 yamat0jp 2 begin
627 yamat0jp 4 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 yamat0jp 2 end;
637 yamat0jp 4 _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 yamat0jp 2 else
747 yamat0jp 4 temp.kind := cc;
748     c := nextChar;
749     break;
750 yamat0jp 2 end;
751     end;
752 yamat0jp 4 lastT.Free;
753     lastT := temp;
754     result := temp;
755 yamat0jp 2 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 yamat0jp 4 Writeln(IntToStr(cr) + ':�t�@�C���I���A$�������������B' + IntToStr(e),
764     '�G���[����:' + IntToStr(e + 1));
765     System.closeFile(BufferedReader);
766 yamat0jp 2 raise EInOutError.Create('error');
767     end;
768 yamat0jp 4 lineIndex := 1;
769 yamat0jp 2 try
770 yamat0jp 4 Readln(BufferedReader, line);
771 yamat0jp 2 except
772 yamat0jp 4 Writeln(IntToStr(cr) + '�����s�����������������B' + ' : ' + IntToStr(e),
773     '�G���[����:' + IntToStr(e + 1));
774 yamat0jp 2 raise;
775     end;
776 yamat0jp 4 result := #13;
777     end
778     else
779 yamat0jp 2 begin
780 yamat0jp 4 result := line[lineIndex];
781     inc(lineIndex);
782 yamat0jp 2 end;
783     end;
784    
785     function TCellG.numAddr: integer;
786     begin
787 yamat0jp 4 result := localAddr;
788 yamat0jp 2 end;
789    
790     function TCellG.snumAddr: integer;
791     begin
792 yamat0jp 4 result := slocalAddr;
793 yamat0jp 2 end;
794    
795     function TCellG.open(const f: TFileName; cellV: TObject): Boolean;
796     begin
797 yamat0jp 4 _cellV := cellV as TCellV;
798 yamat0jp 2 if FileExists(f) = false then
799     begin
800 yamat0jp 4 result := false;
801     Exit;
802 yamat0jp 2 end;
803     try
804 yamat0jp 4 AssignFile(BufferedReader, f);
805     Reset(BufferedReader);
806     Readln(BufferedReader, line);
807     lineIndex := 1;
808     c := nextChar;
809     lastT.kind := nul;
810     result := true;
811 yamat0jp 2 except
812     on EInOutError do
813     begin
814 yamat0jp 4 Writeln('�t�@�C�����J��������');
815     result := false;
816 yamat0jp 2 end;
817     end;
818     end;
819    
820     function TCellG.pKazuI(const n: integer): integer;
821     begin
822 yamat0jp 4 result := (funcTable[n - tIndex] as TTableFunc).parIs;
823 yamat0jp 2 end;
824    
825 yamat0jp 4 function TCellG.searchF(const Id: string; m: integer): integer;
826 yamat0jp 2 var
827     i, j: integer;
828     begin
829 yamat0jp 4 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 yamat0jp 2 end;
835    
836 yamat0jp 4 function TCellG.searchT(const Id: string): integer;
837 yamat0jp 2 var
838     i: integer;
839     begin
840 yamat0jp 4 result := 0;
841     nameTable[0].name := Id;
842     for i := tIndex downto 0 do
843     if Id = nameTable[i].name then
844 yamat0jp 2 begin
845 yamat0jp 4 result := i;
846     break;
847 yamat0jp 2 end;
848     if result = 0 then
849 yamat0jp 4 result := searchF(Id, mIndex);
850 yamat0jp 2 end;
851    
852     procedure TCellG.setFunc(t: TTable);
853     begin
854     if fIndex < (MaxTable div 2) then
855     begin
856 yamat0jp 4 inc(fIndex);
857     funcTable[fIndex] := t;
858     inc(moduleTable[mIndex].number);
859     end
860     else
861     error('����������������');
862 yamat0jp 2 end;
863    
864 yamat0jp 4 procedure TCellG.setModule(Id: string);
865 yamat0jp 2 begin
866 yamat0jp 4 inc(mIndex);
867 yamat0jp 2 if mIndex < MaxModule then
868 yamat0jp 4 moduleTable[mIndex] := TModule.Create(Id, fIndex + 1, 0)
869     else
870     error('���W���[��������������');
871 yamat0jp 2 end;
872    
873     procedure TCellG.setTable(t: TTable);
874     begin
875     if tIndex < MaxTable then
876     begin
877 yamat0jp 4 inc(tIndex);
878     nameTable[tIndex] := t;
879     end
880     else
881     error('����������������');
882 yamat0jp 2 end;
883    
884 yamat0jp 4 function TCellG.tableA1int(const Id: string; const n: integer): integer;
885 yamat0jp 2 begin
886 yamat0jp 4 setTable(TTableArray.Create(Id, arrI, level, localAddr, 1, 0, n));
887     inc(localAddr, n);
888     result := tIndex;
889 yamat0jp 2 end;
890    
891 yamat0jp 4 function TCellG.tableA2int(const Id: string; const x, v: integer): integer;
892 yamat0jp 2 begin
893 yamat0jp 4 setTable(TTableArray.Create(Id, arrI, level, localAddr, 2, x, v));
894     inc(localAddr, x * v);
895     result := tIndex;
896 yamat0jp 2 end;
897    
898 yamat0jp 4 function TCellG.tableFunc(const Id: string; const c, mm: integer): integer;
899 yamat0jp 2 begin
900 yamat0jp 4 setFunc(TTableFunc.Create(Id, funID, level, c, mm, 0, 0));
901     tfIndex := fIndex;
902     result := fIndex + tIndex;
903 yamat0jp 2 end;
904    
905 yamat0jp 4 function TCellG.tableInt(const Id: string): integer;
906 yamat0jp 2 begin
907 yamat0jp 4 setTable(TTable.Create(Id, intID, level, localAddr));
908     inc(localAddr);
909     result := tIndex;
910 yamat0jp 2 end;
911    
912 yamat0jp 4 function TCellG.tableString(Id: string): integer;
913 yamat0jp 2 begin
914 yamat0jp 4 setTable(TTable.Create(Id, strID, level, slocalAddr));
915     inc(slocalAddr);
916     result := tIndex;
917 yamat0jp 2 end;
918    
919 yamat0jp 4 function TCellG.tablePint(const Id: string): integer;
920 yamat0jp 2 begin
921 yamat0jp 4 setFunc(TTable.Create(Id, parI, level, 0));
922     inc((funcTable[tfIndex] as TTableFunc).parIs);
923     result := fIndex + tIndex;
924 yamat0jp 2 end;
925    
926 yamat0jp 4 function TCellG.tablePstr(Id: string): integer;
927 yamat0jp 2 begin
928 yamat0jp 4 setFunc(TTable.Create(Id, parS, level, 0));
929     inc((funcTable[tfIndex] as TTableFunc).parSs);
930     result := fIndex + tIndex;
931 yamat0jp 2 end;
932    
933     function TCellG.tAddr(const n: integer): TRaddr;
934     begin
935     if n > tIndex then
936 yamat0jp 4 result := funcTable[n - tIndex].Raddr
937     else
938     result := nameTable[n].Raddr;
939 yamat0jp 2 end;
940    
941     function TCellG.tKind(const n: integer): integer;
942     begin
943     if n = 0 then
944 yamat0jp 4 result := 0
945     else if n > tIndex then
946     result := funcTable[n - tIndex].kind
947     else
948     result := nameTable[n].kind;
949 yamat0jp 2 end;
950    
951     function TCellG.cClass(c: Char): integer;
952     var
953     small, big, m: integer;
954     begin
955 yamat0jp 4 result := others;
956     small := 0;
957     big := High(fClass);
958 yamat0jp 2 while small <= big do
959     begin
960 yamat0jp 4 m := (small + big) div 2;
961 yamat0jp 2 if c < fClass[m].small then
962 yamat0jp 4 big := m - 1
963     else if c > fClass[m].big then
964     small := m + 1
965     else
966 yamat0jp 2 begin
967 yamat0jp 4 result := fClass[m].result;
968     break;
969 yamat0jp 2 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 yamat0jp 4 s := nameTable[t];
979 yamat0jp 2 if s.kind = k then
980 yamat0jp 4 Exit;
981     s.kind := k;
982 yamat0jp 2 if x = true then
983 yamat0jp 4 i := level - 1
984     else
985     i := level;
986 yamat0jp 2 if k = intID then
987     begin
988     if i = s.Raddr.level then
989     begin
990 yamat0jp 4 s.Raddr.addr := localAddr;
991     inc(localAddr);
992     dec(slocalAddr);
993     end
994     else
995 yamat0jp 2 begin
996 yamat0jp 4 s.Raddr.level := addr[s.Raddr.level];
997     inc(addr[s.Raddr.level]);
998     dec(saddr[s.Raddr.level]);
999 yamat0jp 2 end;
1000 yamat0jp 4 end
1001     else if k = strID then
1002 yamat0jp 2 begin
1003     if i = s.Raddr.level then
1004     begin
1005 yamat0jp 4 s.Raddr.addr := slocalAddr;
1006     inc(slocalAddr);
1007     dec(localAddr);
1008     end
1009     else
1010 yamat0jp 2 begin
1011 yamat0jp 4 s.Raddr.level := saddr[s.Raddr.level];
1012     inc(saddr[s.Raddr.level]);
1013     dec(addr[s.Raddr.level]);
1014 yamat0jp 2 end;
1015     end;
1016     end;
1017    
1018     function TCellG.moduleName: string;
1019     begin
1020 yamat0jp 4 result := moduleTable[mIndex].name;
1021 yamat0jp 2 end;
1022    
1023     function TCellG.nextTIndex: integer;
1024     begin
1025 yamat0jp 4 result := tIndex + 1;
1026 yamat0jp 2 end;
1027    
1028 yamat0jp 4 function TCellG.searchFModule(m, Id: string): integer;
1029 yamat0jp 2 var
1030     i: integer;
1031     begin
1032 yamat0jp 4 result := -1;
1033     moduleTable[0].name := m;
1034     for i := mIndex downto 0 do
1035 yamat0jp 2 if m = moduleTable[i].name then
1036 yamat0jp 4 result := i;
1037 yamat0jp 2 if result >= 0 then
1038 yamat0jp 4 result := searchF(Id, result);
1039 yamat0jp 2 end;
1040    
1041     function TCellG.pKazuS(n: integer): integer;
1042     begin
1043 yamat0jp 4 result := (funcTable[n - tIndex] as TTableFunc).parSs;
1044 yamat0jp 2 end;
1045    
1046     function TCellG.funcModori: integer;
1047     begin
1048 yamat0jp 4 result := (funcTable[tfIndex] as TTableFunc).modori;
1049 yamat0jp 2 end;
1050    
1051 yamat0jp 4 procedure TCellG.setKariTable(Id, m: string; s, tI, lc, pi, ps, c: integer);
1052 yamat0jp 2 begin
1053     if kIndex < (MaxTable div 4) then
1054     begin
1055 yamat0jp 4 inc(kIndex);
1056     kariTable[kIndex] := TKari.Create(Id, m, s, tI, lc, 0, pi, ps, c, false);
1057     end
1058     else
1059     error('�������������`������������')
1060 yamat0jp 2 end;
1061    
1062     procedure TCellG.shokika;
1063     var
1064     i: integer;
1065     begin
1066 yamat0jp 4 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 yamat0jp 2
1078 yamat0jp 4 localAddr := 0;
1079     slocalAddr := 0;
1080     e := 0;
1081     errorLine := '';
1082 yamat0jp 2
1083 yamat0jp 4 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 yamat0jp 2 end;
1091    
1092 yamat0jp 4 procedure TCellG.checkKari(Id: string);
1093 yamat0jp 2 var
1094     i: integer;
1095     s: string;
1096     procedure main;
1097     var
1098     j: integer;
1099     begin
1100 yamat0jp 4 j := (funcTable[tfIndex] as TTableFunc).modori;
1101 yamat0jp 2 if j = _V then
1102     if kariTable[i].sahen <> 0 then
1103 yamat0jp 4 error('�����o�������������������������������B')
1104     else if j = _I then
1105 yamat0jp 2 begin
1106 yamat0jp 4 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 yamat0jp 2 end;
1136 yamat0jp 4
1137 yamat0jp 2 begin
1138     if kIndex = -1 then
1139 yamat0jp 4 Exit;
1140     s := moduleTable[mIndex].name;
1141     for i := kIndex downto 0 do
1142 yamat0jp 2 if kariTable[i].tf = false then
1143 yamat0jp 4 if (Id = kariTable[i].name) and (s = kariTable[i].md) then
1144     main;
1145 yamat0jp 2 end;
1146    
1147     function TCellG.funcParSs: integer;
1148     begin
1149 yamat0jp 4 result := (funcTable[tfIndex] as TTableFunc).parSs;
1150 yamat0jp 2 end;
1151    
1152     procedure TCellG.checkKan;
1153     begin
1154 yamat0jp 4 if kan < kIndex then
1155     error('���`��������������������������');
1156 yamat0jp 2 end;
1157    
1158     procedure TCellG.setScI(c: integer);
1159     begin
1160     if kIndex > -1 then
1161 yamat0jp 4 kariTable[kIndex].scI := c;
1162 yamat0jp 2 end;
1163    
1164 yamat0jp 4 function TCellG.tableA1str(Id: string; n: integer): integer;
1165 yamat0jp 2 begin
1166 yamat0jp 4 setTable(TTableArray.Create(Id, arrS, level, slocalAddr, 1, 0, n));
1167     inc(slocalAddr, n);
1168     result := tIndex;
1169 yamat0jp 2 end;
1170    
1171 yamat0jp 4 function TCellG.tableA2str(Id: string; x, v: integer): integer;
1172 yamat0jp 2 begin
1173 yamat0jp 4 setTable(TTableArray.Create(Id, arrS, level, slocalAddr, 2, x, v));
1174     inc(slocalAddr, x * v);
1175     result := tIndex;
1176 yamat0jp 2 end;
1177    
1178     { TTableFunc }
1179    
1180 yamat0jp 4 constructor TTableFunc.Create(const Id: string;
1181     const k, l, a, m, pi, ps: integer);
1182 yamat0jp 2 begin
1183 yamat0jp 4 inherited Create(Id, k, l, a);
1184     modori := m;
1185     parIs := pi;
1186     parIs := ps;
1187 yamat0jp 2 end;
1188    
1189     function TTableFunc.toString: string;
1190     begin
1191 yamat0jp 4 result := (inherited toString) + ' : ' + hyouji(modori) + ' : ' +
1192     IntToStr(parIs) + 'pI' + ' : ' + IntToStr(parSs) + 'pS';
1193 yamat0jp 2 end;
1194    
1195     { TModule }
1196    
1197     constructor TModule.Create(n: string; i, s: integer);
1198     begin
1199 yamat0jp 4 inherited Create;
1200     name := n;
1201     index := i;
1202     number := s;
1203 yamat0jp 2 end;
1204    
1205     constructor TModule.Create(n: string);
1206     begin
1207 yamat0jp 4 inherited Create;
1208     name := n;
1209 yamat0jp 2 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 yamat0jp 4 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 yamat0jp 2 end;
1228    
1229     end.

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26