Compiler_Project_Srikanth_Vanama

701 views
671 views

Published on

2 Comments
1 Like
Statistics
Notes
No Downloads
Views
Total views
701
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
2
Likes
1
Embeds 0
No embeds

No notes for slide
  • January 29, 2010
  • Compiler_Project_Srikanth_Vanama

    1. 1. Srikanth Vanama Computer Science Graduate Student Clemson University
    2. 2. <ul><li>Name : Srikanth Vanama </li></ul><ul><li>School : Clemson University </li></ul><ul><li>Major : Computer Science </li></ul><ul><li>Qualification : Master in Computer Science, Clemson, South Carolina, USA. </li></ul><ul><li>This Project : Implemented during the second semester of my graduate study. </li></ul>January 29, 2010
    3. 3. <ul><li>University Profile. </li></ul><ul><li>System Environment. </li></ul><ul><li>What is a Compiler. </li></ul><ul><li>Reasons to choose this project </li></ul><ul><li>Compiler Developed for? </li></ul><ul><li>Lexical Analyzer </li></ul><ul><li>Parser </li></ul><ul><li>Semantic Analyzer </li></ul><ul><li>Code Generation </li></ul><ul><li>Conclusion </li></ul><ul><li>Questions </li></ul>
    4. 4. <ul><li>Clemson University offers countless opportunities for students, faculty and community members to participate in decades of tradition, improve quality of life for their surrounding communities and pursue academic challenges. </li></ul><ul><li>Ranked as the 22nd best national public university by U.S.News and World Report </li></ul><ul><li>Computer Science offers students the opportunity for classroom study and research in the underlying theory of computation, algorithms, Compilers, Software engineering, CyberInfrastructure and other core areas of traditional computer science. </li></ul>January 29, 2010
    5. 5. <ul><li>Hardware Configuration </li></ul><ul><li>Processor : Intel Pentium-IV (2.23 GHz) </li></ul><ul><li>Hard Disk : 64 GB </li></ul><ul><li>RAM : 512 MB </li></ul><ul><li>Software Configuration </li></ul><ul><li>Operating System : Windows, Mac OSX, Linux </li></ul><ul><li>Technologies : Perl, Java Script </li></ul><ul><li>Tools : Active Perl, Komodo </li></ul><ul><li>Assembler Linkers : HLA </li></ul>January 29, 2010
    6. 6. <ul><li>A Compiler is a Computer Program that translate source code from a high-level programming language to a lower level language (e.g. machine code or assembly language) </li></ul><ul><li>The reason for this is to create an executable program to generate the output of the source program </li></ul><ul><li>Involves operations like </li></ul><ul><ul><li>Lexical Analysis </li></ul></ul><ul><ul><li>Parsing </li></ul></ul><ul><ul><li>Semantic Analysis </li></ul></ul><ul><ul><li>Code Generation </li></ul></ul><ul><ul><li>Code Optimization </li></ul></ul>January 29, 2010
    7. 7. <ul><li>Required programming knowledge on a high scale. </li></ul><ul><li>Opportunity to implement a newly learnt programming language in a full scale real time project. </li></ul><ul><li>To take on a challenging project. </li></ul><ul><li>Build my own compiler. </li></ul><ul><li>Analyze performance differences between Intel and SPARC architectures. </li></ul>
    8. 8. <ul><li>a new programming language with pre-defined syntax and semantics </li></ul><ul><li>A Context-Free Grammar (CFG) is associated with the new language for which the compiler was built. </li></ul><ul><li>A CFG is defined with various constraints and reduction policies. </li></ul>January 29, 2010
    9. 9. <ul><li>The Lexical Analyzer is a procedure that is called every time a token is needed by the parser. </li></ul><ul><li>Tokens are generated based on different criteria from a string of characters from the source code. </li></ul><ul><li>A Token can be of various types. </li></ul><ul><ul><li>Integers, Real values, Reserved Words, Comments, Identifiers, ASCII characters, Multiple ASCII characters. ( Tell Examples here ) </li></ul></ul><ul><li>It returns only lexically correct entities and detects certain error conditions. </li></ul><ul><li>If an error is found, it prints an informative message and continues operation until a valid token is found and returned. </li></ul><ul><li>Example a+b-(c*d) </li></ul>January 29, 2010
    10. 10. <ul><li>Examples of Tokens: </li></ul><ul><li>Identifiers: start with a lower case letter and may contain up to 31 additional lower case letters, digits, -s, and _s. </li></ul><ul><li>Integers: d+, +d+, -d+, where the + represents a continuous sequence of 9 or less significant digits. </li></ul><ul><li>Real Values: as d+.d+, +d+.d+, or -d+.d+ where the total number of significant digits does not exceed 7. </li></ul><ul><li>ASCII Characters: ;,_,-,,,[,],(,),:,!,<,>,+,-,*,/,{.} </li></ul><ul><li>Multiple ASCII Characters: ==, !=, <=, >=, <-, ::, ||, && </li></ul>January 29, 2010
    11. 11. January 29, 2010
    12. 12.
    13. 13. <ul><li>Simple Precedence Parsing mechanism is employed for the language. </li></ul><ul><li>Conditions for a simple precedence grammar </li></ul><ul><ul><li>all right hand sides are unique </li></ul></ul><ul><ul><li>there are no empty right hand sides and </li></ul></ul><ul><ul><li>at most one simple precedence relation holds between pairs of symbols in the grammar. </li></ul></ul>January 29, 2010
    14. 14. <ul><li>Example of a simple precedence grammar: </li></ul><ul><li>E  E+T </li></ul><ul><li>E  T </li></ul><ul><li>T  T*P </li></ul><ul><li>T  P </li></ul><ul><li>P  (E) </li></ul><ul><li>P  V </li></ul>January 29, 2010
    15. 15. <ul><li>The Parser takes input from Lexical Analyzer and the relations defined by the context free grammar. </li></ul><ul><li>The Parser examines each token and reduces accordingly using the rules specified in the grammar. </li></ul><ul><li>Constructs a syntax tree for the source program that we intend to parse. </li></ul>January 29, 2010
    16. 16. <ul><li>This routine is called between the spot where the parser has identified which reduction to make and before that reduction is made. </li></ul><ul><li>Reduction number is passed to the semantic routine. </li></ul><ul><li>The semantic routine will perform the semantics associated with that production and return to the parser to make the syntactic reduction and the corresponding stack reduction. </li></ul>January 29, 2010
    17. 17. <ul><li>The semantic structure of the grammar is constructed. </li></ul><ul><li>Includes three important tasks: </li></ul><ul><li>Storing the variables in the symbol table and setting attributes of those variables in the symbol table </li></ul><ul><li>Maintain a semantic stack that has a 1:1 correspondence with the syntax stack. This semantic stack will be used to store or remember information from one reduction to the next. </li></ul><ul><li>Produces intermediate code, such as 4-tuples to indicate an arithmetic operation, a label, a jump, a conditional test, etc. ( Generate 4-tuples) </li></ul>January 29, 2010
    18. 18. <ul><li>For the Production </li></ul><ul><ul><li>decstat  decstat, var </li></ul></ul><ul><ul><li>The stacks look like </li></ul></ul><ul><ul><li>Example statement for the above production looks like </li></ul></ul><ul><ul><li>VECTOR aqz ELEMENTS 50, bxw, lm </li></ul></ul>January 29, 2010
    19. 19. <ul><li>A 4-tuple is in the format </li></ul><ul><li>(Result, Operator, Operand, Operand) </li></ul><ul><li>Example: </li></ul><ul><li>(S i , SUM, S i-2 , S i-3 ) </li></ul><ul><li> (S i-2 , MEMORY, S i-1 , S i-3 ) </li></ul>January 29, 2010
    20. 20. <ul><li>At this stage of the project we have translated our source program into a sequence of 4-tuples, called intermediate code. </li></ul><ul><li>The 4-tuples are intermediate code in the sense that they reside between the source code and assembly code or machine code. </li></ul><ul><li>The idea behind code generation is to take our intermediate code, the 4-tuples, and generate assembly code for a specific hardware platform and operating system. (INTEL or SPARC) </li></ul><ul><li>This is the first place that we get specific about the computer system that our source program will execute on. </li></ul>January 29, 2010
    21. 21. <ul><li>Do appropriate register allocation based on the target machine’s architecture and memory constraints. </li></ul><ul><li>Assembly code is resulted for the source program. </li></ul><ul><li>The generated Assembly code is given as an input to Assembler linker to finally generate the output of the source program. </li></ul><ul><li>The Assembler linker used for this project is HLA. </li></ul>January 29, 2010
    22. 22. <ul><li>Implemented in Perl. </li></ul><ul><li>Scripting made easy. </li></ul><ul><li>Optimize use of stacks which resulted in efficient memory management </li></ul><ul><li>Employed Innovative Parsing techniques to generate tokens. </li></ul>January 29, 2010
    23. 23. <ul><li>The most challenging project ever done. </li></ul><ul><li>Understood the entire SDLC process which includes </li></ul><ul><ul><li>Requirement Analysis </li></ul></ul><ul><ul><li>Design </li></ul></ul><ul><ul><li>Coding </li></ul></ul><ul><ul><li>Testing </li></ul></ul><ul><ul><li>Implementation </li></ul></ul><ul><ul><li>Code Optimization </li></ul></ul>January 29, 2010
    24. 24. <ul><li>Acquired new skills from different phases of the project. </li></ul><ul><li>Lexical Analysis – Patience </li></ul><ul><li>Parsing – Problem Solving Skills, Time Management </li></ul><ul><li>Semantics Analysis – Algorithmic approach </li></ul><ul><li>Code Generation – Memory Management, Efficiency </li></ul>January 29, 2010
    25. 25. <ul><li>Thank you </li></ul><ul><li>Any Queries ?! </li></ul><ul><li>SRIKANTH VANAMA </li></ul>January 29, 2010

    ×