#AUTHOR:ADWAITA JADHAV
CODES RELATED TO PRINCIPLES OF COMPILER DESIGN
Title: Lexical analyzer for sample language Aim: Generate lexical analyzer for sample language using LEX. Objective:
- To study lexical analysis phase.
- To understand lexical construct of any programming language.
- To study various ways of implementing lexical analyzer.
- To master LEX utility.
Theory: Write in brief:
- Token in any programming language –
- Lexeme and input buffer –
- Use of regular expression (RE) in specifying lexical structure of language –
- Format of source specification file ( *.l )
Input: Source specification ( *.l ) file for C language and input file ( *.c ) . Output: Sequence of tokens generated by lexical analyzer.
Title: Parser for sample language using YACC. Aim: Implement calculator using LEX and YACC tool.
Objective:
- To understand Yacc Tool.
- To study how to use Yacc tool for implementing Parser.
- To understand the compilation and execution of *.y file.
Theory: Write in brief for following:
- Introduction to Yacc –
- Study of *.y file-
- Description of Each Section of *.y file with example-
- Description of standard inbuilt variables and functions-
- Compilation and Execution Process-
Input: Output:
Title: Intermediate code generation for sample language using LEX and YACC. Aim: Generate intermediate code in the form of 3 address code (Quadruple implementation) using LEX and YACC. a. For arithmetic expression b. For any control structure
Objective:
- To understand need for intermediate code.
- To study intermediate code generation phase, different forms of intermediate code like 3 address code, syntax tree, postfix notation.
- To understand syntax directed translation scheme to avoid need for extra pass.
- To get need for type checking.
Theory: Write in brief for following:
- Abstract syntax directed translation scheme-
- Quadruples, triples, indirect triples
Input: LEX and YACC specification files for given programming language constructs, input file consisting of given piece of C program. Example input: A = b+c*d+-p; Output: ICG in the form of quadruples. OP ARG1 ARG2 RES UMINUS P - T1
- C D T2
- B T2 T3
- T3 T1 T4 = A T4 -
Title: Implementing recursive descent parser for sample language. Aim: Implement Recursive Descent parser for given grammar.
Objective:
- To study parsing phase in the compiler.
- To study types of parsers – top down and bottom up.
- Problems encountered during top down parser.
- How to write a top down parser.
Theory: Write in brief for following:
-
CFG, non-terminals, terminals, productions, derivation sequence-
-
Introduction to RDP:
-
Elimination of Left recursion:
-
Give Example:
Input: String satisfying given grammar, string not satisfying given grammar to test error condition. Output: Success for correct string, Failure for syntactically wrong string.
Title: Generating Abstract Syntax tree using LEX and YACC Aim: Implement parser with ambiguous CFG that recognize infix expression using LEX and YACC and perform semantic checking and generate syntax tree as output
Objective:
- To study Semantic Analyzer parsing phase.
- To understand semantic construct of programming language.
- To get used to parser generator, YACC.
- To understanding communication between LEX and YACC.
Theory: Explain following points in brief:
- Use of Context Free Grammar in specifying syntax of programming language, with specific example of C language.
- Working of lexical analyzer and parser as co-routines to avoid extra pass-
- Format of source specification file ( *.y ) for YACC –
- How tokens separated by lexical analyzer generated using LEX are made available to parser generated by YACC
- Types of Parser
Input: LEX and YACC source specification files for arithmetic grammar. Output: Generation of abstract syntax tree.
Aim: Writing a C /C++ program to implement local code optimization techniques like constant folding, copy propagation, common sub-expression elimination(Implementation of DAG algorithm). Objective:
- To understand the need and importance of code optimization.
- To study types of optimization - local and global.
- To know implementation of DAG.
Theory: Write in brief for following points:
- What is code optimization-.
- Types of code optimization – local and global
- Basic block, different local optimization techniques like constant folding, copy propagation, common sub-expression elimination.
- Directed acyclic graph – creation and traversal.
- Algorithm to generate DAG from quadruples.
Input: Intermediate code in the form of 3 address code (quadruple array). Output: Modified quadruples by applying above mentioned techniques.
Aim: Write a C program to generate code (in assembly language) using labeled tree.
Objective:
- To study code generation phase of compiler.
- Observe machine dependency of code generation process.
- To study the nature of target machine and nature of target code.
Theory: Write in brief for following points:
- Process of code generation
- Problem of register allocation and assignment
- Assumptions for code generation.
- Labeled tree and conversion to labeled tree.
Input: Intermediate code (for arithmetic expression) in the form of syntax tree. Output: Assembly code generated for given input.