Changeset 220 for branches/CpuSingleSize/UAssembler.pas
- Timestamp:
- Oct 20, 2020, 1:10:09 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/CpuSingleSize/UAssembler.pas
r219 r220 25 25 FOnError: TErrorEvent; 26 26 Parser: TParser; 27 function ParseVar: Boolean; 27 28 function ParseDb: Boolean; 28 29 function ParseOrg: Boolean; … … 36 37 Labels: TDictionary<string, Integer>; 37 38 LabelRefs: TList<TLabelRef>; 39 Variables: TDictionary<string, Integer>; 38 40 Messages: TMessages; 39 41 procedure Error(Text: string; Pos: TPoint); … … 81 83 end else 82 84 if Token.Kind = tkIdentifier then begin; 85 if Variables.TryGetValue(Token.Value, Addr) then begin 86 Memory.Write(Addr); 87 end else 83 88 if Labels.TryGetValue(Token.Value, Addr) then begin 84 89 Memory.Write(Addr); … … 107 112 while not Parser.CheckNextKind(tkEof) do begin 108 113 ParseLabel; 114 if ParseVar then begin 115 end else 109 116 if ParseDb then begin 110 117 end else … … 119 126 UpdateLabelRefs; 120 127 Error('Compilation finished.', Point(0, 0)); 128 end; 129 130 function TAssembler.ParseVar: Boolean; 131 var 132 TokenName: TToken; 133 TokenValue: TToken; 134 Number: TInteger; 135 begin 136 Result := False; 137 if Parser.CheckNextAndRead(tkIdentifier, 'VAR') then begin 138 Result := True; 139 while True do begin 140 TokenName := Parser.ReadNext; 141 if TokenName.Kind = tkIdentifier then begin 142 TokenValue := Parser.ReadNext; 143 if TokenValue.Kind = tkNumber then begin 144 if not Labels.ContainsKey(TokenName.Value) then begin 145 if TryStrToInt(TokenValue.Value, Number) then 146 Variables.Add(TokenName.Value, Number) 147 else Error('Expected number', TokenValue.Pos); 148 end else Error('Duplicate variable name ' + TokenName.Value, TokenName.Pos); 149 end else Error('Expected variable value.', TokenValue.Pos); 150 end else Error('Expected variable name.', TokenName.Pos); 151 if Parser.CheckNextAndRead(tkSpecialSymbol, ',') then begin 152 Continue; 153 end; 154 Break; 155 end; 156 end; 121 157 end; 122 158 … … 212 248 Parser.Expect(tkSpecialSymbol, ')'); 213 249 end else 250 if InstructionInfo.Params[I] = ptRegIndirectGroup then begin 251 Parser.Expect(tkSpecialSymbol, '('); 252 Token := Parser.ReadNext; 253 if (Token.Value <> '') and (Token.Value[1] = 'R') then begin 254 Token.Value := Copy(Token.Value, 2, MaxInt); 255 if TryStrToInt(Token.Value, Number) then begin 256 Memory.Write(Number); 257 Parser.Expect(tkSpecialSymbol, ':'); 258 Token := Parser.ReadNext; 259 if (Token.Value <> '') and (Token.Value[1] = 'R') then begin 260 Token.Value := Copy(Token.Value, 2, MaxInt); 261 if TryStrToInt(Token.Value, Number) then begin 262 Memory.Write(Number); 263 end else Error('Expected numeric register index error', Token.Pos); 264 end else Error('Expected register name starting with R character.', Token.Pos); 265 end else Error('Expected numeric register index error', Token.Pos); 266 end else Error('Expected register name starting with R character.', Token.Pos); 267 Parser.Expect(tkSpecialSymbol, ')'); 268 end else 214 269 end; 215 270 end; … … 271 326 Labels := TDictionary<string, Integer>.Create; 272 327 LabelRefs := TList<TLabelRef>.Create; 328 Variables := TDictionary<string, Integer>.Create; 273 329 end; 274 330 275 331 destructor TAssembler.Destroy; 276 332 begin 333 FreeAndNil(Variables); 277 334 FreeAndNil(Labels); 278 335 FreeAndNil(LabelRefs);
Note:
See TracChangeset
for help on using the changeset viewer.