Changeset 99 for branches/interpreter/Source3.pas
- Timestamp:
- Feb 6, 2017, 12:11:54 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/interpreter/Source3.pas
r98 r99 6 6 7 7 type 8 PBeginEnd = ^TBeginEnd; 9 PAssignment = ^TAssignment; 10 PVariable = ^TVariable; 11 PConstant = ^TConstant; 12 PIfThenElse = ^TIfThenElse; 13 PWhileDo = ^TWhileDo; 14 PExpression = ^TExpression; 15 PExecution = ^TExecution; 16 8 17 TBaseType = (btBoolean, btInteger, btChar, btShortString, btArray); 9 18 … … 26 35 Name: string; 27 36 DataType: PType; 28 case Integer of 29 0: (ValueChar: Char); 30 1: (ValueInteger: Integer); 31 2: (ValueString: ShortString); 32 3: (ValueBoolean: Boolean); 33 end; 34 PVariable = ^TVariable; 37 Index: Integer; 38 end; 35 39 36 40 { TVariables } … … 41 45 function GetByName(Name: string): PVariable; 42 46 end; 47 PVariables = ^TVariables; 43 48 44 49 TConstant = record 45 50 Name: string; 46 51 DataType: PType; 47 case Integer of 48 0: (ValueChar: Char); 49 1: (ValueInteger: Integer); 50 2: (ValueString: ShortString); 51 3: (ValueBoolean: Boolean); 52 end; 53 PConstant = ^TConstant; 52 Index: Integer; 53 case TBaseType of 54 btChar: (ValueChar: Char); 55 btInteger: (ValueInteger: Integer); 56 btShortString: (ValueString: ShortString); 57 btBoolean: (ValueBoolean: Boolean); 58 end; 59 60 { TConstants } 61 62 TConstants = record 63 Items: array of TConstant; 64 procedure Add(Constant: TConstant); 65 function GetByName(Name: string): PConstant; 66 end; 67 PConstants = ^TConstants; 54 68 55 69 TFunctionParameter = record … … 72 86 CmdType: TCmdType; 73 87 Ptr: Pointer; 74 {case Integer of75 0: (WhileDo: TWhileDo);76 1: (IfThenElse: TIfThenElse);77 2: (BeginEnd: TBeginEnd);78 3: (Assignment: TAssignment);79 4: (Execution: TExecution);80 }end;88 case Integer of 89 0: (WhileDo: PWhileDo); 90 1: (IfThenElse: PIfThenElse); 91 2: (BeginEnd: PBeginEnd); 92 3: (Assignment: PAssignment); 93 4: (Execution: PExecution); 94 end; 81 95 PCommand = ^TCommand; 96 97 { TBeginEnd } 82 98 83 99 TBeginEnd = record 84 100 Commands: array of TCommand; 85 end; 86 PBeginEnd = ^TBeginEnd; 101 procedure Add; 102 function GetLast: PCommand; 103 end; 104 105 TReadType = (rtVariable, rtConstant, rtExpression, rtFunctionCall); 106 TGetValue = record 107 ReadType: TReadType; 108 case TReadType of 109 rtVariable: (Variable: PVariable); 110 rtConstant: (Constant: PConstant); 111 rtExpression: (Expression: PExpression); 112 rtFunctionCall: (FunctionCall: PExecution); 113 end; 114 PGetValue = ^TGetValue; 115 116 TExpOperand = (eoNone, eoAdd, eoSubtract, eoAnd, eoOr, eoNot); 87 117 88 118 TExpression = record 89 end; 90 PExpression = ^TExpression; 119 Operand: TExpOperand; 120 Items: array of TGetValue; 121 end; 91 122 92 123 TAssignment = record 93 124 Destination: PVariable; 94 Source: TExpression; 95 end; 96 PAssignment = ^TAssignment; 125 Source: TGetValue; 126 end; 97 127 98 128 TIfThenElse = record 99 Condition: T Expression;129 Condition: TGetValue; 100 130 DoThen: TCommand; 101 131 DoElse: TCommand; 102 132 end; 103 PIfThenElse = ^TIfThenElse;104 133 105 134 TWhileDo = record 106 Condition: T Expression;135 Condition: TGetValue; 107 136 Command: TCommand; 108 137 end; 109 PWhileDo = ^TWhileDo;110 138 111 139 { TFunction } … … 130 158 131 159 TExecutionParams = record 132 Items: array of T Expression;160 Items: array of TGetValue; 133 161 end; 134 162 … … 137 165 Parameters: TExecutionParams; 138 166 end; 139 PExecution = ^TExecution;140 167 141 168 TProgramCode = record 142 169 Name: string; 143 170 Variables: TVariables; 171 Constants: TConstants; 144 172 Types: TTypes; 145 173 Functions: TFunctions; … … 180 208 end; 181 209 182 { TVariables } 183 184 procedure TVariables.Add(Variable: TVariable); 185 begin 186 SetLength(Items, Length(Items) + 1); 187 Items[Length(Items) - 1] := Variable; 188 end; 189 190 function TVariables.GetByName(Name: string): PVariable; 210 { TBeginEnd } 211 212 procedure TBeginEnd.Add; 213 begin 214 SetLength(Commands, Length(Commands) + 1); 215 end; 216 217 function TBeginEnd.GetLast: PCommand; 218 begin 219 Result := @Commands[Length(Commands) - 1]; 220 end; 221 222 { TConstants } 223 224 procedure TConstants.Add(Constant: TConstant); 225 begin 226 SetLength(Items, Length(Items) + 1); 227 Items[Length(Items) - 1] := Constant; 228 Items[Length(Items) - 1].Index := Length(Items) - 1; 229 end; 230 231 function TConstants.GetByName(Name: string): PConstant; 191 232 var 192 233 I: Integer; … … 198 239 end; 199 240 200 { TFunctionParameters } 201 202 procedure TFunctionParameters.Add(Param: TFunctionParameter); 203 begin 204 SetLength(Items, Length(Items) + 1); 205 Items[Length(Items) - 1] := Param; 206 end; 207 208 { TTypes } 209 210 procedure TTypes.Add(DataType: TType); 211 begin 212 SetLength(Items, Length(Items) + 1); 213 Items[Length(Items) - 1] := DataType; 214 end; 215 216 function TTypes.GetByName(Name: string): PType; 241 { TVariables } 242 243 procedure TVariables.Add(Variable: TVariable); 244 begin 245 SetLength(Items, Length(Items) + 1); 246 Items[Length(Items) - 1] := Variable; 247 Items[Length(Items) - 1].Index := Length(Items) - 1; 248 end; 249 250 function TVariables.GetByName(Name: string): PVariable; 217 251 var 218 252 I: Integer; … … 224 258 end; 225 259 226 function TTypes.GetLast: PType; 227 begin 228 Result := @Items[Length(Items) - 1]; 229 end; 230 231 { TFunctions } 232 233 procedure TFunctions.Add(Func: TFunction); 234 begin 235 SetLength(Items, Length(Items) + 1); 236 Items[Length(Items) - 1] := Func; 237 end; 238 239 function TFunctions.GetByName(Name: string): PFunction; 260 { TFunctionParameters } 261 262 procedure TFunctionParameters.Add(Param: TFunctionParameter); 263 begin 264 SetLength(Items, Length(Items) + 1); 265 Items[Length(Items) - 1] := Param; 266 end; 267 268 { TTypes } 269 270 procedure TTypes.Add(DataType: TType); 271 begin 272 SetLength(Items, Length(Items) + 1); 273 Items[Length(Items) - 1] := DataType; 274 end; 275 276 function TTypes.GetByName(Name: string): PType; 240 277 var 241 278 I: Integer; … … 247 284 end; 248 285 286 function TTypes.GetLast: PType; 287 begin 288 Result := @Items[Length(Items) - 1]; 289 end; 290 291 { TFunctions } 292 293 procedure TFunctions.Add(Func: TFunction); 294 begin 295 SetLength(Items, Length(Items) + 1); 296 Items[Length(Items) - 1] := Func; 297 end; 298 299 function TFunctions.GetByName(Name: string): PFunction; 300 var 301 I: Integer; 302 begin 303 I := 0; 304 while (I < Length(Items)) and (Items[I].Name <> Name) do I := I + 1; 305 if I < Length(Items) then Result := @Items[I] 306 else Result := nil; 307 end; 308 249 309 function TFunctions.GetLast: PFunction; 250 310 begin
Note:
See TracChangeset
for help on using the changeset viewer.