Changeset 119 for branches/generator/Forms
- Timestamp:
- Nov 29, 2017, 12:31:26 PM (7 years ago)
- Location:
- branches/generator/Forms
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/generator/Forms/UFormMain.lfm
r118 r119 1 1 object FormMain: TFormMain 2 Left = 3 822 Left = 376 3 3 Height = 678 4 Top = 1954 Top = 202 5 5 Width = 1050 6 6 Caption = 'Language generator' … … 17 17 Width = 1050 18 18 Align = alClient 19 ScrollBars = ssAutoBoth 19 20 TabOrder = 0 20 21 end … … 67 68 object MenuItem2: TMenuItem 68 69 Caption = 'File' 70 object MenuItem11: TMenuItem 71 Action = ANew 72 end 69 73 object MenuItem4: TMenuItem 70 74 Action = AOpen 75 end 76 object MenuItem10: TMenuItem 77 Action = ASave 71 78 end 72 79 object MenuItem5: TMenuItem … … 126 133 OnExecute = ABuildCompilerExecute 127 134 end 135 object ASave: TAction 136 Caption = 'Save' 137 ImageIndex = 5 138 OnExecute = ASaveExecute 139 end 140 object ANew: TAction 141 Caption = 'New' 142 ImageIndex = 10 143 OnExecute = ANewExecute 144 end 128 145 end 129 146 object OpenDialog1: TOpenDialog -
branches/generator/Forms/UFormMain.pas
r118 r119 15 15 TFormMain = class(TForm) 16 16 ABuildCompiler: TAction; 17 ANew: TAction; 18 ASave: TAction; 17 19 AExit: TAction; 18 20 AOpen: TAction; … … 24 26 MemoBNF: TMemo; 25 27 MenuItem1: TMenuItem; 28 MenuItem10: TMenuItem; 29 MenuItem11: TMenuItem; 26 30 MenuItem2: TMenuItem; 27 31 MenuItem3: TMenuItem; … … 39 43 procedure ABuildCompilerExecute(Sender: TObject); 40 44 procedure AExitExecute(Sender: TObject); 45 procedure ANewExecute(Sender: TObject); 41 46 procedure AOpenExecute(Sender: TObject); 42 47 procedure ARulesExecute(Sender: TObject); 43 48 procedure ASaveAsExecute(Sender: TObject); 49 procedure ASaveExecute(Sender: TObject); 44 50 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); 45 51 procedure FormShow(Sender: TObject); 46 52 private 47 { private declarations }53 procedure ReloadMemo; 48 54 public 49 55 { public declarations } … … 70 76 FormRules.Rules := Core.Grammer.Rules; 71 77 FormRules.ShowModal; 72 MemoBNF.Lines.Text := Core.Grammer.GetBNF;78 ReloadMemo; 73 79 FreeAndNil(FormRules); 74 80 end; … … 82 88 end; 83 89 90 procedure TFormMain.ASaveExecute(Sender: TObject); 91 begin 92 Core.Grammer.SaveToXmlFile(Core.Grammer.FileName); 93 end; 94 84 95 procedure TFormMain.FormClose(Sender: TObject; var CloseAction: TCloseAction); 85 96 begin … … 90 101 begin 91 102 Core.PersistentForm1.Load(Self, True); 92 MemoBNF.Lines.Text := Core.Grammer.GetBNF; 103 ReloadMemo; 104 end; 105 106 procedure TFormMain.ReloadMemo; 107 begin 108 MemoBNF.Lines.Text := Core.Grammer.GetString; 93 109 end; 94 110 … … 98 114 end; 99 115 116 procedure TFormMain.ANewExecute(Sender: TObject); 117 begin 118 Core.Grammer.Rules.Clear; 119 ReloadMemo; 120 end; 121 100 122 procedure TFormMain.ABuildCompilerExecute(Sender: TObject); 101 var102 ParserFile: TStringList;103 SourceFile: TStringList;104 Rule: TRule;105 Item: TRuleItem;106 OutputDir: string;107 Line: string;108 I: Integer;109 123 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); 124 Core.Grammer.BuildCompiler; 200 125 end; 201 126 … … 205 130 if OpenDialog1.Execute then begin 206 131 Core.Grammer.LoadFromXmlFile(OpenDialog1.FileName); 132 ReloadMemo; 207 133 end; 208 134 end; -
branches/generator/Forms/UFormRule.lfm
r117 r119 15 15 Left = 376 16 16 Height = 25 17 Top = 4 7617 Top = 480 18 18 Width = 75 19 19 Anchors = [akLeft, akBottom] … … 25 25 Left = 168 26 26 Height = 25 27 Top = 4 7627 Top = 480 28 28 Width = 75 29 29 Anchors = [akLeft, akBottom] … … 41 41 end 42 42 object PageControl1: TPageControl 43 Left = 1644 Height = 42145 Top = 4843 Left = 8 44 Height = 392 45 Top = 80 46 46 Width = 640 47 47 ActivePage = TabSheet1 … … 63 63 TabOrder = 3 64 64 end 65 object CheckBoxCreateNode: TCheckBox 66 Left = 16 67 Height = 24 68 Top = 48 69 Width = 152 70 Caption = 'Create source node' 71 TabOrder = 4 72 end 65 73 end -
branches/generator/Forms/UFormRule.pas
r117 r119 16 16 ButtonOk: TButton; 17 17 ButtonCancel: TButton; 18 CheckBoxCreateNode: TCheckBox; 18 19 EditName: TEdit; 19 20 Label1: TLabel; … … 64 65 Self.Rule := Rule; 65 66 EditName.Text := Rule.Name; 67 CheckBoxCreateNode.Checked := Rule.CreateSourceNode; 66 68 FormRuleItems.LoadData(Rule.Items); 67 69 end; … … 70 72 begin 71 73 Rule.Name := EditName.Text; 74 Rule.CreateSourceNode := CheckBoxCreateNode.Checked; 72 75 FormRuleItems.SaveData(Rule.Items); 73 76 end; -
branches/generator/Forms/UFormRuleItems.pas
r117 r119 71 71 begin 72 72 if (Item.Index >= 0) and (Item.Index < RuleItems.Count) then begin 73 Item.Caption := RuleItems[Item.Index].Get BNF;73 Item.Caption := RuleItems[Item.Index].GetString; 74 74 Item.Data := RuleItems[Item.Index]; 75 75 end; … … 97 97 RuleItem: TRuleItem; 98 98 begin 99 RuleItem := TRuleItem(ListView.Selected.Data); 100 FormRuleItem := TFormRuleItem.Create(nil); 101 FormRuleItem.LoadData(RuleItem); 102 if FormRuleItem.ShowModal = mrOk then begin 103 FormRuleItem.SaveData(RuleItem); 104 ReloadList; 99 if Assigned(ListView.Selected) then begin 100 RuleItem := TRuleItem(ListView.Selected.Data); 101 FormRuleItem := TFormRuleItem.Create(nil); 102 FormRuleItem.LoadData(RuleItem); 103 if FormRuleItem.ShowModal = mrOk then begin 104 FormRuleItem.SaveData(RuleItem); 105 ReloadList; 106 end; 107 FreeAndNil(FormRuleItem); 105 108 end; 106 FreeAndNil(FormRuleItem);107 109 end; 108 110 -
branches/generator/Forms/UFormRules.lfm
r116 r119 72 72 end 73 73 item 74 Caption = 'Node' 75 Width = 80 76 end 77 item 74 78 Caption = 'Items' 75 Width = 62979 Width = 500 76 80 end> 77 81 MultiSelect = True -
branches/generator/Forms/UFormRules.pas
r117 r119 58 58 UFormRule, UCore; 59 59 60 const 61 BooleanText: array[Boolean] of string = ('No', 'Yes'); 62 60 63 { TFormRules } 61 64 … … 88 91 FormRule: TFormRule; 89 92 begin 90 Rule := TRule(ListView1.Selected.Data); 91 FormRule := TFormRule.Create(nil); 92 FormRule.LoadData(Rule); 93 if FormRule.ShowModal = mrOk then begin 94 FormRule.SaveData(Rule); 95 ReloadList; 93 if Assigned(ListView1.Selected) then begin 94 Rule := TRule(ListView1.Selected.Data); 95 FormRule := TFormRule.Create(nil); 96 FormRule.LoadData(Rule); 97 if FormRule.ShowModal = mrOk then begin 98 FormRule.SaveData(Rule); 99 ReloadList; 100 end; 101 FreeAndNil(FormRule); 96 102 end; 97 FreeAndNil(FormRule);98 103 end; 99 104 … … 123 128 Item.Caption := Rules[Item.Index].Name; 124 129 Item.Data := Rules[Item.Index]; 125 Item.SubItems.Add(Rules[Item.Index].Items.GetBNF); 130 Item.SubItems.Add(BooleanText[Rules[Item.Index].CreateSourceNode]); 131 Item.SubItems.Add(Rules[Item.Index].Items.GetString); 126 132 end; 127 133 end;
Note:
See TracChangeset
for help on using the changeset viewer.