MANIPAL INSTITUTE OF TECHNOLOGY (Constituent Institute of MANIPAL University) MANIPAL

Similar documents
CA Compiler Construction

Assignment 1 (Lexical Analyzer)

A simple syntax-directed

Projects for Compilers

Assignment 1 (Lexical Analyzer)

KALASALINGAM UNIVERSITY ANAND NAGAR, KRISHNAN KOIL DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING ODD SEMESTER COURSE PLAN

Introduction to Syntax Analysis. Compiler Design Syntax Analysis s.l. dr. ing. Ciprian-Bogdan Chirila

SRM UNIVERSITY FACULTY OF ENGINEERING AND TECHNOLOGY SCHOOL OF COMPUTING DEPARTMENT OF CSE COURSE PLAN

SRM UNIVERSITY FACULTY OF ENGINEERING AND TECHNOLOGY SCHOOL OF COMPUTER SCIENCE AND ENGINEERING COURSE PLAN

Formal Languages and Compilers Lecture I: Introduction to Compilers

Compiler Design Overview. Compiler Design 1

CPS 506 Comparative Programming Languages. Syntax Specification

GUJARAT TECHNOLOGICAL UNIVERSITY

SRM UNIVERSITY FACULTY OF ENGINEERING AND TECHNOLOGY

LECTURE NOTES ON COMPILER DESIGN P a g e 2

Lexical and Syntax Analysis

Compiler Construction Principles And Practice Solution Manual

Compiler Design. Computer Science & Information Technology (CS) Rank under AIR 100

Compilers for Modern Architectures Course Syllabus, Spring 2015

COMPILER CONSTRUCTION LAB 2 THE SYMBOL TABLE. Tutorial 2 LABS. PHASES OF A COMPILER Source Program. Lab 2 Symbol table

Compiler Design (40-414)

Application Specific Signal Processors S

10/4/18. Lexical and Syntactic Analysis. Lexical and Syntax Analysis. Tokenizing Source. Scanner. Reasons to Separate Lexical and Syntactic Analysis

Examples of attributes: values of evaluated subtrees, type information, source file coordinates,

2068 (I) Attempt all questions.

Figure 2.1: Role of Lexical Analyzer

CS Compiler Construction West Virginia fall semester 2014 August 18, 2014 syllabus 1.0

Modern Compiler Design: An approach to make Compiler Design a Significant Study for Students

C: How to Program. Week /Mar/05

Parsing and Pattern Recognition

CS 4201 Compilers 2014/2015 Handout: Lab 1

Chapter 2, Part III Arithmetic Operators and Decision Making

Evaluation Scheme L T P Total Credit Theory Mid Sem Exam

CS /534 Compiler Construction University of Massachusetts Lowell. NOTHING: A Language for Practice Implementation

Lexical analysis. Syntactical analysis. Semantical analysis. Intermediate code generation. Optimization. Code generation. Target specific optimization

DOID: A Lexical Analyzer for Understanding Mid-Level Compilation Processes

CSE 3302 Programming Languages Lecture 2: Syntax

Chapter 4: Syntax Analyzer

UNIT -2 LEXICAL ANALYSIS

10/5/17. Lexical and Syntactic Analysis. Lexical and Syntax Analysis. Tokenizing Source. Scanner. Reasons to Separate Lexical and Syntax Analysis

Formal Languages and Compilers Lecture VI: Lexical Analysis

DEPARTMENT OF INFORMATION TECHNOLOGY AUTOMATA AND COMPILER DESIGN. B.Tech-IT, III Year -I Sem

BIRLA INSTITUTE OF TECHNOLOGY AND SCIENCE, Pilani Pilani Campus Instruction Division

A Simple Syntax-Directed Translator

MIT Specifying Languages with Regular Expressions and Context-Free Grammars. Martin Rinard Massachusetts Institute of Technology

MIT Specifying Languages with Regular Expressions and Context-Free Grammars

Using an LALR(1) Parser Generator

MATVEC: MATRIX-VECTOR COMPUTATION LANGUAGE REFERENCE MANUAL. John C. Murphy jcm2105 Programming Languages and Translators Professor Stephen Edwards

Chapter 3: Lexical Analysis

COP 3402 Systems Software Top Down Parsing (Recursive Descent)

CS 403: Scanning and Parsing

KU Compilerbau - Programming Assignment

Lexical Analysis (ASU Ch 3, Fig 3.1)

Prof. Mohamed Hamada Software Engineering Lab. The University of Aizu Japan

COP4020 Programming Assignment 1 CALC Interpreter/Translator Due March 4, 2015

COMP 3002: Compiler Construction. Pat Morin School of Computer Science

1. Explain the input buffer scheme for scanning the source program. How the use of sentinels can improve its performance? Describe in detail.

CST-402(T): Language Processors

LECTURE 3. Compiler Phases

THE COMPILATION PROCESS EXAMPLE OF TOKENS AND ATTRIBUTES

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Computer Science and Engineering

CS321 Languages and Compiler Design I. Winter 2012 Lecture 4

CIT 3136 Lecture 7. Top-Down Parsing

CSCI312 Principles of Programming Languages!

Lexical Analysis. Introduction

Lexical Analysis. Dragon Book Chapter 3 Formal Languages Regular Expressions Finite Automata Theory Lexical Analysis using Automata

G.PULLAIH COLLEGE OF ENGINEERING & TECHNOLOGY

Error Recovery during Top-Down Parsing: Acceptable-sets derived from continuation

INSTITUTE OF AERONAUTICAL ENGINEERING (AUTONOMOUS)

Building lexical and syntactic analyzers. Chapter 3. Syntactic sugar causes cancer of the semicolon. A. Perlis. Chomsky Hierarchy

Time : 1 Hour Max Marks : 30

CS131: Programming Languages and Compilers. Spring 2017

Quick Parser Development Using Modified Compilers and Generated Syntax Rules

ECE251 Midterm practice questions, Fall 2010

3. Context-free grammars & parsing

PRINCIPLES OF COMPILER DESIGN UNIT II LEXICAL ANALYSIS 2.1 Lexical Analysis - The Role of the Lexical Analyzer

Automatic Scanning and Parsing using LEX and YACC

ST. XAVIER S COLLEGE

Chapter 3: Describing Syntax and Semantics. Introduction Formal methods of describing syntax (BNF)

It parses an input string of tokens by tracing out the steps in a leftmost derivation.

LEXIMET: A Lexical Analyzer Generator including McCabe's Metrics.

CS6660 COMPILER DESIGN L T P C

LANGUAGE PROCESSORS. Introduction to Language processor:

Syntax/semantics. Program <> program execution Compiler/interpreter Syntax Grammars Syntax diagrams Automata/State Machines Scanning/Parsing

Parsing #1. Leonidas Fegaras. CSE 5317/4305 L3: Parsing #1 1

Compiler Design. Dr. Chengwei Lei CEECS California State University, Bakersfield

Translator Design CRN Course Administration CMSC 4173 Spring 2018

COMP 181 Compilers. Administrative. Last time. Prelude. Compilation strategy. Translation strategy. Lecture 2 Overview

Philadelphia University Faculty of Information Technology Department of Computer Science --- Semester, 2007/2008. Course Syllabus

An Implementation of Object-Oriented Program Transformation for. Thought-Guided Debugging

QUESTIONS RELATED TO UNIT I, II And III

University of Utrecht. 1992; Fokker, 1995), the use of monads to structure functional programs (Wadler,

Sometimes an ambiguous grammar can be rewritten to eliminate the ambiguity.

CSE302: Compiler Design

Translator Design CRN Course Administration CMSC 4173 Spring 2017

GUJARAT TECHNOLOGICAL UNIVERSITY

COP4020 Programming Languages. Syntax Prof. Robert van Engelen

Syntax. A. Bellaachia Page: 1

Compiler Techniques MN1 The nano-c Language

LECTURE 11. Semantic Analysis and Yacc

Transcription:

MANIPAL INSTITUTE OF TECHNOLOGY (Constituent Institute of MANIPAL University) MANIPAL-576104 CSE 312 LANGUAGE PROCESSORS LAB MANUAL VI Sem, BE (CS&E) 2015 Prepared By Approved By 1. Dr. Ashalatha Nayak 2. Ms. Deepthi. S. (H.O.D) 3. Mr. Shyam Karanth 4. Ms. Ancilla Pinto DEPT OF COMPTER SCIENCE & ENGG. M. I. T., MANIPAL

Week-wise Schedule Week 1 : Preliminary Scanning Applications Week 2 : Identification of Tokens in a given Program Week 3, 4, 5 : Design of Lexical Analyzer Week 6, 7, 8, 9, 10 : Design of Parser Week 11 : Design of Code Generator Week 12 : Usage of Lex Week 13 & 14 : Final Test PROCEDURE OF EVALUATION Student will be evaluated based on following criteria: Scanning : 5 Marks Tokenizing : 5 Marks Lexical analyzer : 15 Marks Parser : 20 Marks Code generation : 5 Marks LEX : 10 Marks Test : 40 Marks (15 write up+ 25 Execution.) Total 100 Marks

WEEK 1: Preliminary Scanning applications 1) Programs on file operations. 2) Write a program, which will read a program written in C, recognize all of the keywords in that program and print them in upper case letters. WEEK 2: Identification of Tokens in a given Program 1) Write a program which will take as input a C program consisting of single and multi-line comments and multiple blank spaces and produces as output the C program without comments and single blank space. // This is a single line comment /* *****This is a ****** Multiline Comment *****/ 2) Write a program, which will read a program written in C, recognize all of the lexemes (int, float, char, for, while etc., ids, +, _, /,*,(,), numbers, <,>, <>,<=,>=,!=,== ), tokens (keywords, identifiers, operators, special symbols, relational operators) and display them in a separate file. 3) Repeat Qn. (2) by storing tokens in each of the following data structures: a. Arrays b. Singly/doubly Linked lists c. Hash tables WEEK 3 10: Design of Mini Compiler for C Language for the given subset Data Types : int, char Arrays : 1-dimensional Expressions : Arithmetic and Relational Looping statements : for, while Decision statements : if, if else Note: The following grammar for C language is to be adopted with necessary corrections Program - main () { declarations statement-list } declarations data-type identifier-list; declarations data-type int char identifier-list id id, identifier-list id[number], identifier-list id[number] statement_list statement ; statement_list statement assign-stat decision_stat looping-stat

assign_stat id = expn expn simple-expn eprime eprime relop simple-expn simple-exp term seprime seprime addop term seprime term factor tprime tprime mulop factor tprime factor id num decision-stat if ( expn ) stat dprime dprime else stat looping-stat while (expn) stat for (assign_stat ; expn ; assign_stat ) stat relop = =!= <= >= > < addop + mulop * / % To construct an Lexical Analyzer. WEEK 3, 4 & 5: Design of Lexical analyzer Identifying different classes of tokens like: keywords, identifiers and special symbols. Selecting a suitable data structure for symbol table (the alternates are linked list, hashing, array of structures, binary search tree) Having selected a data structure, identifying the appropriate fields. To test the Lexical Analyzer: Input: C Program Output: Tokens and their Class Interface: The Lexical Analyzer should tokenize a given source program and return the next token and it s class whenever the parser requests.

WEEK 6-10: Design of a Recursive Descent Parser To code and test parser: Remove left recursion from each of the productions so that the underlying grammar can be parsed with a parser. The parser obtains a string of tokens from the lexical analyzer and verifies that the string can be generated by the grammar for the C language. The parser should report syntax errors if any (for eg.: Misspelling an identifier or keyword, Undeclared or Multiply declared identifier, Arithmetic or Relational Expressions with unbalanced parentheses and Expression syntax error etc.) with appropriate line-no. 1. E num T T *num T ϵ Simple grammars 2. S a ( T ) T T, S S 3. E E+T T T T*F F F ( E ) id 4. S aacbe A Ab b B d 5. lexp aterm list aterm number identifier list (lexp_seq) lexp_seq lexp_seq lexp lexp 6. Build a RD parser for the above C grammar. WEEK 11: Design of Code generator WEEK 12: Usage of LEX 1. Write a LEX program to count the number of lines, words, blank spaces and characters in a given input. 2. Write a LEX program to find the number of vowels, consonants in the given input. 3. Write a LEX program to check if a given number is positive or negative. 4. Write a LEX program to check if a given statement is simple or compound. 5. Write a LEX program to count the type of numbers. 6. Write a LEX program to check the validity of a given arithmetic statement. 7. Write a lex program to count the number of printf and scanf statements in a valid c program and replace them with write and read statements respectively.

8. Write a lex program to count the number of characters, words, blanks and lines in a given string. WEEK 13 and 14: Test REFERENCES 1. Alfred V. Aho, Monica S. Lam, Ravi Sethi, Jeffrey D. Ullman, Compilers Principles, Techniques and Tools, Pearson Education, 2 nd edition. 2010 2. D M Dhamdhere, Systems Programming and Operating Systems, Tata McGraw Hill, 2 nd Revised Edition, 2001. 3. Kenneth C. Louden, Compiler Construction - Principles and Practice, Thomson, India Edition, 2007. ***************************