MLR Institute of Technology Dundigal, Quthbullapur (M), Hyderabad
|
|
- Miles Nichols
- 6 years ago
- Views:
Transcription
1 MLR Institute of Technology Dundigal, Quthbullapur (M), Hyderabad Course Name Course Code : Class Branch COMPUTER SCIENCE AND ENGINEERING COMPILER DESIGN LAB MANUAL : COMPILER DESIGN : III B. Tech II Semester Year : Course Faculty OBJECTIVES : Computer Science and Engineering : Mrs. K. Archana, Assistant Professor Mrs. Durga Sree, Assistant Professor To meet the challenge of ensuring excellence in engineering education, the issue of quality needs to be addressed, debated and taken forward in a systematic manner. Accreditation is the principal means of quality assurance in higher education. The major emphasis of accreditation process is to measure the outcomes of the program that is being accredited In line with this, Faculty of Institute of MLR Institute of Technologuy, Hyderabad has taken a lead in incorporating philosophy of outcome based education in the process of problem solving and career development. So, all students of the institute should understand the depth and approach of course to be taught through this question bank, which will enhance learner s learning process.
2 COMPILER DESIGN LAB SYSTEM REQUIREMENTS 1. Intel based desktop PC of 166MHz or faster processor with at least 64 MB RAM and 100 MB free disk space. 2. C compiler LAB OBJECTIVES 1. To provide an Understanding of the language translation peculiarities by designing complete translator for mini language. 2. To provide an understanding of the design aspect of operating system SYLLABUS 1. Design a Lexical analyzer for the above language. The lexical analyzer should ignore redundant spaces, tabs and newlines. It should also ignore comments. Although the syntax specification states that identifiers can be arbitrarily long, you may restrict the length to some reasonable value. 2. Implement the lexical analyzer using flex, flex or lex or other lexical analyzer generating tools. 3. Design Predictive parser for the given language 4. Design SLR bottom up parser for the above language. 5. Convert the BNF rules into Yacc form and write code to generate abstract syntax tree. 6. Write program to generate machine code from the abstract syntax tree generated by the parser. following instruction set may be considered as
3 LAB CODE Students should report to the concerned lab as per the time table. Students who turn up late to the labs will in no case be permitted to do the program schedule for the day. After completion of the program, certification of the concerned staff in-charge in the observation book is necessary. Student should bring a notebook of 100 pages and should enter the readings /observations into the notebook while performing the experiment. The record of observations along with the detailed experimental procedure of the experiment in the immediate last session should be submitted and certified staff member in-charge. Not more than 3-students in a group are permitted to perform the experiment on the set. The group-wise division made in the beginning should be adhered to and no mix up of students among different groups will be permitted. The components required pertaining to the experiment should be collected from stores in-charge after duly filling in the requisition form. When the experiment is completed, should disconnect the setup made by them, and should return all the components/instruments taken for the purpose. Any damage of the equipment or burn-out components will be viewed seriously either by putting penalty or by dismissing the total group of students from the lab for the semester/year. Students should be present in the labs for total scheduled duration. Students are required to prepare thoroughly to perform the experiment before coming to laboratory.
4 EXPERIMENT : 1 NAME OF THE EXPERIMENT: Design A Lexical Analyzer AIM Design a Lexical analyzer. The lexical analyzer should ignore redundant s tabs and new lines. It should also ignore comments. Although the syntax specification s those identifiers can be arbitrarily long, you may restrict the length to some reasonable Value. THEORY Lexical analyzer or scanner is the process where the stream of characters making up the source program is read from left-to-right and grouped into tokens. Tokens are sequences of characters with a collective meaning. There are usually only a small number of tokens for a programming language: constants (integer, double, char, string, etc.), operators (arithmetic, relational, logical), punctuation, and reserved words. ALGORITHM step1: Start step2: Declare the variable char exp[20],id[10],dig[10],ch, int i,j; step3: Enter the "enter expression:"; step4: Read the expression step5: Initialize i=0 step6: Repeat step 5 until i<strlen(exp); upto step 25 step7: Assign ch=exp[i]; step8: Declare j=0; step9: Repeat step 8 (ch>='a'&&ch<='z') upto step14 step10: Assign id[j++]=ch; step11: Increment i =i+1 step12: Repeat step 11 while((exp[i]>='a'&&exp[i]<='z') (exp[i]>='0'&&exp[i]<='9')) upto step12 step13: Assign id[j++]=exp[i++] step14: Declare id[j]='\0' step15: Display " identifier" step16: Otherwise repeat step 15 if(ch=='+' ch=='-' ch=='*' ch=='/' ch=='%' ch=='=')upto step17 step17: Display "operator" step18: Increment i=i+1 step19: Otherwise repeat step 18 if(ch>='0'&&ch<='9')upto step24 step20: Assign dig[j++]=ch step21: Increment i=i+1 step22: Repeat while(exp[i]>='0'&&exp[i]<='9') step23: Assign dig[j++]=exp[i++];
5 step24: Declare dig[j]='\0'; step25: Display "constant" step26: Stop OUTPUT VIVA QUESTIONS 1. What is lexical analyzer? 2. Which compiler is used for lexical analyzer? 3. What is pattern? 4. What is the output of Lexical analyzer? 5. What is the lexeme? 6. what is the token?
6 EXPERIMENT: 2 NAME OF THE EXPERIMENT: Implement lexical analyzer using lexical analyzer generating tools. AIM: Implement the lexical analyzer using JLex, flex or lex other lexical analyzer generating tools. THEORY Lex tool used to generate lexical analyzers and parsers. The Overview describes the basic building blocks of a compiler and explains the interaction with lex. Conventional arithmetic operations and control statements, such as ifelse and while, are implemented. ALGORITHM: Step1: Step2: Step3: Step4: Step5: Start Declare the declarations for the given language tokens like digit, alphabet, white space, delimiters, etc. digit[0-9] letter[a-z a-z] delim[\t\n] W$delim+ID(letter)(letter/digit)+ Integer digit+ % % ws print ( SpecialCharacters ) ID print( Identifiers ) digit print( \n Integer) if printf( keyword ) else print(keyword) & & print(logoical operators) > print(logoical operators) < print(logoical operators) <= print(logoical operators) >= print(logoical operators) = printf( \n \n )! printf( \n \n ) + printf( arithmetic operator ) - printf ( arithmetic ) * printf( arithmetic ) % printf(arithmetic ) % % printf( arithmetic ) Write the auxillary procedure in main() function end Stop OUTPUT [root@localhost]# lex lexprog.l [root@localhost]# cc lex.yy.c [root@localhost]#./a.out lexprog
7 VIVA QUESTIONS 1. What is Parsing? 2. What is Token? 3. How many section in LEX program? 4. What is meant by extension of dot l(.l) in LEX? 5. What is the syntax of LEX compiler program to save it? 6. what is the output command of LEX?
8 EXPERIMENT: 3 NAME OF THE EXPERIMENT : Predictive Parser of the RECURSIVE DESCENT PARSER AIM : Design Predictive Parser of the RECURSIVE DESCENT PARSER given language Input String: cdefbcdbccdefbcdabcdefdef THEORY Recursive descent parsing is probably the most well-known and intuitive technique applicable to a subclass of context-free grammars. A subroutine for each non-terminal should determine a rule according to which the substring shall be parsed. Parse Tree:
9 ALGORITHM: Step1: Start Step2: Declaration of the functions int S(),int A(),int B(),int C(),int D(); Step3: Declare the variable char input[100];int i; Step4: Enter the string Step5: Read the by gets(input); Step6: The given input is true when (S()==1) Step7: Print string is accepted Step8: Otherwise print string is not accepted Step 9: called method int S() j if(a()==1) if(b()==1) if(input[i]=='a') if(input[i]=='b') if(c()==1) if(d()==1) if(input[i]=='e') if(input[i]=='f') return 1; Step10: called method int A() if(b()==1) if(input[i]=='b') if(input[i]=='c') return 1;
10 Step11: called method int B() if(c()==1) if(input[i]=='b') if(input[i]=='c') if(input[i]=='d') return 1; Step12: Called method int C() if(input[i]=='c') if(input[i]=='d') if(input[i]=='e') if(input[i]=='f') return 1; Step13: Called method int D() if(input[i]=='d')
11 return 1; Step14: Stop OUTPUT
12 VIVA QUESTIONS 1. What is Predictive parser? 2. How many types of analysis can we do using Parser? 3. What is Recursive Decent Parser? 4. What is LR Parser? 5. What is back Tracking? 6. What are the problems in Top-Down parsing?
13 EXPERIMENT: 4 NAME OF THE EXPERIMENT: Design of SLR AIM: Design SLR bottom up parser for the above language THEORY The easiest technique for generating LR-based parse table is known as SLR (Simple LR).Understanding this technique should provide and what you need to know to understand how LR parsers work in general. Remember that the idea behind LR parsing is to produce a DFA that defines the handles (string of terminals and non-terminals that indicate a reduction) of the input language. The SLR technique is based on generating sets of LR(0) items that describe the states of the DFA, as well as a transition function that maps between these states. Defn: An LR(0) item of a grammar G is a production of G with a dot (.) at some point on the right side. Defn: Closure(I) where I is a set of LR(0) items consists of Every item in I If A -> α. B β in closure(i), for all productions B -> γ, add B ->. γ to closure(i) if not already there. Keep applying this rule until no more items can be added. Initial elements (I) are often referred to as the kernel elements of closure(i). Defn: Goto(I,X), where I is a set of items, X is a terminal or non-terminal, is the closure(a a X. b) where A a. X b is in I. Algorithm: C =closure(s. S), where S S is the production added for augmentation Repeat For each item I in C and grammar symbol X such that Goto(I,X) is not empty and not in already an element of C Add Goto(I,X) to C ALGORITHM Step1: Start Step2: Initially the parser has s0 on the stack where s0 is the initial state and w$ is in buffer Step3: Set ip point to the first symbol of w$ Step4: repeat forever, begin Step5: Let S be the state on top of the stack and a symbol pointed to by ip Step6: If action [S, a] =shift S then begin Push S1 on to the top of the stack Advance ip to next input symbol Step7: Else if action [S, a], reduce A->B then begin Pop 2* B symbols of the stack Let S1 be the state now on the top of the stack Step8: Output the production A B End Step9: else if action [S, a]=accepted, then return Else Error() End Step10: Stop
14 TEST CASES OUTPUT1 OUTPUT2 VIVA QUESTIONS 1. What is SLR parsing? 2. What is Shift reduced parser? 3. What are the operations of Parser? 4. What is the use of parsing table? 5. What is bottom up parsing?
15 EXPERIMENT: 5 NAME OF THE EXPERIMENT: Convert the BNF rules into YACC AIM: Convert the BNF rules into YACC form and write code to generate abstract syntax tree THEORY Yacc is a tool for building syntax analyzers, also known as parsers, yacc has been used to implement hundreds of languages. Its applications range from small desk calculators, to medium-sized preprocessors for typesetting, to large compiler front ends for complete programming languages. A yacc specification is based on a collection of grammar rules that describe the syntax of a language; yacc turns the specification into a syntax analyzer. A pure syntax analyzer merely checks whether or not an input string conforms to the syntax of the language. ALGORITHM: Step1: Start Step2: declare the declarations as a header file include<ctype.h> Step3: token digit Step4: define the translations rules like line, expr, term, factor Line:exp \n print( \n %d \n,$1) Expr:expr + term ($$=$1=$3 Term:term + factor($$ =$1*$3 Factor Factor: ( enter ) $$ =$2) % % Step5: define the supporting C routines Step6: Stop OUTPUT: [root@localhost]# lex codegen.l [root@localhost]# yacc d codegen.y [root@localhost]# cc lex.yy.c y.tab.c ll -lm [root@localhost]#./a.out INPUT OUTPUT VIVA QUESTIONS 1. What is Abstract Syntax tree? 2. What are BNF Rules? 3. What is DAG representation? 4. How LALR(1) states are generates? 5. In which condition the user has to supply more information to YACC?
16 EXPERIMENT : 6 NAME OF THE EXPERIMENT: To generate machine code AIM: Write program to generate machine code from the abstract syntax tree generated by the Parser.The following instruction set may considered as target code. THEORY Machine code, also known as machine language, is the elemental language of computers, comprising a long sequence of binary digital zeros and ones ALGORITHM Step1: Step2: Step3: Step4: Step5: Step6: Step7: Step8: Step9: Start for every three address statement of the form x=y op z begin Call getreg() to obtain the location L which the computation y op z should be performed Obtain the current location of the operand y by consulting its address descriptor,and if the values of Y are currently both in the memory location as well as in the register, then prefer the register.if the value of y is not currently available in 1,then generate an instruction MOV y,l Generate the instruction OP Z,l and update the address descriptor of X to indicate that X is now available in l and in register then update t\ its descriptor to indicate that it will contain the run time value of x If the current values of y ad/or z are in register and we have no further use for them,and they are live at the end of the block,then after the register descriptor to indicate that after the execution of the statem,ent x=y op z,those registers will no longer contain y and / or z. store all results Stop OUTPUT
17 VIVA QUESTIONS 1. What is target code? 2. What is machine code? 3. What is Cross compiler? 4. Give the example for cross compiler? 5. What is the difference between syntax & Semantics? Prepared by: Mrs K. Archana, Mrs. Durga Sree HOD, COMPUTER SCIENCE AND ENGINEERING
18
INSTITUTE OF AERONAUTICAL ENGINEERING (AUTONOMOUS)
Name Code Class Branch INSTITUTE OF AERONAUTICAL ENGINEERING (AUTONOMOUS) Dundigal, Hyderabad - 500 043 Year 0-0 INFORMATION TECHNOLOGY ASSIGNMENT QUESTIONS AUTOMATA AND COMPILER DESIGN A50513 III B. Tech
More informationINSTITUTE OF AERONAUTICAL ENGINEERING
INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad - 00 043 INFORMATION TECHNOLOGY TUTORIAL QUESTION BANK Name AUTOMATA AND COMPILER DESIGN Code A03 Class III B. Tech I Semester Branch
More informationFormal Languages and Compilers Lecture VII Part 3: Syntactic A
Formal Languages and Compilers Lecture VII Part 3: Syntactic Analysis Free University of Bozen-Bolzano Faculty of Computer Science POS Building, Room: 2.03 artale@inf.unibz.it http://www.inf.unibz.it/
More informationYacc: A Syntactic Analysers Generator
Yacc: A Syntactic Analysers Generator Compiler-Construction Tools The compiler writer uses specialised tools (in addition to those normally used for software development) that produce components that can
More informationContext-free grammars
Context-free grammars Section 4.2 Formal way of specifying rules about the structure/syntax of a program terminals - tokens non-terminals - represent higher-level structures of a program start symbol,
More informationCOMPILER CONSTRUCTION LAB 2 THE SYMBOL TABLE. Tutorial 2 LABS. PHASES OF A COMPILER Source Program. Lab 2 Symbol table
COMPILER CONSTRUCTION Lab 2 Symbol table LABS Lab 3 LR parsing and abstract syntax tree construction using ''bison' Lab 4 Semantic analysis (type checking) PHASES OF A COMPILER Source Program Lab 2 Symtab
More informationCompiler Construction: Parsing
Compiler Construction: Parsing Mandar Mitra Indian Statistical Institute M. Mitra (ISI) Parsing 1 / 33 Context-free grammars. Reference: Section 4.2 Formal way of specifying rules about the structure/syntax
More informationINSTITUTE OF AERONAUTICAL ENGINEERING
INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad -500 043 INFORMATION TECHNOLOGY TUTORIAL QUESTION BANK Name : PRINCIPLES OF PROGRAMMING LANGUAGES Code : A40511 Class : II B. Tech
More informationSection A. A grammar that produces more than one parse tree for some sentences is said to be ambiguous.
Section A 1. What do you meant by parser and its types? A parser for grammar G is a program that takes as input a string w and produces as output either a parse tree for w, if w is a sentence of G, or
More informationCompiler Design 1. Bottom-UP Parsing. Goutam Biswas. Lect 6
Compiler Design 1 Bottom-UP Parsing Compiler Design 2 The Process The parse tree is built starting from the leaf nodes labeled by the terminals (tokens). The parser tries to discover appropriate reductions,
More informationSYED AMMAL ENGINEERING COLLEGE (An ISO 9001:2008 Certified Institution) Dr. E.M. Abdullah Campus, Ramanathapuram
CS6660 COMPILER DESIGN Question Bank UNIT I-INTRODUCTION TO COMPILERS 1. Define compiler. 2. Differentiate compiler and interpreter. 3. What is a language processing system? 4. List four software tools
More informationAbout the Authors... iii Introduction... xvii. Chapter 1: System Software... 1
Table of Contents About the Authors... iii Introduction... xvii Chapter 1: System Software... 1 1.1 Concept of System Software... 2 Types of Software Programs... 2 Software Programs and the Computing Machine...
More informationQuestion Bank. 10CS63:Compiler Design
Question Bank 10CS63:Compiler Design 1.Determine whether the following regular expressions define the same language? (ab)* and a*b* 2.List the properties of an operator grammar 3. Is macro processing a
More informationCS 2210 Sample Midterm. 1. Determine if each of the following claims is true (T) or false (F).
CS 2210 Sample Midterm 1. Determine if each of the following claims is true (T) or false (F). F A language consists of a set of strings, its grammar structure, and a set of operations. (Note: a language
More informationCST-402(T): Language Processors
CST-402(T): Language Processors Course Outcomes: On successful completion of the course, students will be able to: 1. Exhibit role of various phases of compilation, with understanding of types of grammars
More informationUNIT-III BOTTOM-UP PARSING
UNIT-III BOTTOM-UP PARSING Constructing a parse tree for an input string beginning at the leaves and going towards the root is called bottom-up parsing. A general type of bottom-up parser is a shift-reduce
More informationAbout the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Compiler Design
i About the Tutorial A compiler translates the codes written in one language to some other language without changing the meaning of the program. It is also expected that a compiler should make the target
More informationUsing an LALR(1) Parser Generator
Using an LALR(1) Parser Generator Yacc is an LALR(1) parser generator Developed by S.C. Johnson and others at AT&T Bell Labs Yacc is an acronym for Yet another compiler compiler Yacc generates an integrated
More informationBIRLA INSTITUTE OF TECHNOLOGY AND SCIENCE, Pilani Pilani Campus Instruction Division
SECOND SEMESTER 2015-2016 Course Handout (Part II) Date:23-01-2017 In addition to part I (General Handout for all courses appended to the time table) this portion gives further specific details regarding
More informationData Mining Laboratory Manual
Data Mining Laboratory Manual Department of Information Technology MLR INSTITUTE OF TECHNOLOGY Marri Laxman Reddy Avenue, Dundigal, Gandimaisamma (M), R.R. Dist. Data Mining Laboratory Manual Prepared
More informationLexical and Syntax Analysis. Bottom-Up Parsing
Lexical and Syntax Analysis Bottom-Up Parsing Parsing There are two ways to construct derivation of a grammar. Top-Down: begin with start symbol; repeatedly replace an instance of a production s LHS with
More informationMidTerm Papers Solved MCQS with Reference (1 to 22 lectures)
CS606- Compiler Construction MidTerm Papers Solved MCQS with Reference (1 to 22 lectures) by Arslan Arshad (Zain) FEB 21,2016 0300-2462284 http://lmshelp.blogspot.com/ Arslan.arshad01@gmail.com AKMP01
More informationLexical Analysis. Introduction
Lexical Analysis Introduction Copyright 2015, Pedro C. Diniz, all rights reserved. Students enrolled in the Compilers class at the University of Southern California have explicit permission to make copies
More informationUNIT III & IV. Bottom up parsing
UNIT III & IV Bottom up parsing 5.0 Introduction Given a grammar and a sentence belonging to that grammar, if we have to show that the given sentence belongs to the given grammar, there are two methods.
More informationGUJARAT TECHNOLOGICAL UNIVERSITY
Type of course: Core GUJARAT TECHNOLOGICAL UNIVERSITY SUBJECT NAME: Compiler Design SUBJECT CODE: 21701 B.E. 7 th SEMESTER Prerequisite: Data Structures and Algorithms, Theory of Computation, Rationale:
More informationVIVA QUESTIONS WITH ANSWERS
VIVA QUESTIONS WITH ANSWERS 1. What is a compiler? A compiler is a program that reads a program written in one language the source language and translates it into an equivalent program in another language-the
More informationSyntax Analysis. Amitabha Sanyal. (www.cse.iitb.ac.in/ as) Department of Computer Science and Engineering, Indian Institute of Technology, Bombay
Syntax Analysis (www.cse.iitb.ac.in/ as) Department of Computer Science and Engineering, Indian Institute of Technology, Bombay September 2007 College of Engineering, Pune Syntax Analysis: 2/124 Syntax
More information4. Lexical and Syntax Analysis
4. Lexical and Syntax Analysis 4.1 Introduction Language implementation systems must analyze source code, regardless of the specific implementation approach Nearly all syntax analysis is based on a formal
More informationFaculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology
Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology exam Compiler Construction in4303 April 9, 2010 14.00-15.30 This exam (6 pages) consists of 52 True/False
More informationflex is not a bad tool to use for doing modest text transformations and for programs that collect statistics on input.
flex is not a bad tool to use for doing modest text transformations and for programs that collect statistics on input. More often than not, though, you ll want to use flex to generate a scanner that divides
More informationCOMPILER CONSTRUCTION Seminar 02 TDDB44
COMPILER CONSTRUCTION Seminar 02 TDDB44 Martin Sjölund (martin.sjolund@liu.se) Adrian Horga (adrian.horga@liu.se) Department of Computer and Information Science Linköping University LABS Lab 3 LR parsing
More information4. Lexical and Syntax Analysis
4. Lexical and Syntax Analysis 4.1 Introduction Language implementation systems must analyze source code, regardless of the specific implementation approach Nearly all syntax analysis is based on a formal
More informationPART 3 - SYNTAX ANALYSIS. F. Wotawa TU Graz) Compiler Construction Summer term / 309
PART 3 - SYNTAX ANALYSIS F. Wotawa (IST @ TU Graz) Compiler Construction Summer term 2016 64 / 309 Goals Definition of the syntax of a programming language using context free grammars Methods for parsing
More informationFormal Languages and Compilers Lecture VII Part 4: Syntactic A
Formal Languages and Compilers Lecture VII Part 4: Syntactic Analysis Free University of Bozen-Bolzano Faculty of Computer Science POS Building, Room: 2.03 artale@inf.unibz.it http://www.inf.unibz.it/
More informationMIT Parse Table Construction. Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology
MIT 6.035 Parse Table Construction Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology Parse Tables (Review) ACTION Goto State ( ) $ X s0 shift to s2 error error goto s1
More informationVALLIAMMAI ENGINEERING COLLEGE
VALLIAMMAI ENGINEERING COLLEGE SRM Nagar, Kattankulathur 60 20 DEPARTMENT OF INFORMATION TECHNOLOGY QUESTION BANK VI SEMESTER CS6660 COMPILER DESIGN Regulation 20 Academic Year 207 8 Prepared by Ms. S.
More informationCSCI312 Principles of Programming Languages!
CSCI312 Principles of Programming Languages!! Chapter 3 Regular Expression and Lexer Xu Liu Recap! Copyright 2006 The McGraw-Hill Companies, Inc. Clite: Lexical Syntax! Input: a stream of characters from
More informationA programming language requires two major definitions A simple one pass compiler
A programming language requires two major definitions A simple one pass compiler [Syntax: what the language looks like A context-free grammar written in BNF (Backus-Naur Form) usually suffices. [Semantics:
More informationG.PULLAIH COLLEGE OF ENGINEERING & TECHNOLOGY
G.PULLAI COLLEGE OF ENGINEERING & TECNOLOGY Nandikotkur Road, Kurnool 518002 DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING Semester VI (2017-2018) COURSE DESCRIPTION Course Code : 15A05601 Course Title
More informationDEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Subject Name: CS2352 Principles of Compiler Design Year/Sem : III/VI
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Subject Name: CS2352 Principles of Compiler Design Year/Sem : III/VI UNIT I - LEXICAL ANALYSIS 1. What is the role of Lexical Analyzer? [NOV 2014] 2. Write
More information2068 (I) Attempt all questions.
2068 (I) 1. What do you mean by compiler? How source program analyzed? Explain in brief. 2. Discuss the role of symbol table in compiler design. 3. Convert the regular expression 0 + (1 + 0)* 00 first
More information1. (a) What are the closure properties of Regular sets? Explain. (b) Briefly explain the logical phases of a compiler model. [8+8]
Code No: R05311201 Set No. 1 1. (a) What are the closure properties of Regular sets? Explain. (b) Briefly explain the logical phases of a compiler model. [8+8] 2. Compute the FIRST and FOLLOW sets of each
More informationGeneral Overview of Compiler
General Overview of Compiler Compiler: - It is a complex program by which we convert any high level programming language (source code) into machine readable code. Interpreter: - It performs the same task
More informationLR Parsing. Leftmost and Rightmost Derivations. Compiler Design CSE 504. Derivations for id + id: T id = id+id. 1 Shift-Reduce Parsing.
LR Parsing Compiler Design CSE 504 1 Shift-Reduce Parsing 2 LR Parsers 3 SLR and LR(1) Parsers Last modifled: Fri Mar 06 2015 at 13:50:06 EST Version: 1.7 16:58:46 2016/01/29 Compiled at 12:57 on 2016/02/26
More informationCompiler Design. Computer Science & Information Technology (CS) Rank under AIR 100
GATE- 2016-17 Postal Correspondence 1 Compiler Design Computer Science & Information Technology (CS) 20 Rank under AIR 100 Postal Correspondence Examination Oriented Theory, Practice Set Key concepts,
More informationSYNTAX ANALYSIS 1. Define parser. Hierarchical analysis is one in which the tokens are grouped hierarchically into nested collections with collective meaning. Also termed as Parsing. 2. Mention the basic
More informationProgramming Language Syntax and Analysis
Programming Language Syntax and Analysis 2017 Kwangman Ko (http://compiler.sangji.ac.kr, kkman@sangji.ac.kr) Dept. of Computer Engineering, Sangji University Introduction Syntax the form or structure of
More informationThe analysis part breaks up the source program into constituent pieces and creates an intermediate representation of the source program.
COMPILER DESIGN 1. What is a compiler? A compiler is a program that reads a program written in one language the source language and translates it into an equivalent program in another language-the target
More informationLR Parsing Techniques
LR Parsing Techniques Introduction Bottom-Up Parsing LR Parsing as Handle Pruning Shift-Reduce Parser LR(k) Parsing Model Parsing Table Construction: SLR, LR, LALR 1 Bottom-UP Parsing A bottom-up parser
More informationCS606- compiler instruction Solved MCQS From Midterm Papers
CS606- compiler instruction Solved MCQS From Midterm Papers March 06,2014 MC100401285 Moaaz.pk@gmail.com Mc100401285@gmail.com PSMD01 Final Term MCQ s and Quizzes CS606- compiler instruction If X is a
More informationMODULE 14 SLR PARSER LR(0) ITEMS
MODULE 14 SLR PARSER LR(0) ITEMS In this module we shall discuss one of the LR type parser namely SLR parser. The various steps involved in the SLR parser will be discussed with a focus on the construction
More informationSimple LR (SLR) LR(0) Drawbacks LR(1) SLR Parse. LR(1) Start State and Reduce. LR(1) Items 10/3/2012
LR(0) Drawbacks Consider the unambiguous augmented grammar: 0.) S E $ 1.) E T + E 2.) E T 3.) T x If we build the LR(0) DFA table, we find that there is a shift-reduce conflict. This arises because the
More informationBottom-up parsing. Bottom-Up Parsing. Recall. Goal: For a grammar G, withstartsymbols, any string α such that S α is called a sentential form
Bottom-up parsing Bottom-up parsing Recall Goal: For a grammar G, withstartsymbols, any string α such that S α is called a sentential form If α V t,thenα is called a sentence in L(G) Otherwise it is just
More informationLanguages and Compilers
Principles of Software Engineering and Operational Systems Languages and Compilers SDAGE: Level I 2012-13 4. Lexical Analysis (Scanning) Dr Valery Adzhiev vadzhiev@bournemouth.ac.uk Office: TA-121 For
More informationPreparing for the ACW Languages & Compilers
Preparing for the ACW 08348 Languages & Compilers Introductory Lab There is an Introductory Lab Just involves copying the lab task See separate Lab slides Language Roadmaps Convenient way of showing syntax
More informationLECTURE 11. Semantic Analysis and Yacc
LECTURE 11 Semantic Analysis and Yacc REVIEW OF LAST LECTURE In the last lecture, we introduced the basic idea behind semantic analysis. Instead of merely specifying valid structures with a context-free
More informationCSE 130 Programming Language Principles & Paradigms Lecture # 5. Chapter 4 Lexical and Syntax Analysis
Chapter 4 Lexical and Syntax Analysis Introduction - Language implementation systems must analyze source code, regardless of the specific implementation approach - Nearly all syntax analysis is based on
More informationCSE302: Compiler Design
CSE302: Compiler Design Instructor: Dr. Liang Cheng Department of Computer Science and Engineering P.C. Rossin College of Engineering & Applied Science Lehigh University March 27, 2007 Outline Recap General/Canonical
More informationStructure of a compiler. More detailed overview of compiler front end. Today we ll take a quick look at typical parts of a compiler.
More detailed overview of compiler front end Structure of a compiler Today we ll take a quick look at typical parts of a compiler. This is to give a feeling for the overall structure. source program lexical
More informationCompiler Lab. Introduction to tools Lex and Yacc
Compiler Lab Introduction to tools Lex and Yacc Assignment1 Implement a simple calculator with tokens recognized using Lex/Flex and parsing and semantic actions done using Yacc/Bison. Calculator Input:
More informationSyntax-Directed Translation
Syntax-Directed Translation ALSU Textbook Chapter 5.1 5.4, 4.8, 4.9 Tsan-sheng Hsu tshsu@iis.sinica.edu.tw http://www.iis.sinica.edu.tw/~tshsu 1 What is syntax-directed translation? Definition: The compilation
More informationAs we have seen, token attribute values are supplied via yylval, as in. More on Yacc s value stack
More on Yacc s value stack As we noted last time, Yacc uses a second stack to store the attribute values of the tokens and terminals in the parse stack. For a token, the attributes are computed by the
More informationCS 4120 Introduction to Compilers
CS 4120 Introduction to Compilers Andrew Myers Cornell University Lecture 6: Bottom-Up Parsing 9/9/09 Bottom-up parsing A more powerful parsing technology LR grammars -- more expressive than LL can handle
More informationTDDD55 - Compilers and Interpreters Lesson 3
TDDD55 - Compilers and Interpreters Lesson 3 November 22 2011 Kristian Stavåker (kristian.stavaker@liu.se) Department of Computer and Information Science Linköping University LESSON SCHEDULE November 1,
More informationTwo hours UNIVERSITY OF MANCHESTER SCHOOL OF COMPUTER SCIENCE. Date: Friday 20th May 2016 Time: 14:00-16:00
Two hours UNIVERSITY OF MANCHESTER SCHOOL OF COMPUTER SCIENCE Compilers Date: Friday 20th May 2016 Time: 14:00-16:00 Please answer any THREE Questions from the FIVE Questions provided This is a CLOSED
More information1. Lexical Analysis Phase
1. Lexical Analysis Phase The purpose of the lexical analyzer is to read the source program, one character at time, and to translate it into a sequence of primitive units called tokens. Keywords, identifiers,
More informationLexical and Parser Tools
Lexical and Parser Tools CSE 413, Autumn 2005 Programming Languages http://www.cs.washington.edu/education/courses/413/05au/ 7-Dec-2005 cse413-20-tools 2005 University of Washington 1 References» The Lex
More informationDEPARTMENT OF INFORMATION TECHNOLOGY / COMPUTER SCIENCE AND ENGINEERING UNIT -1-INTRODUCTION TO COMPILERS 2 MARK QUESTIONS
BHARATHIDASAN ENGINEERING COLLEGE DEPARTMENT OF INFORMATION TECHNOLOGY / COMPUTER SCIENCE AND ENGINEERING Year & Semester : III & VI Degree & Branch : B.E (CSE) /B.Tech (Information Technology) Subject
More informationRYERSON POLYTECHNIC UNIVERSITY DEPARTMENT OF MATH, PHYSICS, AND COMPUTER SCIENCE CPS 710 FINAL EXAM FALL 96 INSTRUCTIONS
RYERSON POLYTECHNIC UNIVERSITY DEPARTMENT OF MATH, PHYSICS, AND COMPUTER SCIENCE CPS 710 FINAL EXAM FALL 96 STUDENT ID: INSTRUCTIONS Please write your student ID on this page. Do not write it or your name
More informationChapter 4. Lexical and Syntax Analysis
Chapter 4 Lexical and Syntax Analysis Chapter 4 Topics Introduction Lexical Analysis The Parsing Problem Recursive-Descent Parsing Bottom-Up Parsing Copyright 2012 Addison-Wesley. All rights reserved.
More informationCompiler phases. Non-tokens
Compiler phases Compiler Construction Scanning Lexical Analysis source code scanner tokens regular expressions lexical analysis Lennart Andersson parser context free grammar Revision 2011 01 21 parse tree
More informationINSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad
INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad - 500 043 INFORMATIONTECHOGY TUTORIAL QUESTION BANK ACADEMIC YEAR - 2018-19 Course Title Mobile Application Development Course Code
More informationVALLIAMMAI ENGNIEERING COLLEGE SRM Nagar, Kattankulathur
VALLIAMMAI ENGNIEERING COLLEGE SRM Nagar, Kattankulathur 603203. DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING Year & Semester : III & VI Section : CSE 1 & 2 Subject Code : CS6660 Subject Name : COMPILER
More informationCompiler Design Aug 1996
Aug 1996 Part A 1 a) What are the different phases of a compiler? Explain briefly with the help of a neat diagram. b) For the following Pascal keywords write the state diagram and also write program segments
More informationPrinciples of Programming Languages
Principles of Programming Languages h"p://www.di.unipi.it/~andrea/dida2ca/plp- 14/ Prof. Andrea Corradini Department of Computer Science, Pisa Lesson 8! Bo;om- Up Parsing Shi?- Reduce LR(0) automata and
More informationBottom-Up Parsing. Lecture 11-12
Bottom-Up Parsing Lecture 11-12 (From slides by G. Necula & R. Bodik) 2/20/08 Prof. Hilfinger CS164 Lecture 11 1 Administrivia Test I during class on 10 March. 2/20/08 Prof. Hilfinger CS164 Lecture 11
More informationGujarat Technological University Sankalchand Patel College of Engineering, Visnagar B.E. Semester VII (CE) July-Nov Compiler Design (170701)
Gujarat Technological University Sankalchand Patel College of Engineering, Visnagar B.E. Semester VII (CE) July-Nov 2014 Compiler Design (170701) Question Bank / Assignment Unit 1: INTRODUCTION TO COMPILING
More informationLR Parsers. Aditi Raste, CCOEW
LR Parsers Aditi Raste, CCOEW 1 LR Parsers Most powerful shift-reduce parsers and yet efficient. LR(k) parsing L : left to right scanning of input R : constructing rightmost derivation in reverse k : number
More informationSRM UNIVERSITY FACULTY OF ENGINEERING AND TECHNOLOGY SCHOOL OF COMPUTING DEPARTMENT OF CSE COURSE PLAN
Course Code : CS0301 Course Title : Compiler Design Semester : V Course Time : July Dec 2011 DAY SRM UNIVERSITY FACULTY OF ENGINEERING AND TECHNOLOGY SCHOOL OF COMPUTING DEPARTMENT OF CSE COURSE PLAN SECTION
More informationLet us construct the LR(1) items for the grammar given below to construct the LALR parsing table.
MODULE 18 LALR parsing After understanding the most powerful CALR parser, in this module we will learn to construct the LALR parser. The CALR parser has a large set of items and hence the LALR parser is
More informationWednesday, September 9, 15. Parsers
Parsers What is a parser A parser has two jobs: 1) Determine whether a string (program) is valid (think: grammatically correct) 2) Determine the structure of a program (think: diagramming a sentence) Agenda
More informationCOMPILER DESIGN. For COMPUTER SCIENCE
COMPILER DESIGN For COMPUTER SCIENCE . COMPILER DESIGN SYLLABUS Lexical analysis, parsing, syntax-directed translation. Runtime environments. Intermediate code generation. ANALYSIS OF GATE PAPERS Exam
More informationParsers. What is a parser. Languages. Agenda. Terminology. Languages. A parser has two jobs:
What is a parser Parsers A parser has two jobs: 1) Determine whether a string (program) is valid (think: grammatically correct) 2) Determine the structure of a program (think: diagramming a sentence) Agenda
More informationPrinciple of Compilers Lecture IV Part 4: Syntactic Analysis. Alessandro Artale
Free University of Bolzano Principles of Compilers Lecture IV Part 4, 2003/2004 AArtale (1) Principle of Compilers Lecture IV Part 4: Syntactic Analysis Alessandro Artale Faculty of Computer Science Free
More informationLexical and Syntax Analysis. Top-Down Parsing
Lexical and Syntax Analysis Top-Down Parsing Easy for humans to write and understand String of characters Lexemes identified String of tokens Easy for programs to transform Data structure Syntax A syntax
More informationLR Parsing - The Items
LR Parsing - The Items Lecture 10 Sections 4.5, 4.7 Robb T. Koether Hampden-Sydney College Fri, Feb 13, 2015 Robb T. Koether (Hampden-Sydney College) LR Parsing - The Items Fri, Feb 13, 2015 1 / 31 1 LR
More informationMonday, September 13, Parsers
Parsers Agenda Terminology LL(1) Parsers Overview of LR Parsing Terminology Grammar G = (Vt, Vn, S, P) Vt is the set of terminals Vn is the set of non-terminals S is the start symbol P is the set of productions
More information3. Syntax Analysis. Andrea Polini. Formal Languages and Compilers Master in Computer Science University of Camerino
3. Syntax Analysis Andrea Polini Formal Languages and Compilers Master in Computer Science University of Camerino (Formal Languages and Compilers) 3. Syntax Analysis CS@UNICAM 1 / 54 Syntax Analysis: the
More informationLECTURE NOTES ON COMPILER DESIGN P a g e 2
LECTURE NOTES ON COMPILER DESIGN P a g e 1 (PCCS4305) COMPILER DESIGN KISHORE KUMAR SAHU SR. LECTURER, DEPARTMENT OF INFORMATION TECHNOLOGY ROLAND INSTITUTE OF TECHNOLOGY, BERHAMPUR LECTURE NOTES ON COMPILER
More informationMIDTERM EXAM (Solutions)
MIDTERM EXAM (Solutions) Total Score: 100, Max. Score: 83, Min. Score: 26, Avg. Score: 57.3 1. (10 pts.) List all major categories of programming languages, outline their definitive characteristics and
More informationExamples of attributes: values of evaluated subtrees, type information, source file coordinates,
1 2 3 Attributes can be added to the grammar symbols, and program fragments can be added as semantic actions to the grammar, to form a syntax-directed translation scheme. Some attributes may be set by
More informationSyn S t yn a t x a Ana x lysi y s si 1
Syntax Analysis 1 Position of a Parser in the Compiler Model Source Program Lexical Analyzer Token, tokenval Get next token Parser and rest of front-end Intermediate representation Lexical error Syntax
More informationChapter 2 - Programming Language Syntax. September 20, 2017
Chapter 2 - Programming Language Syntax September 20, 2017 Specifying Syntax: Regular expressions and context-free grammars Regular expressions are formed by the use of three mechanisms Concatenation Alternation
More informationLecture 8: Deterministic Bottom-Up Parsing
Lecture 8: Deterministic Bottom-Up Parsing (From slides by G. Necula & R. Bodik) Last modified: Fri Feb 12 13:02:57 2010 CS164: Lecture #8 1 Avoiding nondeterministic choice: LR We ve been looking at general
More informationProf. Mohamed Hamada Software Engineering Lab. The University of Aizu Japan
Compilers Prof. Mohamed Hamada Software Engineering Lab. The University of Aizu Japan Lexical Analyzer (Scanner) 1. Uses Regular Expressions to define tokens 2. Uses Finite Automata to recognize tokens
More informationKALASALINGAM UNIVERSITY ANAND NAGAR, KRISHNAN KOIL DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING ODD SEMESTER COURSE PLAN
Subject with Code KALASALINGAM UNIVERSITY ANAND NAGAR, KRISHNAN KOIL 626 126 DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING ODD SEMESTER 2013-2014 Semester/Branch/Section Credits : 3 COURSE PLAN : Compiler
More informationLR Parsing LALR Parser Generators
LR Parsing LALR Parser Generators Outline Review of bottom-up parsing Computing the parsing DFA Using parser generators 2 Bottom-up Parsing (Review) A bottom-up parser rewrites the input string to the
More informationBottom Up Parsing. Shift and Reduce. Sentential Form. Handle. Parse Tree. Bottom Up Parsing 9/26/2012. Also known as Shift-Reduce parsing
Also known as Shift-Reduce parsing More powerful than top down Don t need left factored grammars Can handle left recursion Attempt to construct parse tree from an input string eginning at leaves and working
More informationfor (i=1; i<=100000; i++) { x = sqrt (y); // square root function cout << x+i << endl; }
Ex: The difference between Compiler and Interpreter The interpreter actually carries out the computations specified in the source program. In other words, the output of a compiler is a program, whereas
More informationLecture 7: Deterministic Bottom-Up Parsing
Lecture 7: Deterministic Bottom-Up Parsing (From slides by G. Necula & R. Bodik) Last modified: Tue Sep 20 12:50:42 2011 CS164: Lecture #7 1 Avoiding nondeterministic choice: LR We ve been looking at general
More information