Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /trunk/CellK.pas

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (hide annotations) (download) (as text)
Mon Feb 23 07:50:11 2015 UTC (9 years, 1 month ago) by yamat0jp
File MIME type: text/x-pascal
File size: 28272 byte(s)


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

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