Compiler Design LAB MANUAL
April 20, 2017 | Author: Omkar Amrutanshu | Category: N/A
Short Description
Download Compiler Design LAB MANUAL...
Description
Laboratory Manual On
Compiler Design Lab CS-691
For 6 Semester Students CSE School: Computer Science & Engineering th
Author KIIT University, Bhubaneswar
LESSON PLAN Sl No.
Topics/Coverage
Week involved
1
Program to generate Lexical Tokens
1-2
2
Study of LEX tool
2-3
3
Design of a Recursive Descent Parser
4
Design of a Recursive Predictive Parser
5
Implementation of Non-Recursive Predictive Parsing Method
5-6
6
Implementation of Operator Precedence Parsing Method
6-7
7
Implementation of SLR Parsing Method
8
Study of YACC tool
HARDWARE /SOFTWARE
IBM-compatible 486 System Hard drive Min 8MB memory Win XP/7 C Complier Linux Operating System Tool : LEX/FLEX , YAAC
3-4 4-5
7-9 9-10
COMPILER DESIGN LAB SYLLABUS Lecture : -0
Tutorial : Practical :
-0
: - 3 Hrs/Week
Internal Assessment Marks: End Term Marks : Credits :
60 40 4
OBJECTIVES To introduce the student to Lexical analysis phase of a compiler. To teach the importance of a built-in tool like “FLEX” to implement the Lexical Analyzer. To provide an in-depth knowledge in various parsing techniques using C programming. To introduce the built-in tool “YACC” to implement parsing using various grammars.
COURSE OUTCOMES Able to understand the implementation of transition diagrams in tokenizing the lexemes of a source program. Able to understand the benefit of using built-in tool in tokenizing the lexemes of a source program by reducing the programmer’s effort. Able to to analyze and differentiate different Top-down parsing algorithms. Able to to implement various kinds of bottom-down parsing algorithms. Able to reduce the coding effort by using the built-in tool YACC in implementing bottom-up parsing for various program constructs.
MAPPING of CO to PO
COs POs Able to understand the implementation of transition diagrams in tokenizing the lexemes of a source program. Able to understand the benefit of using built-in tool in tokenizing the lexemes of a source program by reducing the programmer’s effort. Able to analyze and differentiate different Top-down parsing algorithms. Able to implement various kinds of bottom-down parsing algorithms. Able to reduce the coding effort by using the built-in tool YACC in implementing bottom-up parsing for various program constructs
a b c d e f g h i H M
H M
H
H M
H M
M
H
M M M
H
H
H M M
H
H
M H M
M
j k l M
List of Experiments: Assignment 1 Program for Lexical analysis by constructing symbol table, number table, operator table –implementing the DFAs for the token classes IDENTIFIERS, NUMBERS and OPERATORS. [Input:A source program in C,Output: symbol table, number table, operator table having two entries:Lexeme. Token class].
Assignment 2
Using LEX TOOL
Program for Lexical analysis by constructing symbol table, number table, operator table –implementing the DFAs for the token classes IDENTIFIERS, NUMBERS and OPERATORS. [Input :A source program in C,Output: symbol table, number table, operator table having two entries:Lexeme. Token class].
Assignment 3 Using LEX TOOL a. Program to count the number of vowels and consonants in a given file. b. Program to count the type of numbers in a given file. c. Program to count the number of printf and scanf in a given file. d. Program to count the number of identifiers in a given file. e. Program to count the number of words, characters, blank spaces and lines in a given file. f. Program to count the number of comment lines in a given file. g. Program to check the validity of arithmetic statement. h. Program to count the number of constants in a given file.
Assignment 4 Program for implementing Recursive Descent Parsing using the following grammar:
S cAd A ab |a
Assignment 5 Program for implementing Recursive Predictive Parsing using the following grammar: expr term expr ‘ expr’+term expr’|є term factor term’ term’ * factor term’| є factor id |(expr)
Assignment 6 Program for implementing Non-RecursivePredictive Parsing using the following grammar: expr term expr ‘ expr’+term expr’|є term factor term’ term’ * factor term’| є factor id |(expr)
Assignment 7 Program for implementing Operator-Precedence Parsing.
Assignment 8 Program for implementing Simple-LR Parsing using the following grammar: expr term expr ‘ expr’+term expr’|є term factor term’ term’ * factor term’| є factor id |(expr)
Assignment 9
Using YACC TOOL
a. Program for implementing a simple calculator using the following grammar: L E\n E E + T |T T T * F |F F (E) |digit b. Program for implementing an advance calculator using the following grammar: L LE\n|L\n | E E + E | E - E | E * E | E/E | (E) |-E |number
GUIDE LINES
Students must read the lab module and make necessary preparation for each session PRIOR TO coming to the lab. Each lab session will last for approximately THREE hours, which is divided into the following time slots: Instructor will give a brief demonstration during the allocated time and students will be given some hands-on exercises. Hence the students are expected to fully utilize this time to enquire the instructor/tutors regarding the subject matter. Students must:: i. Answer all the given questions ii. Report to the lab instructor and demonstrator to submit the answers before the lab ends No take-home assignment will be allowed. The code written by the student should meet the following: Program should have proper input prompt messages and descriptive output. Input validation should be done (data type, range error etc.) and give appropriate error messages and suggest corrective actions. Comment lines should be used to give problem statement, describe functions and key logics. Program should be indented properly. Variables and functions should be meaningfully named. All the students should sit according to their roll numbers starting from their left to right. All the students are supposed to enter the terminal number in the log book. Students should not change the terminal on which they are working. All the students are expected to get at least the algorithm of the program/concept to be implemented. Students should strictly observe the instructions given by the teacher/Lab Instructor. Students must be in the lab before the lab activities started. No late coming is tolerated without prior consent from the respective lecturer. During lab session any form of portable data storage and retrieval devices is prohibited. If found, then we reserve the right to confiscate the item and devoid your mark for that particular lab session. Duplicated lab assignment: the source and duplicate will be considered void. Submission procedure: a) Create a folder in the D: \ drive of your workstation. Name the folder with your ID number and your name. Example: 04xxxxxx Rahul Desai b) Save all your answers and source codes inside the folder. Name the files according to the question, example: question1.cpp/question1.txt. Completed lab assignment needs to be submitted to the instructor/demonstrator for inspection and assessment
SCHEME OF EVALUATION Maximum Marks for Compiler Design Lab is 100 which is divide into Mid-term and End-term Evaluations. The Mid-Term Evaluation (Continuous Evaluation over the semester) : 60 Marks The End-Term Evaluation (At the End of the Semester) : 40 Marks Minimum Marks for Passing in lab course: Mid-Term (40% of 60) = 24 Marks End-Term (40% of 40) = 16 Marks Total = 24+16=40 Marks
REFERENCES 1. 2. 3.
Compilers Principles,Techniques and Tools by Alfred V. Aho, Monica S. Lam, Ravi Sethi, Jeffery D. Ullman, Pearson Education , 2009. http://epaperpress.com/lexandyacc/download/LexandYaccTutorial.pdf. www.cse.iitk.ac.in/users/dsand/cs335/Mlex_tutorial.pdf.
View more...
Comments