| 48 |
procedure TCellK._block_body; |
procedure TCellK._block_body; |
| 49 |
begin |
begin |
| 50 |
while true do |
while true do |
|
begin |
|
| 51 |
case token.kind of |
case token.kind of |
| 52 |
CellG._aI: |
CellG._aI: |
| 53 |
_array; |
_array; |
| 54 |
CellG._Rbrace,CellG.dollar: |
CellG._Rbrace, CellG.dollar: |
| 55 |
break; |
break; |
| 56 |
CellG._I,CellG._S, CellG._V: |
CellG._I, CellG._S, CellG._V: |
| 57 |
break; |
break; |
| 58 |
else |
else |
| 59 |
_statement; |
_statement; |
| 60 |
end; |
end; |
|
end; |
|
| 61 |
end; |
end; |
| 62 |
|
|
| 63 |
function TCellK.compile: Boolean; |
function TCellK.compile: Boolean; |
| 64 |
begin |
begin |
| 65 |
_cellG.shokika; |
_cellG.shokika; |
| 66 |
_cellV.shokika; |
_cellV.shokika; |
| 67 |
shokika; |
shokika; |
| 68 |
token:=_cellG.makeToken; |
token := _cellG.makeToken; |
| 69 |
while token.kind <> CellG.dollar do |
while token.kind <> CellG.dollar do |
| 70 |
begin |
_module; |
| 71 |
_module; |
result := _cellG.e < 1; |
|
end; |
|
|
result:=_cellG.e<1; |
|
| 72 |
end; |
end; |
| 73 |
|
|
| 74 |
constructor TCellK.Create(v: TCellV; g: TCellG); |
constructor TCellK.Create(v: TCellV; g: TCellG); |
| 75 |
begin |
begin |
| 76 |
inherited Create; |
inherited Create; |
| 77 |
shokika; |
shokika; |
| 78 |
_cellV:=v; |
_cellV := v; |
| 79 |
_cellG:=g; |
_cellG := g; |
| 80 |
end; |
end; |
| 81 |
|
|
| 82 |
procedure TCellK._module; |
procedure TCellK._module; |
| 85 |
backP1, backP2: integer; |
backP1, backP2: integer; |
| 86 |
begin |
begin |
| 87 |
if token.kind = CellG.Id then |
if token.kind = CellG.Id then |
| 88 |
begin |
_cellG.setModule(token.Id) |
| 89 |
_cellG.setModule(token.id); |
else |
| 90 |
end else |
_cellG.error('モジュール名がありません'); |
| 91 |
begin |
token := _cellG.checkGet(_cellG.makeToken, CellG._Lbrace); |
| 92 |
_cellG.error('モジュール名がありません'); |
backP1 := _cellV.genCodeP(CellV.ict, 0); |
| 93 |
end; |
backP2 := _cellV.genCodeP(CellV.ics, 0); |
| 94 |
token:=_cellG.checkGet(_cellG.makeToken,CellG._Lbrace); |
_cellG.blockBegin; |
| 95 |
backP1:=_cellV.genCodeP(CellV.ict,0); |
_block_body; |
| 96 |
backP2:=_cellV.genCodeP(CellV.ics,0); |
while (token.kind = CellG._I) or (token.kind = CellG._S) or |
| 97 |
_cellG.blockBegin; |
(token.kind = CellG._V) do |
| 98 |
_block_body; |
begin |
| 99 |
while (token.kind = CellG._I)or(token.kind = CellG._S)or(token.kind = CellG._V) do |
backP := _cellV.genCodeP(CellV.jmp, 0); |
| 100 |
begin |
_function; |
| 101 |
backP:=_cellV.genCodeP(CellV.jmp,0); |
_cellV.backPatchJ(backP); |
| 102 |
_function; |
_block_body; |
| 103 |
_cellV.backPatchJ(backP); |
end; |
| 104 |
_block_body; |
_cellV.backPatch(backP1, backP2); |
| 105 |
end; |
_cellG.blockEnd; |
| 106 |
_cellV.backPatch(backP1,backP2); |
token := _cellG.checkGet(token, CellG._Rbrace); |
|
_cellG.blockEnd; |
|
|
token:=_cellG.checkGet(token,CellG._Rbrace); |
|
| 107 |
end; |
end; |
| 108 |
|
|
| 109 |
procedure TCellK._array; |
procedure TCellK._array; |
| 110 |
var |
var |
| 111 |
v: integer; |
v: integer; |
| 112 |
id: string; |
Id: string; |
| 113 |
begin |
begin |
| 114 |
token:=_cellG.makeToken; |
token := _cellG.makeToken; |
| 115 |
while true do |
while true do |
| 116 |
begin |
begin |
| 117 |
if token.kind = CellG.Id then |
if token.kind = CellG.Id then |
| 118 |
begin |
begin |
| 119 |
id:=token.id; |
Id := token.Id; |
| 120 |
token:=_cellG.checkGet(_cellG.makeToken,CellG._Lbracket); |
token := _cellG.checkGet(_cellG.makeToken, CellG._Lbracket); |
| 121 |
if token.kind = CellG.Num then |
if token.kind = CellG.Num then |
| 122 |
begin |
begin |
| 123 |
v:=token.value; |
v := token.value; |
| 124 |
token:=_cellG.makeToken; |
token := _cellG.makeToken; |
| 125 |
if token.kind = CellG._Rbracket then |
if token.kind = CellG._Rbracket then |
| 126 |
begin |
begin |
| 127 |
_cellG.tableA1int(id,v); |
_cellG.tableA1int(Id, v); |
| 128 |
token:=_cellG.makeToken; |
token := _cellG.makeToken; |
| 129 |
end else |
end |
| 130 |
if token.kind = CellG._Ex then |
else if token.kind = CellG._Ex then |
| 131 |
begin |
begin |
| 132 |
token:=_cellG.makeToken; |
token := _cellG.makeToken; |
| 133 |
if token.kind = CellG.Num then |
if token.kind = CellG.Num then |
| 134 |
begin |
begin |
| 135 |
_cellG.tableA2int(id,v,token.value); |
_cellG.tableA2int(Id, v, token.value); |
| 136 |
token:=_cellG.checkGet(_cellG.makeToken,CellG._Rbracket); |
token := _cellG.checkGet(_cellG.makeToken, CellG._Rbracket); |
| 137 |
end else |
end |
| 138 |
|
else |
| 139 |
begin |
begin |
| 140 |
_cellG.error('数字がありません'); |
_cellG.error('数字がありません'); |
| 141 |
Exit; |
Exit; |
| 142 |
end; |
end; |
| 143 |
end else |
end |
| 144 |
|
else |
| 145 |
begin |
begin |
| 146 |
_cellG.error('名前がありません'); |
_cellG.error('名前がありません'); |
| 147 |
Exit; |
Exit; |
| 148 |
end; |
end; |
| 149 |
end; |
end; |
| 150 |
end; |
end; |
| 151 |
if token.kind = CellG._Comma then |
if token.kind = CellG._Comma then |
| 152 |
begin |
begin |
| 153 |
token:=_cellG.makeToken; |
token := _cellG.makeToken; |
| 154 |
continue; |
continue; |
| 155 |
end else |
end |
| 156 |
if token.kind = CellG._Semicolon then |
else if token.kind = CellG._Semicolon then |
| 157 |
begin |
begin |
| 158 |
token:=_cellG.makeToken; |
token := _cellG.makeToken; |
| 159 |
Exit; |
Exit; |
| 160 |
end else |
end |
| 161 |
|
else |
| 162 |
begin |
begin |
| 163 |
_cellG.error('; or , がありません'); |
_cellG.error('; or , がありません'); |
| 164 |
Exit; |
Exit; |
| 165 |
end; |
end; |
| 166 |
end; |
end; |
| 167 |
end; |
end; |
| 170 |
var |
var |
| 171 |
backP1, backP2: integer; |
backP1, backP2: integer; |
| 172 |
begin |
begin |
| 173 |
token:=_cellG.checkGet(token,CellG._Lbrace); |
token := _cellG.checkGet(token, CellG._Lbrace); |
| 174 |
backP1:=_cellV.genCodeP(CellV.ict,0); |
backP1 := _cellV.genCodeP(CellV.ict, 0); |
| 175 |
backP2:=_cellV.genCodeP(CellV.ics,0); |
backP2 := _cellV.genCodeP(CellV.ics, 0); |
| 176 |
_block_body; |
_block_body; |
| 177 |
_cellV.backPatch(backP1,backP2); |
_cellV.backPatch(backP1, backP2); |
| 178 |
_cellG.blockEnd; |
_cellG.blockEnd; |
| 179 |
if token.kind = CellG.dollar then |
if token.kind = CellG.dollar then |
| 180 |
begin |
_cellG.error('}がありません') |
| 181 |
_cellG.error('}がありません'); |
else |
| 182 |
end else |
token := _cellG.makeToken; |
|
begin |
|
|
token:=_cellG.makeToken; |
|
|
end; |
|
| 183 |
end; |
end; |
| 184 |
|
|
| 185 |
procedure TCellK._function; |
procedure TCellK._function; |
| 188 |
s: string; |
s: string; |
| 189 |
err, x: Boolean; |
err, x: Boolean; |
| 190 |
begin |
begin |
| 191 |
s:=''; |
s := ''; |
| 192 |
f:=token.kind; |
f := token.kind; |
| 193 |
x:=f=CellG._V; |
x := f = CellG._V; |
| 194 |
token:=_cellG.makeToken; |
token := _cellG.makeToken; |
| 195 |
if token.kind = CellG.Id then |
if token.kind = CellG.Id then |
| 196 |
begin |
begin |
| 197 |
s:=token.id; |
s := token.Id; |
| 198 |
token:=_cellG.makeToken; |
token := _cellG.makeToken; |
| 199 |
_cellG.tableFunc(s,_cellV.nextCode,f); |
_cellG.tableFunc(s, _cellV.nextCode, f); |
| 200 |
end else |
end |
| 201 |
begin |
else |
| 202 |
_cellG.error('関数名がありません'); |
_cellG.error('関数名がありません'); |
| 203 |
end; |
token := _cellG.checkGet(token, CellG._Lparen); |
| 204 |
token:=_cellG.checkGet(token,CellG._Lparen); |
_cellG.blockBegin; |
| 205 |
_cellG.blockBegin; |
err := false; |
|
err:=false; |
|
| 206 |
if token.kind = CellG._Rparen then |
if token.kind = CellG._Rparen then |
| 207 |
begin |
token := _cellG.makeToken |
| 208 |
token:=_cellG.makeToken; |
else |
|
end else |
|
|
begin |
|
| 209 |
while true do |
while true do |
| 210 |
begin |
begin |
| 211 |
|
f := token.kind; |
| 212 |
f:=token.kind; |
if (f = CellG._I) or (f = CellG._S) then |
|
if (f = CellG._I)or(f = CellG._S) then |
|
| 213 |
begin |
begin |
| 214 |
token:=_cellG.makeToken; |
token := _cellG.makeToken; |
| 215 |
if token.kind = CellG.Id then |
if token.kind = CellG.Id then |
| 216 |
begin |
begin |
| 217 |
if f = CellG._I then |
if f = CellG._I then |
| 218 |
begin |
begin |
| 219 |
_cellG.tablePint(token.id); |
_cellG.tablePint(token.Id); |
| 220 |
end else |
end |
| 221 |
|
else |
| 222 |
begin |
begin |
| 223 |
_cellG.tablePstr(token.id); |
_cellG.tablePstr(token.Id); |
| 224 |
end; |
end; |
| 225 |
token:=_cellG.makeToken; |
token := _cellG.makeToken; |
| 226 |
end else |
end |
| 227 |
|
else |
| 228 |
begin |
begin |
| 229 |
_cellG.error('引数名がありません'); |
_cellG.error('引数名がありません'); |
| 230 |
end; |
end; |
| 231 |
if token.kind = CellG._Comma then |
if token.kind = CellG._Comma then |
| 232 |
begin |
begin |
| 233 |
token:=_cellG.makeToken; |
token := _cellG.makeToken; |
| 234 |
continue; |
continue; |
| 235 |
end else |
end |
| 236 |
if token.kind = CellG._Rparen then |
else if token.kind = CellG._Rparen then |
| 237 |
begin |
begin |
| 238 |
_cellG.endPar; |
_cellG.endPar; |
| 239 |
token:=_cellG.makeToken; |
token := _cellG.makeToken; |
| 240 |
break; |
break; |
| 241 |
end else |
end |
| 242 |
begin |
else |
| 243 |
_cellG.error(',or)がありません'); |
begin |
| 244 |
err:=true; |
_cellG.error(',or)がありません'); |
| 245 |
break; |
err := true; |
| 246 |
|
break; |
| 247 |
end; |
end; |
| 248 |
end else |
end |
| 249 |
|
else |
| 250 |
begin |
begin |
| 251 |
_cellG.error('SorIがありません'); |
_cellG.error('SorIがありません'); |
| 252 |
err:=true; |
err := true; |
| 253 |
break; |
break; |
| 254 |
end; |
end; |
|
|
|
| 255 |
end; |
end; |
|
end; |
|
| 256 |
if err = true then |
if err = true then |
| 257 |
begin |
while (token.kind <> CellG._Lbrace) and (token.kind <> CellG._Rbrace) and |
| 258 |
while (token.kind <> CellG._Lbrace)and(token.kind <> CellG._Rbrace)and(token.kind <> CellG._Semicolon) do |
(token.kind <> CellG._Semicolon) do |
| 259 |
begin |
begin |
| 260 |
if token.kind = CellG._Rbrace then |
if token.kind = CellG._Rbrace then |
| 261 |
begin |
begin |
| 262 |
_cellG.error('{ がありません'); |
_cellG.error('{ がありません'); |
| 263 |
_cellG.blockEnd; |
_cellG.blockEnd; |
| 264 |
token:=_cellG.makeToken; |
token := _cellG.makeToken; |
| 265 |
Exit; |
Exit; |
| 266 |
end; |
end; |
| 267 |
token:=_cellG.makeToken; |
token := _cellG.makeToken; |
| 268 |
end; |
end; |
| 269 |
end; |
if (err = false) and (s <> '') then |
| 270 |
if (err = false)and(s <> '') then |
_cellG.checkKari(s); |
| 271 |
begin |
_block; |
|
_cellG.checkKari(s); |
|
|
end; |
|
|
_block; |
|
| 272 |
if x = true then |
if x = true then |
| 273 |
begin |
begin |
| 274 |
_cellV.genCodeRV; |
_cellV.genCodeRV; |
| 275 |
retIS:=true; |
retIS := true; |
| 276 |
end; |
end; |
| 277 |
if retIS = false then |
if retIS = false then |
| 278 |
begin |
_cellG.error('return文がありません'); |
| 279 |
_cellG.error('return文がありません'); |
retIS := false; |
|
end; |
|
|
retIS:=false; |
|
| 280 |
end; |
end; |
| 281 |
|
|
| 282 |
procedure TCellK._expression; |
procedure TCellK._expression; |
| 284 |
sa, saI, saC: integer; |
sa, saI, saC: integer; |
| 285 |
s, ti: integer; |
s, ti: integer; |
| 286 |
begin |
begin |
| 287 |
_expression1; |
_expression1; |
| 288 |
if token.kind <> CellG._Equal then |
if token.kind <> CellG._Equal then |
| 289 |
begin |
Exit; |
|
Exit; |
|
|
end; |
|
| 290 |
if sahen = 0 then |
if sahen = 0 then |
| 291 |
begin |
_cellG.error('代入式が正しくありません。'); |
| 292 |
_cellG.error('代入式が正しくありません。'); |
s := shift; |
| 293 |
end; |
saI := saIndex; |
| 294 |
s:=shift; |
saC := saCode; |
|
saI:=saIndex; |
|
|
saC:=saCode; |
|
| 295 |
if sahen = -1 then |
if sahen = -1 then |
|
begin |
|
| 296 |
if shift = 2 then |
if shift = 2 then |
| 297 |
begin |
begin |
| 298 |
ti:=_cellG.tableString(ident); |
ti := _cellG.tableString(ident); |
| 299 |
sahen:=CellG.strID; |
sahen := CellG.strID; |
| 300 |
_cellV.backPatchL(saC,ti,1); |
_cellV.backPatchL(saC, ti, 1); |
| 301 |
s:=2; |
s := 2; |
| 302 |
end else |
end |
| 303 |
begin |
else |
|
ti:=_cellG.tableInt(ident); |
|
|
sahen:=CellG.intID; |
|
|
_cellV.backPatchL(saC,ti,0); |
|
|
s:=1; |
|
|
end; |
|
|
end; |
|
|
shift:=0; |
|
|
sa:=sahen; |
|
|
token:=_cellG.makeToken; |
|
|
_expression; |
|
|
if (sa <> -1)and(s <> shift) then |
|
|
begin |
|
|
if ((sa = CellG.intID)or(sa = CellG.strID))and(sa <> CellG.arrI)and(sa <> CellG.arrS) then |
|
| 304 |
begin |
begin |
| 305 |
|
ti := _cellG.tableInt(ident); |
| 306 |
|
sahen := CellG.intID; |
| 307 |
|
_cellV.backPatchL(saC, ti, 0); |
| 308 |
|
s := 1; |
| 309 |
|
end; |
| 310 |
|
shift := 0; |
| 311 |
|
sa := sahen; |
| 312 |
|
token := _cellG.makeToken; |
| 313 |
|
_expression; |
| 314 |
|
if (sa <> -1) and (s <> shift) then |
| 315 |
|
if ((sa = CellG.intID) or (sa = CellG.strID)) and (sa <> CellG.arrI) and |
| 316 |
|
(sa <> CellG.arrS) then |
| 317 |
if shift = 2 then |
if shift = 2 then |
| 318 |
begin |
begin |
| 319 |
_cellG.changeT(saI,strID,false); |
_cellG.changeT(saI, strID, false); |
| 320 |
_cellV.backPatchL(saC,saI,1); |
_cellV.backPatchL(saC, saI, 1); |
| 321 |
end else |
end |
| 322 |
begin |
else |
| 323 |
_cellG.changeT(saI,intID,false); |
begin |
| 324 |
_cellV.backPatchL(saC,saI,0); |
_cellG.changeT(saI, intID, false); |
| 325 |
end; |
_cellV.backPatchL(saC, saI, 0); |
| 326 |
end else |
end |
| 327 |
begin |
else |
| 328 |
_cellG.error('型が一致しません'); |
_cellG.error('型が一致しません'); |
|
end; |
|
|
end; |
|
| 329 |
if s <> shift then |
if s <> shift then |
| 330 |
|
if (s = 1) and (con = true) then |
| 331 |
|
shift := 1; |
| 332 |
|
sa := sahen; |
| 333 |
|
if (token.kind = CellG._Rparen) or (token.kind = CellG._Semicolon) then |
| 334 |
begin |
begin |
| 335 |
if (s = 1)and(con = true) then |
if (shift = 2) or ((shift = 0) and (s = 2)) then |
| 336 |
begin |
ti := _cellV.genCodeO(CellV.sls) |
| 337 |
shift:=1; |
else |
| 338 |
end; |
ti := _cellV.genCodeO(CellV.sld); |
| 339 |
end; |
ident := ''; |
| 340 |
sa:=sahen; |
sa := 0; |
| 341 |
if (token.kind = CellG._Rparen)or(token.kind = CellG._Semicolon) then |
end |
| 342 |
begin |
else if (shift = 2) or ((shift = 0) and (s = 2)) then |
| 343 |
if (shift = 2)or((shift = 0)and(s = 2)) then |
ti := _cellV.genCodeO(CellV.sds) |
| 344 |
begin |
else |
| 345 |
ti:=_cellV.genCodeO(CellV.sls); |
ti := _cellV.genCodeO(CellV.sid); |
|
end else |
|
|
begin |
|
|
ti:=_cellV.genCodeO(CellV.sld); |
|
|
end; |
|
|
ident:=''; |
|
|
sa:=0; |
|
|
end else |
|
|
begin |
|
|
if (shift = 2)or((shift = 0)and(s = 2)) then |
|
|
begin |
|
|
ti:=_cellV.genCodeO(CellV.sds); |
|
|
end else |
|
|
begin |
|
|
ti:=_cellV.genCodeO(CellV.sid); |
|
|
end; |
|
|
end; |
|
| 346 |
if sahen = 0 then |
if sahen = 0 then |
| 347 |
begin |
_cellG.setScI(ti); |
| 348 |
_cellG.setScI(ti); |
sahen := sa; |
| 349 |
end; |
saIndex := 0; |
| 350 |
sahen:=sa; |
saCode := 0; |
| 351 |
saIndex:=0; |
con := false; |
|
saCode:=0; |
|
|
con:=false; |
|
| 352 |
end; |
end; |
| 353 |
|
|
| 354 |
procedure TCellK._statement; |
procedure TCellK._statement; |
| 359 |
while true do |
while true do |
| 360 |
begin |
begin |
| 361 |
case token.kind of |
case token.kind of |
| 362 |
CellG._Lbrace: |
CellG._Lbrace: |
|
begin |
|
|
_cellG.blockBegin; |
|
|
_cellV.genCodeP(CellV.dit,_cellG.bLevel); |
|
|
_block; |
|
|
_cellV.genCodeP(CellV.dik,_cellG.bLevel+1); |
|
|
break; |
|
|
end; |
|
|
CellG.Id: |
|
|
begin |
|
|
_expression; |
|
|
token:=_cellG.checkGet(token,CellG._Semicolon); |
|
|
shift:=0; |
|
|
break; |
|
|
end; |
|
|
CellG._Read,CellG._ReadS: |
|
|
begin |
|
|
i:=token.kind; |
|
|
token:=_cellG.makeToken; |
|
|
if token.kind <> CellG.Id then |
|
|
begin |
|
|
_cellG.error('名前がありません'); |
|
|
token:=_cellG.makeToken; |
|
|
continue; |
|
|
end; |
|
|
tIndex:=_cellG.searchT(token.id); |
|
|
tk:=_cellG.tKind(tIndex); |
|
|
if (tk = CellG.strID)or(tk = CellG.parS)or((tk = 0)and(i = CellG._ReadS)) then |
|
|
begin |
|
|
if tk = 0 then |
|
| 363 |
begin |
begin |
| 364 |
tIndex:=_cellG.tableString(token.id); |
_cellG.blockBegin; |
| 365 |
|
_cellV.genCodeP(CellV.dit, _cellG.bLevel); |
| 366 |
|
_block; |
| 367 |
|
_cellV.genCodeP(CellV.dik, _cellG.bLevel + 1); |
| 368 |
|
break; |
| 369 |
end; |
end; |
| 370 |
_cellV.genCodeT(CellV.las,tIndex); |
CellG.Id: |
|
token:=_cellG.makeToken; |
|
|
_cellV.genCodeO(CellV.ins); |
|
|
_cellV.genCodeO(CellV.sds); |
|
|
end else |
|
|
if (tk = CellG.arrI)or(tk = CellG.parI)or(tk = CellG.intID)or |
|
|
(tk = intID)or((tk = 0)and(i = CellG._Read)) then |
|
|
begin |
|
|
if tk = 0 then |
|
| 371 |
begin |
begin |
| 372 |
tIndex:=_cellG.tableInt(token.id); |
_expression; |
| 373 |
|
token := _cellG.checkGet(token, CellG._Semicolon); |
| 374 |
|
shift := 0; |
| 375 |
|
break; |
| 376 |
end; |
end; |
| 377 |
_cellV.genCodeT(CellV.lda,tIndex); |
CellG._Read, CellG._ReadS: |
|
if tk = CellG.arrI then |
|
| 378 |
begin |
begin |
| 379 |
if hairetu(tIndex) = false then |
i := token.kind; |
| 380 |
|
token := _cellG.makeToken; |
| 381 |
|
if token.kind <> CellG.Id then |
| 382 |
begin |
begin |
| 383 |
continue; |
_cellG.error('名前がありません'); |
| 384 |
|
token := _cellG.makeToken; |
| 385 |
|
continue; |
| 386 |
end; |
end; |
| 387 |
end else |
tIndex := _cellG.searchT(token.Id); |
| 388 |
begin |
tk := _cellG.tKind(tIndex); |
| 389 |
token:=_cellG.makeToken; |
if (tk = CellG.strID) or (tk = CellG.parS) or |
| 390 |
end; |
((tk = 0) and (i = CellG._ReadS)) then |
| 391 |
_cellV.genCodeO(CellV.ini); |
begin |
| 392 |
_cellV.genCodeO(CellV.sid); |
if tk = 0 then |
| 393 |
end else |
tIndex := _cellG.tableString(token.Id); |
| 394 |
begin |
_cellV.genCodeT(CellV.las, tIndex); |
| 395 |
_cellG.error('宣言されていません'); |
token := _cellG.makeToken; |
| 396 |
token:=_cellG.makeToken; |
_cellV.genCodeO(CellV.ins); |
| 397 |
continue; |
_cellV.genCodeO(CellV.sds); |
| 398 |
end; |
end |
| 399 |
token:=_cellG.checkGet(token,CellG._Semicolon); |
else if (tk = CellG.arrI) or (tk = CellG.parI) or (tk = CellG.intID) |
| 400 |
break; |
or (tk = intID) or ((tk = 0) and (i = CellG._Read)) then |
| 401 |
end; |
begin |
| 402 |
CellG._Print,CellG._Println: |
if tk = 0 then |
| 403 |
begin |
tIndex := _cellG.tableInt(token.Id); |
| 404 |
tk:=token.kind; |
_cellV.genCodeT(CellV.lda, tIndex); |
| 405 |
repeat |
if tk = CellG.arrI then |
| 406 |
token:=_cellG.makeToken; |
if hairetu(tIndex) = false then |
| 407 |
if (token.kind = CellG._Semicolon)or(token.kind = CellG._Rbrace) then |
continue |
| 408 |
begin |
else |
| 409 |
break; |
token := _cellG.makeToken; |
| 410 |
end; |
_cellV.genCodeO(CellV.ini); |
| 411 |
_expression; |
_cellV.genCodeO(CellV.sid); |
| 412 |
if shift = 2 then |
end |
| 413 |
begin |
else |
| 414 |
_cellV.genCodeO(CellV.prs); |
begin |
| 415 |
end else |
_cellG.error('宣言されていません'); |
| 416 |
begin |
token := _cellG.makeToken; |
| 417 |
_cellV.genCodeO(CellV.prt); |
continue; |
| 418 |
end; |
end; |
| 419 |
shift:=0; |
token := _cellG.checkGet(token, CellG._Semicolon); |
| 420 |
until token.kind <> CellG._Comma; |
break; |
|
if tk = CellG._Println then |
|
|
begin |
|
|
_cellV.genCodeO(CellV.prl); |
|
|
end; |
|
|
token:=_cellG.checkGet(token,CellG._Semicolon); |
|
|
break; |
|
|
end; |
|
|
CellG._If: |
|
|
begin |
|
|
token:=_cellG.checkGet(_cellG.makeToken,CellG._Lparen); |
|
|
_expression; |
|
|
if con = false then |
|
|
begin |
|
|
_cellG.error('条件式が必要です。'); |
|
|
end; |
|
|
con:=false; |
|
|
shift:=0; |
|
|
token:=_cellG.checkGet(token,CellG._Rparen); |
|
|
backP1:=_cellV.genCodeP(CellV.jpc,0); |
|
|
_statement; |
|
|
if token.kind = CellG._Else then |
|
|
begin |
|
|
backP2:=_cellV.genCodeP(CellV.jmp,0); |
|
|
_cellV.backPatchJ(backP1); |
|
|
token:=_cellG.makeToken; |
|
|
_statement; |
|
|
_cellV.backPatchJ(backP2); |
|
|
end else |
|
|
begin |
|
|
_cellV.backPatchJ(backP1); |
|
|
end; |
|
|
break; |
|
|
end; |
|
|
CellG._For: |
|
|
begin |
|
|
token:=_cellG.checkGet(_cellG.makeToken,CellG._Lparen); |
|
|
shift:=1; |
|
|
_expression; |
|
|
token:=_cellG.checkGet(token,CellG._Semicolon); |
|
|
backP2:=_cellV.nextCode; |
|
|
_expression; |
|
|
if con = false then |
|
|
begin |
|
|
_cellG.error('条件式が必要です'); |
|
|
end; |
|
|
con:=false; |
|
|
token:=_cellG.checkGet(token,CellG._Semicolon); |
|
|
backP1:=_cellV.genCodeP(CellV.jpc,0); |
|
|
backP3:=_cellV.genCodeP(CellV.jmp,0); |
|
|
backP4:=_cellV.nextCode; |
|
|
forex:=true; |
|
|
_expression; |
|
|
forex:=false; |
|
|
shift:=0; |
|
|
_cellV.genCodeP(CellV.jmp,backP2); |
|
|
token:=_cellG.checkGet(token,CellG._Rparen); |
|
|
_cellV.backPatchJ(backP3); |
|
|
loop:=true; |
|
|
breTaihi:=breCode; |
|
|
breCode:=0; |
|
|
_statement; |
|
|
_cellV.genCodeP(CellV.jmp,backP4); |
|
|
_cellV.backPatchJ(backP1); |
|
|
_cellV.backBreak(breCode); |
|
|
loop:=false; |
|
|
breCode:=breTaihi; |
|
|
break; |
|
|
end; |
|
|
CellG._While: |
|
|
begin |
|
|
token:=_cellG.checkGet(_cellG.makeToken,CellG._Lparen); |
|
|
backP2:=_cellV.nextCode; |
|
|
_expression; |
|
|
if con = false then |
|
|
begin |
|
|
_cellG.error('条件式が必要です'); |
|
|
end; |
|
|
con:=false; |
|
|
shift:=0; |
|
|
token:=_cellG.checkGet(token,CellG._Rparen); |
|
|
backP1:=_cellV.genCodeP(CellV.jpc,0); |
|
|
loop:=true; |
|
|
breTaihi:=breCode; |
|
|
breCode:=0; |
|
|
_statement; |
|
|
_cellV.genCodeP(CellV.jmp,backP2); |
|
|
_cellV.backPatchJ(backP1); |
|
|
_cellV.backBreak(breCode); |
|
|
loop:=false; |
|
|
breCode:=breTaihi; |
|
|
break; |
|
|
end; |
|
|
CellG._Do: |
|
|
begin |
|
|
backP1:=_cellV.nextCode; |
|
|
token:=_cellG.makeToken; |
|
|
loop:=true; |
|
|
breTaihi:=breCode; |
|
|
_statement; |
|
|
if token.kind <> CellG._While then |
|
|
begin |
|
|
_cellG.error('whileがありません'); |
|
|
continue; |
|
|
end else |
|
|
begin |
|
|
token:=_cellG.makeToken; |
|
|
end; |
|
|
token:=_cellG.checkGet(token,CellG._Lparen); |
|
|
_expression; |
|
|
if con = false then |
|
|
begin |
|
|
_cellG.error('条件式が必要です'); |
|
|
end; |
|
|
con:=false; |
|
|
shift:=0; |
|
|
token:=_cellG.checkGet(token,CellG._Rparen); |
|
|
backP2:=_cellV.genCodeP(CellV.jpc,0); |
|
|
_cellV.genCodeP(CellV.jmp,backP1); |
|
|
_cellV.backPatchJ(backP2); |
|
|
_cellV.backBreak(breCode); |
|
|
loop:=false; |
|
|
breCode:=breTaihi; |
|
|
token:=_cellG.checkGet(token,CellG._Semicolon); |
|
|
break; |
|
|
end; |
|
|
CellG._Return: |
|
|
begin |
|
|
token:=_cellG.makeToken; |
|
|
tk:=_cellG.funcModori; |
|
|
if tk <> CellG._V then |
|
|
begin |
|
|
if (token.kind = CellG._Semicolon)or(token.kind = CellG._Rbrace) then |
|
|
begin |
|
|
_cellG.error('戻り値がありません'); |
|
|
continue; |
|
| 421 |
end; |
end; |
| 422 |
if tk = CellG._S then |
CellG._Print, CellG._Println: |
| 423 |
begin |
begin |
| 424 |
shift:=2; |
tk := token.kind; |
| 425 |
end else |
repeat |
| 426 |
begin |
token := _cellG.makeToken; |
| 427 |
shift:=1; |
if (token.kind = CellG._Semicolon) or (token.kind = CellG._Rbrace) |
| 428 |
|
then |
| 429 |
|
break; |
| 430 |
|
_expression; |
| 431 |
|
if shift = 2 then |
| 432 |
|
_cellV.genCodeO(CellV.prs) |
| 433 |
|
else |
| 434 |
|
_cellV.genCodeO(CellV.prt); |
| 435 |
|
shift := 0; |
| 436 |
|
until token.kind <> CellG._Comma; |
| 437 |
|
if tk = CellG._Println then |
| 438 |
|
_cellV.genCodeO(CellV.prl); |
| 439 |
|
token := _cellG.checkGet(token, CellG._Semicolon); |
| 440 |
|
break; |
| 441 |
|
end; |
| 442 |
|
CellG._If: |
| 443 |
|
begin |
| 444 |
|
token := _cellG.checkGet(_cellG.makeToken, CellG._Lparen); |
| 445 |
|
_expression; |
| 446 |
|
if con = false then |
| 447 |
|
_cellG.error('条件式が必要です。'); |
| 448 |
|
con := false; |
| 449 |
|
shift := 0; |
| 450 |
|
token := _cellG.checkGet(token, CellG._Rparen); |
| 451 |
|
backP1 := _cellV.genCodeP(CellV.jpc, 0); |
| 452 |
|
_statement; |
| 453 |
|
if token.kind = CellG._Else then |
| 454 |
|
begin |
| 455 |
|
backP2 := _cellV.genCodeP(CellV.jmp, 0); |
| 456 |
|
_cellV.backPatchJ(backP1); |
| 457 |
|
token := _cellG.makeToken; |
| 458 |
|
_statement; |
| 459 |
|
_cellV.backPatchJ(backP2); |
| 460 |
|
end |
| 461 |
|
else |
| 462 |
|
_cellV.backPatchJ(backP1); |
| 463 |
|
break; |
| 464 |
|
end; |
| 465 |
|
CellG._For: |
| 466 |
|
begin |
| 467 |
|
token := _cellG.checkGet(_cellG.makeToken, CellG._Lparen); |
| 468 |
|
shift := 1; |
| 469 |
|
_expression; |
| 470 |
|
token := _cellG.checkGet(token, CellG._Semicolon); |
| 471 |
|
backP2 := _cellV.nextCode; |
| 472 |
|
_expression; |
| 473 |
|
if con = false then |
| 474 |
|
_cellG.error('条件式が必要です'); |
| 475 |
|
con := false; |
| 476 |
|
token := _cellG.checkGet(token, CellG._Semicolon); |
| 477 |
|
backP1 := _cellV.genCodeP(CellV.jpc, 0); |
| 478 |
|
backP3 := _cellV.genCodeP(CellV.jmp, 0); |
| 479 |
|
backP4 := _cellV.nextCode; |
| 480 |
|
forex := true; |
| 481 |
|
_expression; |
| 482 |
|
forex := false; |
| 483 |
|
shift := 0; |
| 484 |
|
_cellV.genCodeP(CellV.jmp, backP2); |
| 485 |
|
token := _cellG.checkGet(token, CellG._Rparen); |
| 486 |
|
_cellV.backPatchJ(backP3); |
| 487 |
|
loop := true; |
| 488 |
|
breTaihi := breCode; |
| 489 |
|
breCode := 0; |
| 490 |
|
_statement; |
| 491 |
|
_cellV.genCodeP(CellV.jmp, backP4); |
| 492 |
|
_cellV.backPatchJ(backP1); |
| 493 |
|
_cellV.backBreak(breCode); |
| 494 |
|
loop := false; |
| 495 |
|
breCode := breTaihi; |
| 496 |
|
break; |
| 497 |
|
end; |
| 498 |
|
CellG._While: |
| 499 |
|
begin |
| 500 |
|
token := _cellG.checkGet(_cellG.makeToken, CellG._Lparen); |
| 501 |
|
backP2 := _cellV.nextCode; |
| 502 |
|
_expression; |
| 503 |
|
if con = false then |
| 504 |
|
_cellG.error('条件式が必要です'); |
| 505 |
|
con := false; |
| 506 |
|
shift := 0; |
| 507 |
|
token := _cellG.checkGet(token, CellG._Rparen); |
| 508 |
|
backP1 := _cellV.genCodeP(CellV.jpc, 0); |
| 509 |
|
loop := true; |
| 510 |
|
breTaihi := breCode; |
| 511 |
|
breCode := 0; |
| 512 |
|
_statement; |
| 513 |
|
_cellV.genCodeP(CellV.jmp, backP2); |
| 514 |
|
_cellV.backPatchJ(backP1); |
| 515 |
|
_cellV.backBreak(breCode); |
| 516 |
|
loop := false; |
| 517 |
|
breCode := breTaihi; |
| 518 |
|
break; |
| 519 |
|
end; |
| 520 |
|
CellG._Do: |
| 521 |
|
begin |
| 522 |
|
backP1 := _cellV.nextCode; |
| 523 |
|
token := _cellG.makeToken; |
| 524 |
|
loop := true; |
| 525 |
|
breTaihi := breCode; |
| 526 |
|
_statement; |
| 527 |
|
if token.kind <> CellG._While then |
| 528 |
|
begin |
| 529 |
|
_cellG.error('whileがありません'); |
| 530 |
|
continue; |
| 531 |
|
end |
| 532 |
|
else |
| 533 |
|
token := _cellG.makeToken; |
| 534 |
|
token := _cellG.checkGet(token, CellG._Lparen); |
| 535 |
|
_expression; |
| 536 |
|
if con = false then |
| 537 |
|
_cellG.error('条件式が必要です'); |
| 538 |
|
con := false; |
| 539 |
|
shift := 0; |
| 540 |
|
token := _cellG.checkGet(token, CellG._Rparen); |
| 541 |
|
backP2 := _cellV.genCodeP(CellV.jpc, 0); |
| 542 |
|
_cellV.genCodeP(CellV.jmp, backP1); |
| 543 |
|
_cellV.backPatchJ(backP2); |
| 544 |
|
_cellV.backBreak(breCode); |
| 545 |
|
loop := false; |
| 546 |
|
breCode := breTaihi; |
| 547 |
|
token := _cellG.checkGet(token, CellG._Semicolon); |
| 548 |
|
break; |
| 549 |
|
end; |
| 550 |
|
CellG._Return: |
| 551 |
|
begin |
| 552 |
|
token := _cellG.makeToken; |
| 553 |
|
tk := _cellG.funcModori; |
| 554 |
|
if tk <> CellG._V then |
| 555 |
|
begin |
| 556 |
|
if (token.kind = CellG._Semicolon) or (token.kind = CellG._Rbrace) |
| 557 |
|
then |
| 558 |
|
begin |
| 559 |
|
_cellG.error('戻り値がありません'); |
| 560 |
|
continue; |
| 561 |
|
end; |
| 562 |
|
if tk = CellG._S then |
| 563 |
|
shift := 2 |
| 564 |
|
else |
| 565 |
|
shift := 1; |
| 566 |
|
_expression; |
| 567 |
|
shift := 0; |
| 568 |
|
end; |
| 569 |
|
retIS := true; |
| 570 |
|
_cellV.genCodeR; |
| 571 |
|
token := _cellG.checkGet(token, CellG._Semicolon); |
| 572 |
|
break; |
| 573 |
|
end; |
| 574 |
|
CellG._Break: |
| 575 |
|
begin |
| 576 |
|
if loop = true then |
| 577 |
|
breCode := _cellV.genCodeP(CellV.jmp, breCode) |
| 578 |
|
else |
| 579 |
|
_cellG.error('ループ外です'); |
| 580 |
|
token := _cellG.checkGet(_cellG.makeToken, CellG._Semicolon); |
| 581 |
|
break; |
| 582 |
end; |
end; |
| 583 |
_expression; |
CellG._Rbrace, CellG.dollar: |
|
shift:=0; |
|
|
end; |
|
|
retIS:=true; |
|
|
_cellV.genCodeR; |
|
|
token:=_cellG.checkGet(token,CellG._Semicolon); |
|
|
break; |
|
|
end; |
|
|
CellG._Break: |
|
|
begin |
|
|
if loop = true then |
|
|
begin |
|
|
breCode:=_cellV.genCodeP(CellV.jmp,breCode); |
|
|
end else |
|
|
begin |
|
|
_cellG.error('ループ外です'); |
|
|
end; |
|
|
token:=_cellG.checkGet(_cellG.makeToken,CellG._Semicolon); |
|
|
break; |
|
|
end; |
|
|
CellG._Rbrace,CellG.dollar: |
|
| 584 |
continue; |
continue; |
| 585 |
else |
else |
| 586 |
token:=_cellG.makeToken; |
token := _cellG.makeToken; |
| 587 |
end; |
end; |
| 588 |
end; |
end; |
| 589 |
end; |
end; |
| 592 |
var |
var |
| 593 |
k: integer; |
k: integer; |
| 594 |
begin |
begin |
| 595 |
_expression; |
_expression; |
| 596 |
k:=token.kind; |
k := token.kind; |
| 597 |
token:=_cellG.makeToken; |
token := _cellG.makeToken; |
| 598 |
_expression; |
_expression; |
| 599 |
case k of |
case k of |
| 600 |
CellG._Equal2: |
CellG._Equal2: |
| 601 |
_cellV.genCodeO(CellV.eql); |
_cellV.genCodeO(CellV.eql); |
| 602 |
CellG._NotEq: |
CellG._NotEq: |
| 603 |
_cellV.genCodeO(CellV.neq); |
_cellV.genCodeO(CellV.neq); |
| 604 |
CellG._Lss: |
CellG._Lss: |
| 605 |
_cellV.genCodeO(CellV.lss); |
_cellV.genCodeO(CellV.lss); |
| 606 |
CellG._Gtr: |
CellG._Gtr: |
| 607 |
_cellV.genCodeO(CellV.gtr); |
_cellV.genCodeO(CellV.gtr); |
| 608 |
CellG._LssEq: |
CellG._LssEq: |
| 609 |
_cellV.genCodeO(CellV.leq); |
_cellV.genCodeO(CellV.leq); |
| 610 |
CellG._GtrEq: |
CellG._GtrEq: |
| 611 |
_cellV.genCodeO(CellV.geq); |
_cellV.genCodeO(CellV.geq); |
| 612 |
else |
else |
| 613 |
_cellG.error('条件式に誤りがあります'); |
_cellG.error('条件式に誤りがあります'); |
| 614 |
end; |
end; |
| 615 |
end; |
end; |
| 616 |
|
|
| 619 |
k: integer; |
k: integer; |
| 620 |
x: Boolean; |
x: Boolean; |
| 621 |
begin |
begin |
| 622 |
_factor; |
_factor; |
| 623 |
while (token.kind = CellG._Mult)or(token.kind = CellG._Div) do |
while (token.kind = CellG._Mult) or (token.kind = CellG._Div) do |
| 624 |
begin |
begin |
| 625 |
k:=token.kind; |
k := token.kind; |
| 626 |
token:=_cellG.makeToken; |
token := _cellG.makeToken; |
| 627 |
if (shift = 2)and(k = CellG._Mult) then |
if (shift = 2) and (k = CellG._Mult) then |
| 628 |
begin |
begin |
| 629 |
x:=true; |
x := true; |
| 630 |
shift:=1; |
shift := 1; |
| 631 |
end else |
end |
| 632 |
begin |
else |
| 633 |
x:=false; |
x := false; |
| 634 |
end; |
_factor; |
|
_factor; |
|
| 635 |
if x = true then |
if x = true then |
| 636 |
begin |
shift := 2; |
|
shift:=2; |
|
|
end; |
|
| 637 |
if shift = 1 then |
if shift = 1 then |
| 638 |
begin |
begin |
| 639 |
if k = CellG._Mult then |
if k = CellG._Mult then |
| 640 |
begin |
_cellV.genCodeO(CellV._mul) |
| 641 |
_cellV.genCodeO(CellV._mul); |
else |
| 642 |
end else |
_cellV.genCodeO(CellV._Div); |
| 643 |
begin |
end |
| 644 |
_cellV.genCodeO(CellV._div); |
else if k = CellG._Mult then |
| 645 |
end; |
_cellV.genCodeO(CellV.mus) |
| 646 |
end else |
else |
| 647 |
begin |
_cellV.genCodeO(CellV.dis); |
| 648 |
if k = CellG._Mult then |
sahen := 0; |
|
begin |
|
|
_cellV.genCodeO(CellV.mus); |
|
|
end else |
|
|
begin |
|
|
_cellV.genCodeO(CellV.dis); |
|
|
end; |
|
|
end; |
|
|
sahen:=0; |
|
| 649 |
end; |
end; |
| 650 |
end; |
end; |
| 651 |
|
|
| 658 |
begin |
begin |
| 659 |
if token.kind = CellG.Num then |
if token.kind = CellG.Num then |
| 660 |
begin |
begin |
| 661 |
checkKata(1); |
checkKata(1); |
| 662 |
_cellV.genCodeV(CellV.lit,token.value); |
_cellV.genCodeV(CellV.lit, token.value); |
| 663 |
token:=_cellG.makeToken; |
token := _cellG.makeToken; |
| 664 |
end else |
end |
| 665 |
if token.kind = CellG.Moji then |
else if token.kind = CellG.Moji then |
| 666 |
begin |
begin |
| 667 |
checkKata(2); |
checkKata(2); |
| 668 |
_cellV.genCodeS(CellV.lis,token.id); |
_cellV.genCodeS(CellV.lis, token.Id); |
| 669 |
token:=_cellG.makeToken; |
token := _cellG.makeToken; |
| 670 |
end else |
end |
| 671 |
if token.kind = CellG._Lparen then |
else if token.kind = CellG._Lparen then |
| 672 |
begin |
begin |
| 673 |
token:=_cellG.makeToken; |
token := _cellG.makeToken; |
| 674 |
_expression; |
_expression; |
| 675 |
token:=_cellG.checkGet(token,CellG._Rparen); |
token := _cellG.checkGet(token, CellG._Rparen); |
| 676 |
end else |
end |
| 677 |
if (token.kind = CellG._Plus)or(token.kind = CellG._Minus) then |
else if (token.kind = CellG._Plus) or (token.kind = CellG._Minus) then |
| 678 |
begin |
begin |
| 679 |
checkKata(1); |
checkKata(1); |
| 680 |
k:=token.kind; |
k := token.kind; |
| 681 |
token:=_cellG.makeToken; |
token := _cellG.makeToken; |
| 682 |
_factor; |
_factor; |
| 683 |
if k = CellG._Minus then |
if k = CellG._Minus then |
| 684 |
begin |
_cellV.genCodeO(CellV.neg); |
| 685 |
_cellV.genCodeO(CellV.neg); |
end |
| 686 |
end; |
else if token.kind = CellG.Id then |
|
end else |
|
|
if token.kind = CellG.Id then |
|
| 687 |
begin |
begin |
| 688 |
tIndex:=_cellG.searchT(token.id); |
tIndex := _cellG.searchT(token.Id); |
| 689 |
k:=_cellG.tKind(tIndex); |
k := _cellG.tKind(tIndex); |
| 690 |
case k of |
case k of |
| 691 |
CellG.funID,0: |
CellG.funID, 0: |
|
begin |
|
|
s:=_cellG.moduleName; |
|
|
t:=token.id; |
|
|
if k = 0 then |
|
|
begin |
|
|
token:=_cellG.makeToken; |
|
|
if (token.kind <> CellG._Period)and(token.kind <> CellG._Lparen) then |
|
| 692 |
begin |
begin |
| 693 |
if token.kind = CellG._Equal then |
s := _cellG.moduleName; |
| 694 |
begin |
t := token.Id; |
| 695 |
sahen:=-1; |
if k = 0 then |
| 696 |
ident:=t; |
begin |
| 697 |
saIndex:=_cellG.nextTIndex; |
token := _cellG.makeToken; |
| 698 |
saCode:=_cellV.genCodeT(CellV.lda,0); |
if (token.kind <> CellG._Period) and (token.kind <> CellG._Lparen) |
| 699 |
end else |
then |
| 700 |
begin |
begin |
| 701 |
|
if token.kind = CellG._Equal then |
| 702 |
|
begin |
| 703 |
|
sahen := -1; |
| 704 |
|
ident := t; |
| 705 |
|
saIndex := _cellG.nextTIndex; |
| 706 |
|
saCode := _cellV.genCodeT(CellV.lda, 0); |
| 707 |
|
end |
| 708 |
|
else |
| 709 |
_cellG.error('初期化されていません'); |
_cellG.error('初期化されていません'); |
| 710 |
end; |
Exit; |
| 711 |
Exit; |
end |
| 712 |
end else |
else if token.kind = CellG._Period then |
| 713 |
if token.kind = CellG._Period then |
begin |
| 714 |
begin |
token := _cellG.makeToken; |
| 715 |
token:=_cellG.makeToken; |
if token.kind <> CellG.Id then |
| 716 |
if token.kind <> CellG.Id then |
begin |
|
begin |
|
| 717 |
_cellG.error('名前がありません'); |
_cellG.error('名前がありません'); |
| 718 |
Exit; |
Exit; |
| 719 |
end; |
end; |
| 720 |
s:=t; |
s := t; |
| 721 |
t:=token.id; |
t := token.Id; |
| 722 |
tIndex:=_cellG.searchFModule(s,t); |
tIndex := _cellG.searchFModule(s, t); |
| 723 |
token:=_cellG.makeToken; |
token := _cellG.makeToken; |
| 724 |
end; |
end; |
| 725 |
end else |
end |
| 726 |
begin |
else |
| 727 |
token:=_cellG.makeToken; |
token := _cellG.makeToken; |
| 728 |
end; |
pi := 0; |
| 729 |
pi:=0; |
ps := 0; |
| 730 |
ps:=0; |
sa := sahen; |
| 731 |
sa:=sahen; |
saI := saIndex; |
| 732 |
saI:=saIndex; |
saC := saCode; |
| 733 |
saC:=saCode; |
token := _cellG.checkGet(token, CellG._Lparen); |
| 734 |
token:=_cellG.checkGet(token,CellG._Lparen); |
if token.kind <> CellG._Rparen then |
| 735 |
if token.kind <> CellG._Rparen then |
begin |
| 736 |
begin |
i := shift; |
| 737 |
i:=shift; |
shift := 0; |
| 738 |
shift:=0; |
while true do |
| 739 |
while true do |
begin |
| 740 |
begin |
_expression; |
| 741 |
_expression; |
if shift = 1 then |
| 742 |
if shift = 1 then |
inc(pi) |
| 743 |
begin |
else |
|
inc(pi); |
|
|
end else |
|
|
begin |
|
| 744 |
inc(ps); |
inc(ps); |
| 745 |
end; |
shift := 0; |
| 746 |
shift:=0; |
if token.kind = CellG._Comma then |
| 747 |
if token.kind = CellG._Comma then |
begin |
| 748 |
begin |
token := _cellG.makeToken; |
|
token:=_cellG.makeToken; |
|
| 749 |
continue; |
continue; |
| 750 |
|
end; |
| 751 |
|
token := _cellG.checkGet(token, CellG._Rparen); |
| 752 |
|
break; |
| 753 |
|
end; |
| 754 |
|
shift := i; |
| 755 |
|
end |
| 756 |
|
else |
| 757 |
|
token := _cellG.makeToken; |
| 758 |
|
if tIndex = 0 then |
| 759 |
|
begin |
| 760 |
|
i := _cellV.genCodeC(0, 0); |
| 761 |
|
if sa = -1 then |
| 762 |
|
sa := CellG.intID; |
| 763 |
|
_cellG.setKariTable(t, s, sa, saI, saC, pi, ps, i); |
| 764 |
|
sahen := 0; |
| 765 |
|
Exit; |
| 766 |
end; |
end; |
| 767 |
token:=_cellG.checkGet(token,CellG._Rparen); |
if _cellG.pKazuI(tIndex) <> pi then |
| 768 |
break; |
_cellG.error('引数の数が合いません(I)'); |
| 769 |
end; |
if _cellG.pKazuS(tIndex) <> ps then |
| 770 |
shift:=i; |
_cellG.error('引数の数が合いません(S)'); |
| 771 |
end else |
i := _cellG.fModori(tIndex); |
| 772 |
begin |
if i = CellG._S then |
| 773 |
token:=_cellG.makeToken; |
checkKata(2) |
| 774 |
end; |
else if i = CellG._I then |
| 775 |
if tIndex = 0 then |
checkKata(1) |
| 776 |
begin |
else |
| 777 |
i:=_cellV.genCodeC(0,0); |
checkKata(0); |
| 778 |
if sa = -1 then |
p := _cellG.tAddr(tIndex); |
| 779 |
begin |
_cellV.genCodeC(p.level, p.addr); |
| 780 |
sa:=CellG.intID; |
sahen := 0; |
| 781 |
end; |
end; |
|
_cellG.setKariTable(t,s,sa,saI,saC,pi,ps,i); |
|
|
sahen:=0; |
|
|
Exit; |
|
|
end; |
|
|
if _cellG.pKazuI(tIndex) <> pi then |
|
|
begin |
|
|
_cellG.error('引数の数が合いません(I)'); |
|
|
end; |
|
|
if _cellG.pKazuS(tIndex) <> ps then |
|
|
begin |
|
|
_cellG.error('引数の数が合いません(S)'); |
|
|
end; |
|
|
i:=_cellG.fModori(tIndex); |
|
|
if i = CellG._S then |
|
|
begin |
|
|
checkKata(2); |
|
|
end else |
|
|
if i = CellG._I then |
|
|
begin |
|
|
checkKata(1); |
|
|
end else |
|
|
begin |
|
|
checkKata(0); |
|
|
end; |
|
|
p:=_cellG.tAddr(tIndex); |
|
|
_cellV.genCodeC(p.level,p.addr); |
|
|
sahen:=0; |
|
|
end; |
|
| 782 |
else |
else |
| 783 |
|
sahen := k; |
| 784 |
sahen:=k; |
saIndex := tIndex; |
| 785 |
saIndex:=tIndex; |
_Sa; |
| 786 |
_Sa; |
i := token.kind; |
| 787 |
i:=token.kind; |
if (i = CellG._Plus2) or (i = CellG._Minus2) then |
| 788 |
if (i = CellG._Plus2)or(i = CellG._Minus2) then |
begin |
| 789 |
begin |
sahen := 0; |
| 790 |
sahen:=0; |
token := _cellG.makeToken; |
| 791 |
token:=_cellG.makeToken; |
if (k = CellG.intID) or (k = CellG.parI) or (k = CellG.arrI) then |
|
if (k = CellG.intID)or(k = CellG.parI)or(k = CellG.arrI) then |
|
| 792 |
begin |
begin |
| 793 |
if k = CellG.arrI then |
if k = CellG.arrI then |
| 794 |
begin |
begin |
| 795 |
if (token.kind = CellG._Rparen)and(forex = true) then |
if (token.kind = CellG._Rparen) and (forex = true) then |
|
begin |
|
|
if i = CellG._Plus2 then |
|
|
begin |
|
|
_cellV.genCodeO(CellV._inc); |
|
|
end else |
|
|
begin |
|
|
_cellV.genCodeO(CellV._dec); |
|
|
end; |
|
|
end else |
|
|
begin |
|
|
|
|
| 796 |
if i = CellG._Plus2 then |
if i = CellG._Plus2 then |
| 797 |
begin |
_cellV.genCodeO(CellV._inc) |
| 798 |
_cellV.genCodeO(CellV.lin); |
else |
| 799 |
end else |
_cellV.genCodeO(CellV._dec) |
| 800 |
begin |
else if i = CellG._Plus2 then |
| 801 |
_cellV.genCodeO(CellV.lde); |
_cellV.genCodeO(CellV.lin) |
| 802 |
end; |
else |
| 803 |
|
_cellV.genCodeO(CellV.lde); |
| 804 |
end; |
end |
| 805 |
end else |
else |
| 806 |
begin |
begin |
| 807 |
|
if (token.kind <> CellG._Rparen) or (forex = false) then |
| 808 |
if (token.kind <> CellG._Rparen)or(forex = false) then |
_cellV.genCodeT(CellV.lod, tIndex); |
| 809 |
begin |
_cellV.genCodeT(CellV.lda, tIndex); |
|
_cellV.genCodeT(CellV.lod,tIndex); |
|
|
end; |
|
|
_cellV.genCodeT(CellV.lda,tIndex); |
|
| 810 |
if i = CellG._Plus2 then |
if i = CellG._Plus2 then |
| 811 |
begin |
_cellV.genCodeO(CellV.lin) |
| 812 |
_cellV.genCodeO(CellV.lin); |
else |
| 813 |
end else |
_cellV.genCodeO(CellV.lde); |
|
begin |
|
|
_cellV.genCodeO(CellV.lde); |
|
|
end; |
|
|
|
|
| 814 |
end; |
end; |
| 815 |
end else |
end |
| 816 |
begin |
else |
| 817 |
_cellG.error('型に誤りがあります'); |
_cellG.error('型に誤りがあります'); |
|
end; |
|
| 818 |
end; |
end; |
|
|
|
| 819 |
end; |
end; |
| 820 |
end else |
end |
| 821 |
begin |
else |
| 822 |
_cellG.error('入力が正しくありません'); |
_cellG.error('入力が正しくありません'); |
|
end; |
|
| 823 |
end; |
end; |
| 824 |
|
|
| 825 |
function TCellK.hairetu(const ti: integer): Boolean; |
function TCellK.hairetu(const ti: integer): Boolean; |
| 826 |
var |
var |
| 827 |
i, j, sa: integer; |
i, j, sa: integer; |
| 828 |
begin |
begin |
| 829 |
sa:=sahen; |
sa := sahen; |
| 830 |
token:=_cellG.checkGet(_cellG.makeToken,CellG._Lbracket); |
token := _cellG.checkGet(_cellG.makeToken, CellG._Lbracket); |
| 831 |
_expression; |
_expression; |
| 832 |
if token.kind = CellG._Rbracket then |
if token.kind = CellG._Rbracket then |
| 833 |
begin |
begin |
| 834 |
token:=_cellG.makeToken; |
token := _cellG.makeToken; |
| 835 |
i:=1; |
i := 1; |
| 836 |
j:=CellV.adv; |
j := CellV.adv; |
| 837 |
end else |
end |
| 838 |
if token.kind = CellG._Ex then |
else if token.kind = CellG._Ex then |
| 839 |
begin |
begin |
| 840 |
token:=_cellG.makeToken; |
token := _cellG.makeToken; |
| 841 |
_expression; |
_expression; |
| 842 |
token:=_cellG.checkGet(token,CellG._Rbracket); |
token := _cellG.checkGet(token, CellG._Rbracket); |
| 843 |
i:=2; |
i := 2; |
| 844 |
j:=CellV.arr; |
j := CellV.arr; |
| 845 |
end else |
end |
| 846 |
|
else |
| 847 |
begin |
begin |
| 848 |
_cellG.error(']or! がありません'); |
_cellG.error(']or! がありません'); |
| 849 |
shift:=0; |
shift := 0; |
| 850 |
result:=false; |
result := false; |
| 851 |
Exit; |
Exit; |
| 852 |
end; |
end; |
| 853 |
sahen:=sa; |
sahen := sa; |
| 854 |
_cellV.genCodeA(j,_cellG.hairetu(ti)); |
_cellV.genCodeA(j, _cellG.hairetu(ti)); |
| 855 |
if _cellG.jigen(ti) <> i then |
if _cellG.jigen(ti) <> i then |
| 856 |
begin |
begin |
| 857 |
_cellG.error('配列の次元が一致しません'); |
_cellG.error('配列の次元が一致しません'); |
| 858 |
result:=false; |
result := false; |
| 859 |
end else |
end |
| 860 |
begin |
else |
| 861 |
result:=true; |
result := true; |
|
end; |
|
| 862 |
end; |
end; |
| 863 |
|
|
| 864 |
procedure TCellK._expression1; |
procedure TCellK._expression1; |
| 865 |
var |
var |
| 866 |
k, s: integer; |
k, s: integer; |
| 867 |
begin |
begin |
| 868 |
_expression2; |
_expression2; |
| 869 |
k:=token.kind; |
k := token.kind; |
| 870 |
if (k <> CellG._Equal2)and(k <> CellG._NotEq)and(k <> CellG._Lss)and(k <> CellG._Gtr)and |
if (k <> CellG._Equal2) and (k <> CellG._NotEq) and (k <> CellG._Lss) and |
| 871 |
(k <> CellG._LssEq)and(k <> CellG._GtrEq) then |
(k <> CellG._Gtr) and (k <> CellG._LssEq) and (k <> CellG._GtrEq) then |
| 872 |
begin |
Exit; |
| 873 |
Exit; |
sahen := 0; |
| 874 |
end; |
s := shift; |
| 875 |
sahen:=0; |
shift := 0; |
| 876 |
s:=shift; |
token := _cellG.makeToken; |
| 877 |
shift:=0; |
_expression2; |
|
token:=_cellG.makeToken; |
|
|
_expression2; |
|
| 878 |
if s <> shift then |
if s <> shift then |
| 879 |
|
_cellG.error('比較するものの型が一致しません。'); |
| 880 |
|
if (s = 2) and ((k <> CellG._Equal2) or (k <> CellG._NotEq)) then |
| 881 |
begin |
begin |
| 882 |
_cellG.error('比較するものの型が一致しません。'); |
_cellG.error('文字の大小比較はできません。'); |
| 883 |
end; |
Exit; |
|
if (s = 2)and((k <> CellG._Equal2)or(k <> CellG._NotEq)) then |
|
|
begin |
|
|
_cellG.error('文字の大小比較はできません。'); |
|
|
Exit; |
|
| 884 |
end; |
end; |
| 885 |
case k of |
case k of |
| 886 |
CellG._Equal2: |
CellG._Equal2: |
| 887 |
if s = 2 then |
if s = 2 then |
| 888 |
begin |
_cellV.genCodeO(CellV.eqs) |
| 889 |
_cellV.genCodeO(CellV.eqs); |
else |
|
end else |
|
|
begin |
|
| 890 |
_cellV.genCodeO(CellV.eql); |
_cellV.genCodeO(CellV.eql); |
| 891 |
end; |
CellG._NotEq: |
| 892 |
CellG._NotEq: |
if s = 2 then |
| 893 |
if s = 2 then |
_cellV.genCodeO(CellV.nes) |
| 894 |
begin |
else |
|
_cellV.genCodeO(CellV.nes); |
|
|
end else |
|
|
begin |
|
| 895 |
_cellV.genCodeO(CellV.neq); |
_cellV.genCodeO(CellV.neq); |
| 896 |
end; |
CellG._Lss: |
| 897 |
CellG._Lss: |
_cellV.genCodeO(CellV.lss); |
| 898 |
_cellV.genCodeO(CellV.lss); |
CellG._Gtr: |
| 899 |
CellG._Gtr: |
_cellV.genCodeO(CellV.gtr); |
| 900 |
_cellV.genCodeO(CellV.gtr); |
CellG._LssEq: |
| 901 |
CellG._LssEq: |
_cellV.genCodeO(CellV.leq); |
| 902 |
_cellV.genCodeO(CellV.leq); |
CellG._GtrEq: |
| 903 |
CellG._GtrEq: |
_cellV.genCodeO(CellV.geq); |
|
_cellV.genCodeO(CellV.geq); |
|
| 904 |
end; |
end; |
| 905 |
con:=true; |
con := true; |
| 906 |
end; |
end; |
| 907 |
|
|
| 908 |
procedure TCellK._expression2; |
procedure TCellK._expression2; |
| 909 |
var |
var |
| 910 |
k: integer; |
k: integer; |
| 911 |
begin |
begin |
| 912 |
_term; |
_term; |
| 913 |
k:=token.kind; |
k := token.kind; |
| 914 |
while (token.kind = CellG._Plus)or(token.kind = CellG._Minus) do |
while (token.kind = CellG._Plus) or (token.kind = CellG._Minus) do |
| 915 |
begin |
begin |
| 916 |
token:=_cellG.makeToken; |
token := _cellG.makeToken; |
| 917 |
_term; |
_term; |
| 918 |
if shift = 1 then |
if shift = 1 then |
|
begin |
|
| 919 |
if k = CellG._Plus then |
if k = CellG._Plus then |
| 920 |
begin |
_cellV.genCodeO(CellV._add) |
| 921 |
_cellV.genCodeO(CellV._add); |
else |
| 922 |
end else |
_cellV.genCodeO(CellV._sub) |
| 923 |
begin |
else if k = CellG._Plus then |
| 924 |
_cellV.genCodeO(CellV._sub); |
_cellV.genCodeO(CellV.ads) |
| 925 |
end; |
else |
| 926 |
end else |
_cellV.genCodeO(CellV.sus); |
|
begin |
|
|
|
|
|
if k = CellG._Plus then |
|
|
begin |
|
|
_cellV.genCodeO(CellV.ads); |
|
|
end else |
|
|
begin |
|
|
_cellV.genCodeO(CellV.sus); |
|
|
end; |
|
|
|
|
|
end; |
|
| 927 |
end; |
end; |
| 928 |
end; |
end; |
| 929 |
|
|
| 930 |
procedure TCellK.checkKata(t: integer); |
procedure TCellK.checkKata(t: integer); |
| 931 |
begin |
begin |
| 932 |
if shift = 0 then |
if shift = 0 then |
| 933 |
begin |
shift := t |
| 934 |
shift:=t; |
else if t <> shift then |
| 935 |
end else |
_cellG.error('型が一致しません。'); |
|
if t <> shift then |
|
|
begin |
|
|
_cellG.error('型が一致しません。'); |
|
|
end; |
|
| 936 |
end; |
end; |
| 937 |
|
|
| 938 |
procedure TCellK._Sa; |
procedure TCellK._Sa; |
| 939 |
begin |
begin |
| 940 |
case sahen of |
case sahen of |
| 941 |
CellG.intID,CellG.parI: |
CellG.intID, CellG.parI: |
| 942 |
begin |
begin |
| 943 |
checkKata(1); |
checkKata(1); |
| 944 |
token:=_cellG.makeToken; |
token := _cellG.makeToken; |
| 945 |
if token.kind = CellG._Equal then |
if token.kind = CellG._Equal then |
| 946 |
begin |
saCode := _cellV.genCodeT(CellV.lda, saIndex) |
| 947 |
saCode:=_cellV.genCodeT(CellV.lda,saIndex); |
else if (token.kind <> CellG._Plus2) and (token.kind <> CellG._Minus2) |
| 948 |
end else |
then |
| 949 |
if (token.kind <> CellG._Plus2)and(token.kind <> CellG._Minus2) then |
_cellV.genCodeT(CellV.lod, saIndex); |
| 950 |
begin |
end; |
| 951 |
_cellV.genCodeT(CellV.lod,saIndex); |
CellG.strID, CellG.parS: |
| 952 |
end; |
begin |
|
end; |
|
|
CellG.strID,CellG.parS: |
|
|
begin |
|
| 953 |
checkKata(2); |
checkKata(2); |
| 954 |
token:=_cellG.makeToken; |
token := _cellG.makeToken; |
| 955 |
if token.kind = CellG._Equal then |
if token.kind = CellG._Equal then |
| 956 |
begin |
saCode := _cellV.genCodeT(CellV.las, saIndex) |
| 957 |
saCode:=_cellV.genCodeT(CellV.las,saIndex); |
else if (token.kind <> CellG._Plus2) or (token.kind <> CellG._Minus2) |
| 958 |
end else |
then |
| 959 |
if (token.kind <> CellG._Plus2)or(token.kind <> CellG._Minus2) then |
_cellV.genCodeT(CellV.los, saIndex); |
| 960 |
begin |
end; |
| 961 |
_cellV.genCodeT(CellV.los,saIndex); |
CellG.arrI: |
|
end; |
|
|
end; |
|
|
CellG.arrI: |
|
|
begin |
|
|
checkKata(1); |
|
|
_cellV.genCodeT(CellV.lda,saIndex); |
|
|
if hairetu(saIndex) = true then |
|
|
begin |
|
|
if (token.kind <> CellG._Equal2)and(token.kind <> CellG._Plus2)and(token.kind <> CellG._Minus2) then |
|
| 962 |
begin |
begin |
| 963 |
_cellV.genCodeO(CellV.lod); |
checkKata(1); |
| 964 |
|
_cellV.genCodeT(CellV.lda, saIndex); |
| 965 |
|
if hairetu(saIndex) = true then |
| 966 |
|
if (token.kind <> CellG._Equal2) and (token.kind <> CellG._Plus2) and |
| 967 |
|
(token.kind <> CellG._Minus2) then |
| 968 |
|
_cellV.genCodeO(CellV.lod); |
| 969 |
|
shift := 1; |
| 970 |
end; |
end; |
| 971 |
end; |
CellG.arrS: |
|
shift:=1; |
|
|
end; |
|
|
CellG.arrS: |
|
|
begin |
|
|
checkKata(2); |
|
|
_cellV.genCodeT(CellV.lda,saIndex); |
|
|
if hairetu(saIndex) = true then |
|
|
begin |
|
|
if (token.kind <> CellG._Equal2)and(token.kind <> CellG._Plus2)and(token.kind <> CellG._Minus2) then |
|
| 972 |
begin |
begin |
| 973 |
_cellV.genCodeO(CellV.lds); |
checkKata(2); |
| 974 |
|
_cellV.genCodeT(CellV.lda, saIndex); |
| 975 |
|
if hairetu(saIndex) = true then |
| 976 |
|
if (token.kind <> CellG._Equal2) and (token.kind <> CellG._Plus2) and |
| 977 |
|
(token.kind <> CellG._Minus2) then |
| 978 |
|
_cellV.genCodeO(CellV.lds); |
| 979 |
|
shift := 2; |
| 980 |
end; |
end; |
|
end; |
|
|
shift:=2; |
|
|
end; |
|
| 981 |
end; |
end; |
| 982 |
end; |
end; |
| 983 |
|
|
| 984 |
procedure TCellK.shokika; |
procedure TCellK.shokika; |
| 985 |
begin |
begin |
| 986 |
con:=false; |
con := false; |
| 987 |
saIndex:=0; |
saIndex := 0; |
| 988 |
saCode:=0; |
saCode := 0; |
| 989 |
breCode:=0; |
breCode := 0; |
| 990 |
retIS:=false; |
retIS := false; |
| 991 |
loop:=false; |
loop := false; |
| 992 |
shift:=0; |
shift := 0; |
| 993 |
sahen:=-1; |
sahen := -1; |
| 994 |
ident:=''; |
ident := ''; |
| 995 |
forex:=false; |
forex := false; |
| 996 |
end; |
end; |
| 997 |
|
|
| 998 |
end. |
end. |