Changeset 234
- Timestamp:
- Jun 27, 2023, 12:50:09 AM (17 months ago)
- Location:
- branches/xpascal
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/xpascal/Forms/FormMain.lfm
r233 r234 24 24 TabOrder = 0 25 25 end 26 object PanelSource: TPanel 27 Left = 7 28 Height = 832 26 object Splitter1: TSplitter 27 Cursor = crVSplit 28 Left = 0 29 Height = 8 30 Top = 824 31 Width = 1491 32 Align = alBottom 33 ResizeAnchor = akBottom 34 end 35 object Panel1: TPanel 36 Left = 0 37 Height = 824 29 38 Top = 0 30 Width = 82939 Width = 1491 31 40 Align = alClient 32 BevelOuter = bvNone 33 TabOrder = 1 34 end 35 object PanelOutput: TPanel 36 Left = 836 37 Height = 832 38 Top = 0 39 Width = 655 40 Align = alRight 41 BevelOuter = bvNone 41 ClientHeight = 824 42 ClientWidth = 1491 42 43 TabOrder = 2 43 end 44 object Splitter1: TSplitter 45 Left = 0 46 Height = 832 47 Top = 0 48 Width = 7 44 object PanelSource: TPanel 45 Left = 1 46 Height = 822 47 Top = 1 48 Width = 826 49 Align = alClient 50 BevelOuter = bvNone 51 TabOrder = 0 52 end 53 object PanelOutput: TPanel 54 Left = 835 55 Height = 822 56 Top = 1 57 Width = 655 58 Align = alRight 59 BevelOuter = bvNone 60 TabOrder = 1 61 end 62 object Splitter2: TSplitter 63 Left = 827 64 Height = 822 65 Top = 1 66 Width = 8 67 Align = alRight 68 ResizeAnchor = akRight 69 end 49 70 end 50 71 object MainMenu1: TMainMenu -
branches/xpascal/Forms/FormMain.pas
r233 r234 41 41 MenuItemFile: TMenuItem; 42 42 OpenDialog1: TOpenDialog; 43 Panel1: TPanel; 43 44 PanelOutput: TPanel; 44 45 PanelSource: TPanel; 45 46 PanelMessages: TPanel; 46 47 Splitter1: TSplitter; 48 Splitter2: TSplitter; 47 49 procedure ACompileExecute(Sender: TObject); 48 50 procedure AConsoleExecute(Sender: TObject); -
branches/xpascal/Forms/FormOutput.lfm
r230 r234 1 1 object FormOutput: TFormOutput 2 Left = 5632 Left = 814 3 3 Height = 544 4 Top = 3394 Top = 448 5 5 Width = 932 6 6 Caption = 'Output' … … 17 17 BorderSpacing.Around = 4 18 18 Anchors = [akTop, akLeft, akRight, akBottom] 19 Color = clBlack 20 Font.Color = clWhite 19 21 Font.Height = -20 20 22 Font.Name = 'DejaVu Sans Mono' -
branches/xpascal/Forms/FormSource.lfm
r227 r234 1 1 object FormSource: TFormSource 2 Left = 5242 Left = 692 3 3 Height = 749 4 Top = 2994 Top = 345 5 5 Width = 1176 6 6 Caption = 'Source' … … 12 12 Left = 12 13 13 Height = 701 14 Top = 3 614 Top = 32 15 15 Width = 1156 16 16 Align = alCustom 17 17 BorderSpacing.Around = 4 18 18 Anchors = [akTop, akLeft, akRight, akBottom] 19 Color = clBlack 20 Font.Color = clWhite 19 21 Font.Height = -20 20 22 Font.Name = 'Liberation Mono' -
branches/xpascal/Generators/GeneratorCSharp.pas
r233 r234 14 14 procedure GenerateProgram(Block: TBlock; Prog:TProgram); 15 15 procedure GenerateFunction(ParentBlock: TBlock; FunctionDef: TFunction); 16 procedure GenerateProcedure(ParentBlock: TBlock; ProcedureDef: TProcedure); 16 17 procedure GenerateBlock(ParentBlock: TBlock; Block: TBlock); 17 18 procedure GenerateBlockConst(ParentBlock: TBlock; Block: TBlock); 18 19 procedure GenerateBlockVar(ParentBlock: TBlock; Block: TBlock); 19 20 procedure GenerateBlockFunctions(ParentBlock: TBlock; Block: TBlock); 21 procedure GenerateBlockProcedures(ParentBlock: TBlock; Block: TBlock); 20 22 procedure GenerateBeginEnd(Block: TBlock; BeginEnd: TBeginEnd; Enclosed: Boolean = True); 21 23 procedure GenerateCommand(Block: TBlock; Command: TCommand); … … 25 27 procedure GenerateForToDo(Block: TBlock; ForToDo: TForToDo); 26 28 procedure GenerateFunctionCall(Block: TBlock; FunctionCall: TFunctionCall); 29 procedure GenerateProcedureCall(Block: TBlock; ProcedureCall: TProcedureCall); 27 30 procedure GenerateAssignment(Block: TBlock; Assignment: TAssignment); 28 31 procedure GenerateExpression(Block: TBlock; Expression: TExpression); … … 54 57 if Command is TBeginEnd then GenerateBeginEnd(Block, TBeginEnd(Command)) 55 58 else if Command is TFunctionCall then GenerateFunctionCall(Block, TFunctionCall(Command)) 59 else if Command is TProcedureCall then GenerateProcedureCall(Block, TProcedureCall(Command)) 56 60 else if Command is TAssignment then GenerateAssignment(Block, TAssignment(Command)) 57 61 else if Command is TIfThenElse then GenerateIfThenElse(Block, TIfThenElse(Command)) … … 138 142 end; 139 143 144 procedure TGeneratorCSharp.GenerateProcedureCall(Block: TBlock; 145 ProcedureCall: TProcedureCall); 146 var 147 I: Integer; 148 begin 149 AddText(ProcedureCall.ProcedureDef.Name); 150 if ProcedureCall.Params.Count > 0 then begin 151 AddText('('); 152 for I := 0 to ProcedureCall.Params.Count - 1 do begin 153 if ProcedureCall.ProcedureDef.Params[I].Kind = pkVar then 154 AddText('ref '); 155 GenerateExpression(Block, TExpression(ProcedureCall.Params[I])); 156 end; 157 AddText(')'); 158 end; 159 end; 160 140 161 procedure TGeneratorCSharp.GenerateAssignment(Block: TBlock; Assignment: TAssignment); 141 162 begin … … 238 259 Indent := Indent + 1; 239 260 GenerateBlockFunctions(nil, Prog.SystemBlock); 261 GenerateBlockProcedures(nil, Prog.SystemBlock); 240 262 GenerateBlock(nil, Prog.SystemBlock); 241 263 AddTextLine('public static void Main()'); … … 246 268 AddTextLine(); 247 269 GenerateBlockFunctions(Prog.Block, Prog.Block); 270 GenerateBlockProcedures(Prog.Block, Prog.Block); 248 271 AddTextLine('public void Entry()'); 249 272 GenerateBlock(Block, Prog.Block); … … 320 343 AddTextLine('{'); 321 344 Indent := Indent + 1; 322 if FunctionDef.InternalName = 'WriteLn' then AddTextLine('Console.Write(Text + "\n");') 323 else if FunctionDef.InternalName = 'Write' then AddTextLine('Console.Write(Text);') 324 else if FunctionDef.InternalName = 'ReadLn' then AddTextLine('Text = Console.ReadLine();') 325 else if FunctionDef.InternalName = 'Read' then AddTextLine('Text = Console.ReadLine();') 326 else if FunctionDef.InternalName = 'IntToStr' then AddTextLine('return Value.ToString();') 345 if FunctionDef.InternalName = 'IntToStr' then AddTextLine('return Value.ToString();') 327 346 else if FunctionDef.InternalName = 'StrToInt' then begin 328 347 AddTextLine('int x = 0;'); … … 349 368 end; 350 369 370 procedure TGeneratorCSharp.GenerateProcedure(ParentBlock: TBlock; 371 ProcedureDef: TProcedure); 372 var 373 I: Integer; 374 Param: TFunctionParameter; 375 begin 376 AddText('void ' + ProcedureDef.Name + '('); 377 for I := 0 to ProcedureDef.Params.Count - 1 do begin 378 Param := TFunctionParameter(ProcedureDef.Params[I]); 379 if Param.Kind = pkVar then AddText('ref '); 380 GenerateTypeRef(Param.TypeRef); 381 AddText(' '); 382 AddText(Param.Name); 383 if I > 0 then AddText(', '); 384 end; 385 AddTextLine(')'); 386 if ProcedureDef.InternalName <> '' then begin 387 AddTextLine('{'); 388 Indent := Indent + 1; 389 if ProcedureDef.InternalName = 'WriteLn' then AddTextLine('Console.Write(Text + "\n");') 390 else if ProcedureDef.InternalName = 'Write' then AddTextLine('Console.Write(Text);') 391 else if ProcedureDef.InternalName = 'ReadLn' then AddTextLine('Text = Console.ReadLine();') 392 else if ProcedureDef.InternalName = 'Read' then AddTextLine('Text = Console.ReadLine();'); 393 394 Indent := Indent - 1; 395 AddTextLine('}'); 396 end else begin 397 GenerateBlock(ParentBlock, ProcedureDef.Block); 398 AddTextLine; 399 end; 400 end; 401 351 402 procedure TGeneratorCSharp.GenerateBlockFunctions(ParentBlock: TBlock; 352 403 Block: TBlock); … … 360 411 end; 361 412 413 procedure TGeneratorCSharp.GenerateBlockProcedures(ParentBlock: TBlock; 414 Block: TBlock); 415 var 416 I: Integer; 417 begin 418 for I := 0 to Block.Procedures.Count - 1 do begin 419 GenerateProcedure(ParentBlock, TProcedure(Block.Procedures[I])); 420 AddTextLine; 421 end; 422 end; 423 362 424 procedure TGeneratorCSharp.GenerateBeginEnd(Block: TBlock; BeginEnd: TBeginEnd; Enclosed: Boolean = True); 363 425 var -
branches/xpascal/Generators/GeneratorPascal.pas
r230 r234 14 14 procedure GenerateProgram(Block: TBlock; Prog:TProgram); 15 15 procedure GenerateFunction(ParentBlock: TBlock; FunctionDef: TFunction); 16 procedure GenerateProcedure(ParentBlock: TBlock; ProcedureDef: TProcedure); 16 17 procedure GenerateBlock(ParentBlock: TBlock; Block: TBlock); 17 18 procedure GenerateBlockVar(ParentBlock: TBlock; Block: TBlock); 18 19 procedure GenerateBlockConst(ParentBlock: TBlock; Block: TBlock); 19 20 procedure GenerateBlockFunctions(ParentBlock: TBlock; Block: TBlock); 21 procedure GenerateBlockProcedures(ParentBlock: TBlock; Block: TBlock); 20 22 procedure GenerateBeginEnd(Block: TBlock; BeginEnd: TBeginEnd); 21 23 procedure GenerateCommand(Block: TBlock; Command: TCommand); … … 25 27 procedure GenerateRepeatUntil(Block: TBlock; RepeatUntil: TRepeatUntil); 26 28 procedure GenerateFunctionCall(Block: TBlock; FunctionCall: TFunctionCall); 29 procedure GenerateProcedureCall(Block: TBlock; ProcedureCall: TProcedureCall); 27 30 procedure GenerateAssignment(Block: TBlock; Assignment: TAssignment); 28 31 procedure GenerateExpression(Block: TBlock; Expression: TExpression); … … 47 50 if Command is TBeginEnd then GenerateBeginEnd(Block, TBeginEnd(Command)) 48 51 else if Command is TFunctionCall then GenerateFunctionCall(Block, TFunctionCall(Command)) 52 else if Command is TProcedureCall then GenerateProcedureCall(Block, TProcedureCall(Command)) 49 53 else if Command is TAssignment then GenerateAssignment(Block, TAssignment(Command)) 50 54 else if Command is TIfThenElse then GenerateIfThenElse(Block, TIfThenElse(Command)) … … 120 124 end; 121 125 126 procedure TGeneratorPascal.GenerateProcedureCall(Block: TBlock; 127 ProcedureCall: TProcedureCall); 128 var 129 I: Integer; 130 begin 131 AddText(ProcedureCall.ProcedureDef.Name); 132 if ProcedureCall.Params.Count > 0 then begin 133 AddText('('); 134 for I := 0 to ProcedureCall.Params.Count - 1 do 135 GenerateExpression(Block, TExpression(ProcedureCall.Params[I])); 136 AddText(')'); 137 end; 138 end; 139 122 140 procedure TGeneratorPascal.GenerateAssignment(Block: TBlock; Assignment: TAssignment); 123 141 begin … … 228 246 AddTextLine('begin'); 229 247 Indent := Indent + 1; 230 if FunctionDef.InternalName = 'WriteLn' then AddTextLine('System.WriteLn(Text);') 231 else if FunctionDef.InternalName = 'Write' then AddTextLine('System.Write(Text);') 232 else if FunctionDef.InternalName = 'IntToStr' then AddTextLine('return SysUtils.IntToStr(Value);') 248 if FunctionDef.InternalName = 'IntToStr' then AddTextLine('return SysUtils.IntToStr(Value);') 233 249 else if FunctionDef.InternalName = 'StrToInt' then AddTextLine('return SysUtils.StrToInt(Value);') 234 250 else if FunctionDef.InternalName = 'BoolToStr' then AddTextLine('return SysUtils.BoolToStr(Value);') … … 242 258 end; 243 259 260 procedure TGeneratorPascal.GenerateProcedure(ParentBlock: TBlock; 261 ProcedureDef: TProcedure); 262 var 263 I: Integer; 264 begin 265 AddText('procedure ' + ProcedureDef.Name); 266 if ProcedureDef.Params.Count > 0 then begin 267 AddText('('); 268 for I := 0 to ProcedureDef.Params.Count - 1 do begin 269 AddText(TFunctionParameter(ProcedureDef.Params[I]).Name); 270 AddText(': '); 271 AddText(TFunctionParameter(ProcedureDef.Params[I]).TypeRef.Name); 272 if I > 0 then AddText(', '); 273 end; 274 AddText(')'); 275 end; 276 AddTextLine(';'); 277 if ProcedureDef.InternalName <> '' then begin 278 AddTextLine('begin'); 279 Indent := Indent + 1; 280 if ProcedureDef.InternalName = 'WriteLn' then AddTextLine('System.WriteLn(Text);') 281 else if ProcedureDef.InternalName = 'Write' then AddTextLine('System.Write(Text);') 282 else if ProcedureDef.InternalName = 'ReadLn' then AddTextLine('System.ReadLn(Text);') 283 else if ProcedureDef.InternalName = 'Read' then AddTextLine('System.Read(Text);'); 284 Indent := Indent - 1; 285 AddTextLine('end;'); 286 end else begin 287 GenerateBlock(ParentBlock, ProcedureDef.Block); 288 AddTextLine(';'); 289 end; 290 end; 291 244 292 procedure TGeneratorPascal.GenerateBlock(ParentBlock: TBlock; Block: TBlock); 245 293 begin 246 294 GenerateBlockConst(ParentBlock, Block); 247 295 GenerateBlockVar(ParentBlock, Block); 296 GenerateBlockProcedures(ParentBlock, Block); 248 297 GenerateBlockFunctions(ParentBlock, Block); 249 298 GenerateBeginEnd(ParentBlock, Block.BeginEnd); … … 317 366 end; 318 367 368 procedure TGeneratorPascal.GenerateBlockProcedures(ParentBlock: TBlock; 369 Block: TBlock); 370 var 371 I: Integer; 372 begin 373 for I := 0 to Block.Procedures.Count - 1 do begin 374 GenerateProcedure(ParentBlock, TProcedure(Block.Procedures[I])); 375 AddTextLine; 376 end; 377 end; 378 319 379 procedure TGeneratorPascal.Generate; 320 380 begin -
branches/xpascal/Generators/GeneratorPhp.pas
r232 r234 14 14 procedure GenerateProgram(Block: TBlock; Prog:TProgram); 15 15 procedure GenerateFunction(ParentBlock: TBlock; FunctionDef: TFunction); 16 procedure GenerateProcedure(ParentBlock: TBlock; ProcedureDef: TProcedure); 16 17 procedure GenerateBlock(ParentBlock: TBlock; Block: TBlock); 17 18 procedure GenerateBlockConst(ParentBlock: TBlock; Block: TBlock); 18 19 procedure GenerateBlockFunctions(ParentBlock: TBlock; Block: TBlock); 20 procedure GenerateBlockProcedures(ParentBlock: TBlock; Block: TBlock); 19 21 procedure GenerateBeginEnd(Block: TBlock; BeginEnd: TBeginEnd); 20 22 procedure GenerateCommand(Block: TBlock; Command: TCommand); … … 24 26 procedure GenerateForToDo(Block: TBlock; ForToDo: TForToDo); 25 27 procedure GenerateFunctionCall(Block: TBlock; FunctionCall: TFunctionCall); 28 procedure GenerateProcedureCall(Block: TBlock; ProcedureCall: TProcedureCall); 26 29 procedure GenerateAssignment(Block: TBlock; Assignment: TAssignment); 27 30 procedure GenerateExpression(Block: TBlock; Expression: TExpression); … … 52 55 if Command is TBeginEnd then GenerateBeginEnd(Block, TBeginEnd(Command)) 53 56 else if Command is TFunctionCall then GenerateFunctionCall(Block, TFunctionCall(Command)) 57 else if Command is TProcedureCall then GenerateProcedureCall(Block, TProcedureCall(Command)) 54 58 else if Command is TAssignment then GenerateAssignment(Block, TAssignment(Command)) 55 59 else if Command is TIfThenElse then GenerateIfThenElse(Block, TIfThenElse(Command)) … … 133 137 end; 134 138 139 procedure TGeneratorPhp.GenerateProcedureCall(Block: TBlock; 140 ProcedureCall: TProcedureCall); 141 var 142 I: Integer; 143 begin 144 AddText(ProcedureCall.ProcedureDef.Name); 145 if ProcedureCall.Params.Count > 0 then begin 146 AddText('('); 147 for I := 0 to ProcedureCall.Params.Count - 1 do 148 GenerateExpression(Block, TExpression(ProcedureCall.Params[I])); 149 AddText(')'); 150 end; 151 end; 152 135 153 procedure TGeneratorPhp.GenerateAssignment(Block: TBlock; Assignment: TAssignment); 136 154 begin … … 240 258 AddTextLine('{'); 241 259 Indent := Indent + 1; 242 if FunctionDef.InternalName = 'WriteLn' then AddTextLine('echo($Text."\n");') 243 else if FunctionDef.InternalName = 'Write' then AddTextLine('echo($Text);') 244 else if FunctionDef.InternalName = 'ReadLn' then AddTextLine('$Text = readline();') 245 else if FunctionDef.InternalName = 'Read' then AddTextLine('$Text = readline();') 246 else if FunctionDef.InternalName = 'IntToStr' then AddTextLine('return $Value;') 260 if FunctionDef.InternalName = 'IntToStr' then AddTextLine('return $Value;') 247 261 else if FunctionDef.InternalName = 'StrToInt' then AddTextLine('return $Value;') 248 262 else if FunctionDef.InternalName = 'BoolToStr' then AddTextLine('return $Value;') … … 256 270 end; 257 271 272 procedure TGeneratorPhp.GenerateProcedure(ParentBlock: TBlock; 273 ProcedureDef: TProcedure); 274 var 275 I: Integer; 276 begin 277 AddText('function ' + ProcedureDef.Name + '('); 278 for I := 0 to ProcedureDef.Params.Count - 1 do begin 279 if ProcedureDef.Params[I].Kind = pkVar then 280 AddText('&'); 281 AddText('$' + TFunctionParameter(ProcedureDef.Params[I]).Name); 282 if I > 0 then AddText(', '); 283 end; 284 AddTextLine(')'); 285 if ProcedureDef.InternalName <> '' then begin 286 AddTextLine('{'); 287 Indent := Indent + 1; 288 if ProcedureDef.InternalName = 'WriteLn' then AddTextLine('echo($Text."\n");') 289 else if ProcedureDef.InternalName = 'Write' then AddTextLine('echo($Text);') 290 else if ProcedureDef.InternalName = 'ReadLn' then AddTextLine('$Text = readline();') 291 else if ProcedureDef.InternalName = 'Read' then AddTextLine('$Text = readline();'); 292 Indent := Indent - 1; 293 AddTextLine('}'); 294 end else begin 295 GenerateBlock(ParentBlock, ProcedureDef.Block); 296 AddTextLine; 297 end; 298 end; 299 258 300 procedure TGeneratorPhp.GenerateBlock(ParentBlock: TBlock; Block: TBlock); 259 301 begin 260 302 GenerateBlockConst(ParentBlock, Block); 303 GenerateBlockProcedures(ParentBlock, Block); 261 304 GenerateBlockFunctions(ParentBlock, Block); 262 305 if Block.BeginEnd.Commands.Count > 0 then begin … … 290 333 end; 291 334 335 procedure TGeneratorPhp.GenerateBlockProcedures(ParentBlock: TBlock; 336 Block: TBlock); 337 var 338 I: Integer; 339 begin 340 for I := 0 to Block.Procedures.Count - 1 do begin 341 GenerateProcedure(ParentBlock, TProcedure(Block.Procedures[I])); 342 AddTextLine; 343 end; 344 end; 345 292 346 procedure TGeneratorPhp.GenerateBeginEnd(Block: TBlock; BeginEnd: TBeginEnd); 293 347 var -
branches/xpascal/Languages/xpascal.cs.po
r233 r234 174 174 msgid "Unsupported tokenizer state." 175 175 msgstr "NepodporovanÜ stav tokenizeru." 176 -
branches/xpascal/Parser.pas
r230 r234 201 201 ResultType := TypeBoolean; 202 202 end; 203 with Block. Functions.AddNew('WriteLn') do begin203 with Block.Procedures.AddNew('WriteLn') do begin 204 204 InternalName := 'WriteLn'; 205 205 Params.AddNew('Text', TypeString); 206 206 end; 207 with Block. Functions.AddNew('Write') do begin207 with Block.Procedures.AddNew('Write') do begin 208 208 InternalName := 'Write'; 209 209 Params.AddNew('Text', TypeString); 210 210 end; 211 with Block. Functions.AddNew('ReadLn') do begin211 with Block.Procedures.AddNew('ReadLn') do begin 212 212 InternalName := 'ReadLn'; 213 213 with Params.AddNew('Text', TypeString) do 214 214 Kind := pkVar; 215 215 end; 216 with Block. Functions.AddNew('Read') do begin216 with Block.Procedures.AddNew('Read') do begin 217 217 InternalName := 'Read'; 218 218 with Params.AddNew('Text', TypeString) do
Note:
See TracChangeset
for help on using the changeset viewer.