- Timestamp:
- Nov 29, 2017, 5:09:16 PM (7 years ago)
- Location:
- branches/generator
- Files:
-
- 2 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/generator/Forms/UFormMain.lfm
r119 r124 80 80 Action = ASaveAs 81 81 end 82 object MenuItem12: TMenuItem 83 Action = AGrammerSettings 84 end 82 85 object MenuItem6: TMenuItem 83 86 Caption = '-' … … 143 146 OnExecute = ANewExecute 144 147 end 148 object AGrammerSettings: TAction 149 Caption = 'Settings' 150 OnExecute = AGrammerSettingsExecute 151 end 145 152 end 146 153 object OpenDialog1: TOpenDialog -
branches/generator/Forms/UFormMain.pas
r123 r124 15 15 TFormMain = class(TForm) 16 16 ABuildCompiler: TAction; 17 AGrammerSettings: TAction; 17 18 ANew: TAction; 18 19 ASave: TAction; … … 28 29 MenuItem10: TMenuItem; 29 30 MenuItem11: TMenuItem; 31 MenuItem12: TMenuItem; 30 32 MenuItem2: TMenuItem; 31 33 MenuItem3: TMenuItem; … … 43 45 procedure ABuildCompilerExecute(Sender: TObject); 44 46 procedure AExitExecute(Sender: TObject); 47 procedure AGrammerSettingsExecute(Sender: TObject); 45 48 procedure ANewExecute(Sender: TObject); 46 49 procedure AOpenExecute(Sender: TObject); … … 66 69 67 70 uses 68 UFormRules, UCore ;71 UFormRules, UCore, UFormGrammer; 69 72 70 73 { TFormMain } … … 123 126 end; 124 127 128 procedure TFormMain.AGrammerSettingsExecute(Sender: TObject); 129 var 130 FormGrammer: TFormGrammer; 131 begin 132 FormGrammer := TFormGrammer.Create(nil); 133 FormGrammer.LoadData(Core.Grammer); 134 if FormGrammer.ShowModal = mrOk then begin 135 FormGrammer.SaveData(Core.Grammer); 136 end; 137 FreeAndNil(FormGrammer); 138 end; 139 125 140 procedure TFormMain.ANewExecute(Sender: TObject); 126 141 begin -
branches/generator/Forms/UFormRuleItem.pas
r123 r124 100 100 ritNonTerminal: ListBox1.SetFocus; 101 101 ritSubItems: TFormRuleItems(FormRuleItems).ListView1.SetFocus; 102 ritTerminalRange: EditTerminalFrom.SetFocus; 102 103 end; 103 104 end; -
branches/generator/URules.pas
r123 r124 116 116 FileName: string; 117 117 Rules: TRules; 118 TopRule: TRule; 118 119 procedure LoadFromXmlFile(FileName: string); 119 120 procedure SaveToXmlFile(FileName: string); … … 149 150 Add(' Source;'); 150 151 Add(''); 151 Add('procedure Compile;'); 152 Add('procedure Compile(FileName: string);'); 153 Add('var'); 154 Add(' SourceFile: Text;'); 152 155 Add('begin'); 156 Add(' AssignFile(SourceFile, FileName);'); 157 Add(' Reset(SourceFile);'); 158 Add(' SetLength(Content, FileSize(SourceFile));'); 159 Add(' Read(SourceFile, Content);'); 160 if Assigned(TopRule) then 161 Add(' Parse' + TopRule.Name + ';'); 162 Add(' CloseFile(SourceFile);'); 153 163 Add('end;'); 154 164 Add(''); 155 165 Add('begin'); 156 Add(' Compile;'); 166 Add(' if ParamCount > 1 then'); 167 Add(' Compile(ParamStr(1));'); 157 168 Add('end.'); 158 169 SaveToFile(FileName); … … 181 192 Add(''); 182 193 Add('type'); 183 for Rule in Rules do begin 194 for Rule in Rules do 195 if Rule.CreateSourceNode then begin 184 196 Add(' T' + Rule.Name + ' = class;'); 185 197 end; 186 198 Add(''); 187 for Rule in Rules do begin 199 for Rule in Rules do 200 if Rule.CreateSourceNode then begin 188 201 Add(' T' + Rule.Name + ' = class'); 189 202 for Item in Rule.Items do begin … … 198 211 Add('implementation'); 199 212 Add(''); 200 for Rule in Rules do 201 if Rule.CreateSourceNode then begin 213 for Rule in Rules do begin 202 214 Add('function Parse' + Rule.Name + ': Boolean;'); 203 215 Add('begin'); … … 212 224 Line := Line + ''; 213 225 end; 214 if Item.RuleItemType = ritTerminal then 215 Line := Line + 'Expect(''' + Item.Terminal + ''')' 216 else if Item.RuleItemType = ritNonTerminal then 217 Line := Line + 'Parse' + Item.NonTerminal.Name; 226 case Item.RuleItemType of 227 ritTerminal: Line := Line + 'Expect(''' + Item.Terminal + ''')'; 228 ritNonTerminal: Line := Line + 'Parse' + Item.NonTerminal.Name; 229 ritTerminalRange: Line := Line + 'Expect(''' + Item.Terminal + ''')'; 230 end; 218 231 if Rule.Items.RuleType = rtOr then begin 219 232 Line := Line + ' then '; … … 245 258 RulesNode: TDOMNode; 246 259 Rule: TRule; 260 TopRuleName: string; 247 261 begin 248 262 Self.FileName := FileName; … … 257 271 Rules.LoadFromXmlNode(RulesNode); 258 272 end; 273 274 TopRule := Rules.FindName(ReadString(RootNode, 'TopRule', '')); 259 275 end; 260 276 finally … … 282 298 RootNode.AppendChild(RulesNode); 283 299 Rules.SaveToXmlNode(RulesNode); 300 301 if Assigned(TopRule) then 302 WriteString(RootNode, 'TopRule', TopRule.Name); 284 303 285 304 WriteXMLFile(Doc, FileName); -
branches/generator/generator.lpi
r118 r124 84 84 </Item3> 85 85 </RequiredPackages> 86 <Units Count=" 8">86 <Units Count="9"> 87 87 <Unit0> 88 88 <Filename Value="generator.lpr"/> … … 135 135 <ResourceBaseClass Value="Form"/> 136 136 </Unit7> 137 <Unit8> 138 <Filename Value="Forms/UFormGrammer.pas"/> 139 <IsPartOfProject Value="True"/> 140 <ComponentName Value="FormGrammer"/> 141 <ResourceBaseClass Value="Form"/> 142 </Unit8> 137 143 </Units> 138 144 </ProjectOptions> -
branches/generator/generator.lpr
r120 r124 9 9 Interfaces, // this includes the LCL widgetset 10 10 Forms, UCore, URules, Common, TemplateGenerics, UFormRule, UFormMain, 11 UFormRules, UFormRuleItem, UFormRuleItems, SysUtils 11 UFormRules, UFormRuleItem, UFormRuleItems, SysUtils, UFormGrammer 12 12 { you can add units after this }; 13 13 -
branches/generator/pascal.grm
r123 r124 358 358 <AnyExcept>0</AnyExcept> 359 359 <NonTerminal>ForToDo</NonTerminal> 360 </RuleItem> 361 <RuleItem> 362 <Type>1</Type> 363 <Optional>0</Optional> 364 <Repetitive>0</Repetitive> 365 <AnyExcept>0</AnyExcept> 366 <NonTerminal>ForInDo</NonTerminal> 360 367 </RuleItem> 361 368 <RuleItem> … … 562 569 <Repetitive>0</Repetitive> 563 570 <AnyExcept>0</AnyExcept> 564 <NonTerminal> BeginEnd</NonTerminal>571 <NonTerminal>DeclarationBlock</NonTerminal> 565 572 </RuleItem> 566 573 <RuleItem> … … 1270 1277 <Rule> 1271 1278 <Name>Term</Name> 1272 <CreateSourceNode> 0</CreateSourceNode>1279 <CreateSourceNode>-1</CreateSourceNode> 1273 1280 <RuleItems> 1274 1281 <Type>0</Type> … … 1662 1669 <Terminal>initialization</Terminal> 1663 1670 </RuleItem> 1671 <RuleItem> 1672 <Type>1</Type> 1673 <Optional>-1</Optional> 1674 <Repetitive>-1</Repetitive> 1675 <AnyExcept>0</AnyExcept> 1676 <NonTerminal>Statement</NonTerminal> 1677 </RuleItem> 1664 1678 </RuleItems> 1665 1679 </Rule> … … 1676 1690 <Terminal>finalization</Terminal> 1677 1691 </RuleItem> 1692 <RuleItem> 1693 <Type>1</Type> 1694 <Optional>-1</Optional> 1695 <Repetitive>-1</Repetitive> 1696 <AnyExcept>0</AnyExcept> 1697 <NonTerminal>Statement</NonTerminal> 1698 </RuleItem> 1678 1699 </RuleItems> 1679 1700 </Rule> … … 1762 1783 </RuleItems> 1763 1784 </Rule> 1785 <Rule> 1786 <Name>Procedure</Name> 1787 <CreateSourceNode>-1</CreateSourceNode> 1788 <RuleItems> 1789 <Type>0</Type> 1790 <RuleItem> 1791 <Type>0</Type> 1792 <Optional>0</Optional> 1793 <Repetitive>0</Repetitive> 1794 <AnyExcept>0</AnyExcept> 1795 <Terminal>procedure</Terminal> 1796 </RuleItem> 1797 <RuleItem> 1798 <Type>1</Type> 1799 <Optional>0</Optional> 1800 <Repetitive>0</Repetitive> 1801 <AnyExcept>0</AnyExcept> 1802 <NonTerminal>FunctionName</NonTerminal> 1803 </RuleItem> 1804 <RuleItem> 1805 <Type>1</Type> 1806 <Optional>-1</Optional> 1807 <Repetitive>0</Repetitive> 1808 <AnyExcept>0</AnyExcept> 1809 <NonTerminal>FunctionParameters</NonTerminal> 1810 </RuleItem> 1811 <RuleItem> 1812 <Type>0</Type> 1813 <Optional>0</Optional> 1814 <Repetitive>0</Repetitive> 1815 <AnyExcept>0</AnyExcept> 1816 <Terminal>;</Terminal> 1817 </RuleItem> 1818 <RuleItem> 1819 <Type>1</Type> 1820 <Optional>0</Optional> 1821 <Repetitive>0</Repetitive> 1822 <AnyExcept>0</AnyExcept> 1823 <NonTerminal>DeclarationBlock</NonTerminal> 1824 </RuleItem> 1825 <RuleItem> 1826 <Type>0</Type> 1827 <Optional>0</Optional> 1828 <Repetitive>0</Repetitive> 1829 <AnyExcept>0</AnyExcept> 1830 <Terminal>;</Terminal> 1831 </RuleItem> 1832 </RuleItems> 1833 </Rule> 1764 1834 </Rules> 1835 <TopRule>Program</TopRule> 1765 1836 </GrammerProject>
Note:
See TracChangeset
for help on using the changeset viewer.