International Conference on Systemics, Cybemetics and Informatics Automated Code Generation using Generative Programming Approach for a Mathematical Expression Sonali Idate Assistant Professor, Department of Computer Engineering and Information Technology,Bharati Vidyapeeth University college of Engineering ,Katraj-Dhankawadi, Pune -43, Maharashtra, India [email protected] Dipak J. Mali Suhas. H. Patil Professor Department of Computer Engineering and Information Technology,Bharati Vidyapeeth University college of Engineering .Katraj-Dhankawadi, Pune -43, Maharashtra, India Senior software engineer IBM India Global Services, TPO, Viman Nagar,Pune Maharashtra, India [email protected] [email protected] Abstract The compiler of high-level languages has the ability to transform a compact representation of a mathematical expression borrowed from mathematics into an equivalent but expansive and complexly interrelated series of assembly language instructions. This saves the programmer a significant amount of work because the mathematical expression is that are already inherently composite. Even when developers have recurring computer-readable metadata to process and a clear idea of how code should be structured, they can still find themselves in need of a technique to automatically generate the code for the mathematical formula. Generative programming is a technique that addresses this problem. Keywords Generative programming, lexical analysis, parsing, code generators, singleton pattern, template pattern 1. Introduction Even when developers have recurring computerreadable metadata to process and a clear idea of how code should be structured, they can still find themselves in need of a technique to automatically generate the code for the mathematical formula to avoid the drudge work of repeatedly writing and tweaking it An important paradigm shift is to replace manual search, adaptation, and assembly of components with the automatic generation of needed components on demand. One important paradigm shift implied here is to build software systems from standard componentry rather than "reinventing the wheel" each time. This requires thinking in adaptation, and assembly of components with the autoniatic generation of needed components on demand. Generative software engineering seeks to integrate domain engineering approaches, component-based approaches, and generative approaches.[4] Applying generative programming produces implementation code from three things: A means of specifying family members, the implementation components from which members can be assembled, The configuration knowledge mapping between a specification of a member and a finished inember. This article proposes that there is need to industrialise and mechanise the software development process to a much greater degree. The process should follow the following pattern: 1) Iteratively gather requirements and evolve a way to capture them in models. 2) Extend a code generation platform to derive and generate the application code lor a specific application platform, 3) Where it isn't cost effective to model and generate, write components that get weaved into the generated code and called at the appropriate points.[2.3] The proposed system Expression Code Generator (ExECG) follows above pattern and builds a sample template-driven code generator tor mathematical expression. 3. System Description 2. Relevance To Generative Programming . The goal of generative programming in software ~ engineering is to increase the productivity, quality, and time, ~ of system families rather than single systems. Another .unportant paradigm shift is to replace manual search, to. market in software development thanks to the deployment of both standard componentry and production automation. Copyright 0 2008 Number: CC-1.7 This peer-reviewed paper has been published by the Pentagram Research Centre (P) Limited. Responsibility of contents of this paper rests upon the authors and not upon Pentagram Research Centre (P) Limited. Copies can be obtained from the company for a cost Paper Identification Code Generators are programs that automatically generate high-level code (Java, C, C++ etc). ExECG follows partial class generator type architecture. Partial. class Generator A partial class generator builds a set of base classes to implement a design specitied in a definition file, These base classes are used as the platform to build the production classes. The base classes are designed to do the majority of the low level work of the completed class, leaving the derived class tree to override specific ~haviors. [1] 134 Automated Code Generation using Generative Programming Approach for a Mathematical Expression Defud 3.1.2 Code generator Template The formula for which the. code is required to be ,..... generated is parsed and validated against the defmed grammar rules. Other data viz. Math Rules, JavaDoc generation rules, ..." Control Structures rules are collected by parsing the respective XMLs and respective results are populated in respective " template factories. JcodeGenerator uses these results and the parsed formula results to generate the code. tion Flle 3.1.3 XML Document Parser As explained' earlier, the respective parsers viz. Math Rules, JavaDoc generation rules, control Structures roles are collected by parsing the respective XMLs and respective results are populated in respective template factories. JcodeGenentor uses these results and the parsed formula results to generate the code. Deriwi class Output Base class ClIS •• Souree Co. Co a., Sowrce 3.1.4 Template Factory Compiler The Template Factory is the collection of XML Templates used for generation of the code. By parsing xmls, the respective factory data objects are populated used while code generation. ,--- ---I I Executable I I I Figure I: Partbl Oat. Generamr (5) 4. System Design Features --------- Design patterns are about design and interaction of objects as well as providing a communication platform concerning elegant, reusable solutions to commonly encountered programming challenges 3.1 System Architecture XML 4.1 Singleton pattern DOC1UlleJlt RuaeraJld A class of which only a single instance can exist Whenever a user start ExCG and create an instance generating the code, the same instance should be used further as same generated code is required to be tested for the in puts provided by the user. Due to the above requirement, ExCG uses a singleton and processes the generated code with only one instance. Template P ~. Parser and FOrlllula er Rule 4.2 Adapter pattern Adapter classes convert the interface of a class into another interface clients expect In future, the user can generate code in multiple languages. In this situation, the user can directly plug in a already written code which parser' defined language roles (e.g. C++). In this scenario, the \,...",( has to write only an adapter and plug in the already written code and populate the factory objects. Temph.1r: Factory ._-- ---, I E:xecutable L 4.3 Facade pattern II FJgUe 2: F.xCGAxeJd~ture 3.1.1 Formula Generator The formula for which the code is required to be generated is parsed and validated against the defined grammar rules. In case of any exception, exception is handled by using Parse Exception. For parsing the formula and populate the data structures, parse Token Manager, Token, char stream etc are used and data is populated in grammar data. Facade provide an unified interface to a set of interfaces in a sub system. Facade defines a higher-level interface that makes the sub system easier to use. In this situation, the user wants generate and test the code for the formula Due to which its necessary to provide an interface which interacts with the sub systems (Formula parsing, XML parsing, Code generation etc) and provides the user the generated code. 5. User Interface Design The user interface (figure 3) shows command hierarchy that defines following major system menu categories. The menu bar, the tool palette and all sub ~ 135 l~ ~ " .\ . International Conference on Systemics, Cybernetics and Informatics Text box is provided to build an expression. Make use of SYmbolview to choose numbers, operators and functions. Note that whole expression must be equated to "-C. To reset the expression Usee can use "Undo" button. functions. The GUI contains the button hierarchy as: to enter the mathematical formula. update, save and undo the changes. The tool bar contains the icons for code generation, edition, save, and test the developed code. The menu bar contains the operation as code generation, edition, save, and test the developed code. Middle window is reserved to display the JAVA code generated for specified mathematical expression. Lower window is used to display messages, exceptions, and evaluation of execution results. . 6.2 Code Generation User must provide valid expression in the expression view and pressing "Generate "button code will get generated in the code view. Generated code is editable in the code view that is user can modify the generated code as per his coding stan co, cut and aste wherever wants __ m m;«jM.lIlc.l4i:bl; i!n;:orljMJ4.~ C1aSSJj~si:lIi'irser , f , lIl'.i.tdoiAllt( :l jlJt~:5oubIe~ss;orJl:M(,~o,~ ••,.:lkb._l,dout.s.dOol>e,,~;Jo;e~ 5" 1 do'~ j STllP.~~ gelcosW(l5.Gj; :'U~. STDRIIr.!\'8 gelsrt/a:(J). ! =<~: ~elm'tfj: ~'STDfltUn'y~ . ~ ReUl!'rh a>t; C(.u~eFRI!IJIlYa!e=~5.1' .•lI!r;;lI3. acutle~~ ~,..rJ:R~ Figure :Ex-CG GUI ; .•.• s: ~3PfR.~II;I>.W4~.cwl5l; d.:lI.'II~STDRWn'ilE: fII3inY;~.5.m: ... =-~.==,=,~-=--=.= .. ==~ The rightmost window is used to initialize the variables in order to test the generated JA VA code. .~~~~= 6. Using Ex-CG 6.3 Verification The design of Ex-CG is founded on flexibility. It can serve small organization intent on having quality coding practices consistently implemented throughout the organization. Improved coding practices will be quickly propagated and will stay with the organization even if star programmershave left. Knowledge stays and accumulateswith the orgaaization, neatly encapsulated in the template library. To run the generated code use "Test" button. Code will get executed for user defined values of variables in the variable view and corresponding output will get displayed in =. =. Figure 5: Expression View oftbe developed code ~~~J;;::;l'Bft%~~Jdm§?4'f%tw@;¥fW¥'''':-:''''< ="9 ~[valuat:incr the e.nte"ion.. .. ~Re:sU1C ot ["re,.dOD tor aivlI!%lvalue!!! : 7S617.7ZHi9299243 l j l " l If :j 1 I. ~ L--. , ... ,_, ~ ._~ Figure 4: Message View 7. Benefits 7.1 Measurable Productivity Gains Generating code by definition is always going to be much faster than hand coding. The productivity gain when writing the mathematical code is at least 70"10, with the coding part of the design,code, and test cycle eliminated 7.2 Higber Quality Generated code is error free and well designed Development teams are more consistent Automatic code generation ensures that software developers are more likely to be focused on the business requirements than the more mundane task of coding. Figure 4: Expression View /' 136 Automated Code Generation using Generative Programming Approach for a Mathematical Expression 7.3 Lower Maintenance Costs 9. References The code generated by Ex-COG will be very easy to understand and therefore easier to maintain. The true longtenn value of code generation emerges when there are new business requirements. Ongoing maintenance costs are reduced because it is easier to regenerate code than to make manual code changes • • • 8. Conclusion The system can take place as a plug-in component It simplifies coding to those developers who are frequently racing mathematical expressions. Thus helping them to do the best of actual problem. • The xJen Architecture by Michel . Katz (http://www.codegeneration.netltiki-re8(Carticle.php? articleId=32) Generative and Component-Based Software Engineering (http://www-ia.tuiimenau.deJ-czarnlgenerateJengi.html) Generative Programming: Modem Techniques to Automate Repetitive Programming Tasks: MSDN Magazine, December 2001. Generative Programming - Methods, Tools, and Applications by Krzysztof Czarnecki and Ulrich W. Eisenecker(http://www.generativeprogramming.org)€ode Generator Model http://www.codegeneration.net/tikiindex. ~, \ 137
© Copyright 2026 Paperzz