Changeset 118 for branches/generator/Forms
- Timestamp:
- Nov 27, 2017, 5:10:04 PM (7 years ago)
- Location:
- branches/generator/Forms
- Files:
-
- 3 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
Note:
See TracChangeset
for help on using the changeset viewer.