Changeset 118
- Timestamp:
- Nov 27, 2017, 5:10:04 PM (7 years ago)
- Location:
- branches/generator
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/generator/Forms/UFormMain.lfm
r117 r118 36 36 Height = 22 37 37 Top = 5 38 Width = 2438 Width = 47 39 39 Align = alNone 40 40 AutoSize = True … … 54 54 Action = ARules 55 55 end 56 object ToolButton2: TToolButton 57 Left = 24 58 Top = 0 59 Action = ABuildCompiler 60 end 56 61 end 57 62 end 58 63 object MainMenu1: TMainMenu 59 64 Images = Core.ImageList1 60 left = 24861 top = 2 1665 left = 312 66 top = 229 62 67 object MenuItem2: TMenuItem 63 68 Caption = 'File' … … 73 78 object MenuItem7: TMenuItem 74 79 Action = AExit 80 end 81 end 82 object MenuItem8: TMenuItem 83 Caption = 'Tools' 84 object MenuItem9: TMenuItem 85 Action = ABuildCompiler 75 86 end 76 87 end … … 110 121 OnExecute = ASaveAsExecute 111 122 end 123 object ABuildCompiler: TAction 124 Caption = 'Build compiler' 125 ImageIndex = 9 126 OnExecute = ABuildCompilerExecute 127 end 112 128 end 113 129 object OpenDialog1: TOpenDialog -
branches/generator/Forms/UFormMain.pas
r117 r118 7 7 uses 8 8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, 9 Menus, ActnList, ComCtrls, UPersistentForm ;9 Menus, ActnList, ComCtrls, UPersistentForm, URules; 10 10 11 11 type … … 14 14 15 15 TFormMain = class(TForm) 16 ABuildCompiler: TAction; 16 17 AExit: TAction; 17 18 AOpen: TAction; … … 29 30 MenuItem6: TMenuItem; 30 31 MenuItem7: TMenuItem; 32 MenuItem8: TMenuItem; 33 MenuItem9: TMenuItem; 31 34 OpenDialog1: TOpenDialog; 32 35 SaveDialog1: TSaveDialog; 33 36 ToolBar1: TToolBar; 34 37 ToolButton1: TToolButton; 38 ToolButton2: TToolButton; 39 procedure ABuildCompilerExecute(Sender: TObject); 35 40 procedure AExitExecute(Sender: TObject); 36 41 procedure AOpenExecute(Sender: TObject); … … 93 98 end; 94 99 100 procedure TFormMain.ABuildCompilerExecute(Sender: TObject); 101 var 102 ParserFile: TStringList; 103 SourceFile: TStringList; 104 Rule: TRule; 105 Item: TRuleItem; 106 OutputDir: string; 107 Line: string; 108 I: Integer; 109 begin 110 OutputDir := 'Generated'; 111 ForceDirectories(OutputDir); 112 113 ParserFile := TStringList.Create; 114 with ParserFile do begin 115 Add('program Compiler;'); 116 Add(''); 117 Add('{$MODE Delphi}'); 118 Add(''); 119 Add('uses'); 120 Add(' Source;'); 121 Add(''); 122 Add('procedure Compile;'); 123 Add('begin'); 124 Add('end;'); 125 Add(''); 126 Add('begin'); 127 Add(' Compile;'); 128 Add('end.'); 129 SaveToFile(OutputDir + DirectorySeparator + 'Compiler.pas'); 130 end; 131 FreeAndNil(ParserFile); 132 133 SourceFile := TStringList.Create; 134 with SourceFile do begin 135 Add('unit Source;'); 136 Add(''); 137 Add('{$MODE Delphi}'); 138 Add(''); 139 Add('interface'); 140 Add(''); 141 Add('uses'); 142 Add(' fgl;'); 143 Add(''); 144 Add('type'); 145 for Rule in Core.Grammer.Rules do begin 146 Add(' T' + Rule.Name + ' = class;'); 147 end; 148 Add(''); 149 for Rule in Core.Grammer.Rules do begin 150 Add(' T' + Rule.Name + ' = class'); 151 for Item in Rule.Items do begin 152 if Item.RuleItemType = ritNonTerminal then 153 if Item.Repetitive then 154 Add(' ' + Item.NonTerminal.Name + ': TFPGObjectList<T' + Item.NonTerminal.Name + '>;') 155 else Add(' ' + Item.NonTerminal.Name + ': T' + Item.NonTerminal.Name + ';'); 156 end; 157 Add(' end;' + LineEnding); 158 end; 159 Add(''); 160 Add('implementation'); 161 Add(''); 162 for Rule in Core.Grammer.Rules do begin 163 Add('function Parse' + Rule.Name + ': Boolean;'); 164 Add('begin'); 165 I := 0; 166 for Item in Rule.Items do begin 167 Line := ' '; 168 if Rule.Items.RuleType = rtOr then begin 169 if I > 0 then Line := Line + 'else '; 170 Line := Line + 'if '; 171 end else 172 if Rule.Items.RuleType = rtAnd then begin 173 Line := Line + ''; 174 end; 175 if Item.RuleItemType = ritTerminal then 176 Line := Line + 'Expect(''' + Item.Terminal + ''')' 177 else if Item.RuleItemType = ritNonTerminal then 178 Line := Line + 'Parse' + Item.NonTerminal.Name; 179 if Rule.Items.RuleType = rtOr then begin 180 Line := Line + ' then '; 181 end else 182 if Rule.Items.RuleType = rtAnd then begin 183 Line := Line + ';'; 184 end; 185 Add(Line); 186 Inc(I); 187 end; 188 if Rule.Items.RuleType = rtOr then begin 189 Add(' else ShowError(''Unexpected token'');'); 190 end; 191 Add('end;'); 192 Add(''); 193 end; 194 195 Add('end.'); 196 197 SaveToFile(OutputDir + DirectorySeparator +'Source.pas'); 198 end; 199 FreeAndNil(SourceFile); 200 end; 201 95 202 procedure TFormMain.AOpenExecute(Sender: TObject); 96 203 begin -
branches/generator/Forms/UFormRuleItem.pas
r117 r118 94 94 ComboBoxNonTerminal.Items.AddObject(Rule.Name, Rule); 95 95 end; 96 ComboBoxNonTerminal.Sorted := True; 96 97 end; 97 98 -
branches/generator/UCore.lfm
r115 r118 4 4 OldCreateOrder = False 5 5 Height = 586 6 HorizontalOffset = 5937 VerticalOffset = 2 506 HorizontalOffset = 393 7 VerticalOffset = 264 8 8 Width = 944 9 9 object ImageList1: TImageList … … 11 11 top = 243 12 12 Bitmap = { 13 4C690 9000000100000001000000000000000000000000000000000000000000013 4C690A0000001000000010000000000000000000000000000000000000000000 14 14 000070A970FF006400FF006200FF70A670FF0000000000000000000000000000 15 15 0000000000000000000000000000000000000000000000000000000000000000 … … 299 299 0000000000000000000000000000000000000000000000000000000000000000 300 300 000000000000000000FF000000FF000000FF0000000000000000000000000000 301 0000000000000000000000000000 301 0000000000000000000000000000000000000000000000000000000000000000 302 000000000000CB6600FFCB6600FFB65100FF0000000000000000000000000000 303 0000000000000000000000000000000000000000000000000000000000000000 304 000000000000CB6600FFFFFFFFFF993300FFB2B2B2FF00000000000000000000 305 0000000000000000000000000000000000000000000000000000000000000000 306 000000000000CB6600FFFFD9A0FF993300FFB2B2B2FF00000000000000000000 307 0000000000000000000000000000000000000000000000000000000000000000 308 000000000000CB6600FFFFD9A0FF993300FFB2B2B2FF00000000000000000000 309 0000000000000000000000000000000000000000000000000000000000000000 310 000000000000CB6600FFFFD493FF993300FFB2B2B2FF00000000000000000000 311 0000000000000000000000000000000000000000000000000000CB6600FFCB66 312 00FFCB6600FFCB6600FFFFCA7BFF993300FF993300FF993300FF993300FF0000 313 0000000000000000000000000000BF6060FFDDDDDDFFDDDDDDFFCB6600FFFFF9 314 F0FFFFEDD2FFFFEDD2FFFFBE5CFFFFB444FFFFAB2DFFFFA319FF993300FF9A9A 315 9AFFDDDDDDFF7B3D3EFF00000000BF6060FFDDDDDDFFDDDDDDFFC9976EFFB651 316 00FFFFC56CFFFFBE5CFFFFB444FFFFA826FFFF9E0DFF993300FF99664DFF9A9A 317 9AFFDDDDDDFF7B3D3EFFB2B2B2FFBF6060FFDDDDDDFFDDDDDDFFDDDDDDFFB886 318 5DFFB65100FFFFAB2DFFFFA319FFFF9E0DFF993300FF99664DFF9A9A9AFFBBBB 319 BBFFDDDDDDFF7B3D3EFFB2B2B2FFBF6060FFDDDDDDFFDDDDDDFFDDDDDDFFDDDD 320 DDFFB8865DFFB65100FFFF9E0DFF993300FF99664DFF9A9A9AFFBBBBBBFFDDDD 321 DDFFDDDDDDFF733939FFB2B2B2FFB3595AFFDDDDDDFFDDDDDDFFDDDDDDFFDDDD 322 DDFFDDDDDDFFB8865DFFB65100FF99664DFF9A9A9AFFBBBBBBFFDDDDDDFFDDDD 323 DDFFDDDDDDFF733939FFB2B2B2FFB3595AFFDDDDDDFFDDDDDDFFDDDDDDFFDDDD 324 DDFFDDDDDDFFDDDDDDFFBBBBBBFF9A9A9AFFBBBBBBFFDDDDDDFFDDDDDDFFDDDD 325 DDFFDDDDDDFF6F3738FFB2B2B2FFA95455FFDDDDDDFFDDDDDDFFDDDDDDFFDDDD 326 DDFFDDDDDDFFDDDDDDFFDDDDDDFFDDDDDDFFDDDDDDFFDDDDDDFFDDDDDDFFDDDD 327 DDFFDDDDDDFF6F3738FFB2B2B2FFA95455FFDDDDDDFFDDDDDDFFDDDDDDFFDDDD 328 DDFFDDDDDDFFDDDDDDFFDDDDDDFFDDDDDDFFDDDDDDFFDDDDDDFFDDDDDDFFDDDD 329 DDFFDDDDDDFF693534FFB2B2B2FFCFA5A5FF9F4F50FF9F4F50FF954A4BFF8F47 330 47FF8F4747FF844242FF844242FF7B3D3EFF7B3D3EFF733939FF6F3738FF6F37 331 38FF693534FF8B7070FFB2B2B2FF00000000D7D7D7FFB2B2B2FFB2B2B2FFB2B2 332 B2FFB2B2B2FFB2B2B2FFB2B2B2FFB2B2B2FFB2B2B2FFB2B2B2FFB2B2B2FFB2B2 333 B2FFB2B2B2FFB2B2B2FFD7D7D7FF 302 334 } 303 335 end -
branches/generator/UCore.pas
r114 r118 6 6 7 7 uses 8 Classes, SysUtils, FileUtil, Controls, URules, UPersistentForm;8 Classes, SysUtils, FileUtil, Controls, ActnList, URules, UPersistentForm; 9 9 10 10 type -
branches/generator/generator.lpi
r117 r118 132 132 <IsPartOfProject Value="True"/> 133 133 <ComponentName Value="FormRuleItems"/> 134 <HasResources Value="True"/> 134 135 <ResourceBaseClass Value="Form"/> 135 136 </Unit7> -
branches/generator/pascal.grm
r117 r118 277 277 <Name>Statement</Name> 278 278 <RuleItems> 279 <Type> 0</Type>279 <Type>1</Type> 280 280 <RuleItem> 281 281 <Type>1</Type> … … 428 428 <Optional>0</Optional> 429 429 <Repetitive>0</Repetitive> 430 <NonTerminal>Identifier</NonTerminal> 430 <NonTerminal>FunctionName</NonTerminal> 431 </RuleItem> 432 <RuleItem> 433 <Type>1</Type> 434 <Optional>-1</Optional> 435 <Repetitive>0</Repetitive> 436 <NonTerminal>FunctionParameters</NonTerminal> 437 </RuleItem> 438 <RuleItem> 439 <Type>0</Type> 440 <Optional>0</Optional> 441 <Repetitive>0</Repetitive> 442 <Terminal>:</Terminal> 443 </RuleItem> 444 <RuleItem> 445 <Type>1</Type> 446 <Optional>0</Optional> 447 <Repetitive>0</Repetitive> 448 <NonTerminal>TypeReference</NonTerminal> 431 449 </RuleItem> 432 450 <RuleItem> … … 447 465 <Repetitive>0</Repetitive> 448 466 <Terminal>;</Terminal> 449 </RuleItem>450 <RuleItem>451 <Type>1</Type>452 <Optional>0</Optional>453 <Repetitive>0</Repetitive>454 <NonTerminal>FunctionParameters</NonTerminal>455 467 </RuleItem> 456 468 </RuleItems> … … 700 712 </RuleItems> 701 713 </Rule> 714 <Rule> 715 <Name>FunctionName</Name> 716 <RuleItems> 717 <Type>0</Type> 718 </RuleItems> 719 </Rule> 702 720 </Rules> 703 721 </GrammerProject>
Note:
See TracChangeset
for help on using the changeset viewer.