Главная Терминология Хоора 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 [ 127 ] 128 129 130 131 132 133 begin [term) factor ifsys+[times, slash]); v/Mle sym in [times, slash] do begin mulop := sym; getsym; factor{fsys+[times, slashQ iSmulop times ibengen{opr,0,4)dsegen(ppr,0,5) end end [term] ; begin [expression] Lsym in [plus, minus] then begin addop := sym; getsym; term(fsys+[plus, minus]); if addop ~ minus tbm gen(qpr,0,l) end else term(fsys+lplus, minus]); while sym in [plus, minus] do begin addop := sym; getsym; term(fsys+[ptus, minus]); if addop = plus then gen(ppr,0,2) else gen(ppr,0,3) end {exprm/on} ; procedure condition(fsys: symset); var /e/tjp: symbol; begin if 5>m = oddsym then begin е/д'ш; expression(fsys); gen(ppr,0,6) end else begin expression([eql, neq, Iss, gtr, leq, geq]+fsys); if -](sym in [eql, neq, Iss, leq, gtr, geq]) then error (20) else begin relop := sym; getsym; expression(fsys)l case re/op of eql: genipprfi, %); neq: gen(ppr,0, 9); Iss: gen(opr,Q,lO); geq: gen(ppi;0,n); gtr: gen(opr,0,l2); leq: geniopr,0,l3); end end [condition] ; begin [statement) ifsym = ident then begin I := positioned); if / == 0 then error (11) else if table[i] .kind Ф variable then begin [присваивание переменной] error (12); i := О end ; getsym; iisym ~ becomes then getsym else error (13); €xpression(fsys); ШФ 0 then with table[i] do gen(sto, lev-level, adr) end else if sym - callsym then begin getsym; it sym Ф ident then error (14) else begin j := po5j7/on(rrf); if / = 0 then error (11) else with tabley\ do if kind = procedure then gm (cd, lev-level, adr) else error (TS); getsym end - end else if sym = ifsym then begin getsym; condition([thensym, dosym\fsys); if sym = thensym then getsym else error (16);, cxl := cx; gen(jpc,0,0); statement (fsys); code[cx\].a := cx end else if sym - beginsym then begin getsym; statementdsemicolon, endsym]i-fsys); while sym in [semicolon]+statbegsys do begin ifsym - semicolon then getsym else error (10); statementdsemicolon, endsym]-{-fsys) end ; ifsym - endsym then getsym dse error (XT) end else if sym - whilesym then begin cxl := cx; getsym; condition([dosym]-\-fsys); cxl := cx; gen(Jpc,Q,0); ifsym = dosym then getsym else error (Щ; statement(fsys); gen(jmp,0,cxl); code[cx2].a := cx end ; test(fsys, I ], 19) end {statement} ; begin [block] dx :== 3; /лО := /х; rafc/c[?x] := cx; gen(jmp,0,0); if lev > levmax thm error (32); repeat if sym == cmstsym then begm getsym; repeat constdeclaration; while sytn = comma йо begin getsym; constdeclaration end ; if sym = semicolon then getsym else error (5) until 5зто ?ь iWewf end ; if jjm = гд/У(/?г then begin getsym; repeat vardeclaration; while j>Hz = comma do begin getsym; vardeclaration end ; if = semicolon then getsym else error (5) until sjvM ?b Wert/; end ; >YhiIe sym - procsym do begm getsym; ifsym - ident then begin ettter(procedure); getsym end else error (4); ifsym = .ус г/со/оп then ge/jvm else e/to/-(5)г b}ock(lev+ l,tx,[semicolon]+fsys); ifsym - semicolon then begin getsym; tesi(statbegsys+[ident, procsym], fsys, 6) end else error (5) end ; test(statbegsys+[ident], declbegsys, 7) until -{sym in declbegsys); code[table[txO].adr].a :== ex; with table[txO] do begin flJr:=: ex; {начальный адрес команд] end ; ebcO := сх; gen(int,0,dx); statement([semicolon, endsym]+fsys)l gen(opr,0,0); {return} test(fsys, [ ], 8); listcode; end [block] ; |