CS 441G Fall 2018 Exam 1 Matching: LETTER

Similar documents
KEY. A 1. The action of a grammar when a derivation can be found for a sentence. Y 2. program written in a High Level Language

Structure of a Compiler: Scanner reads a source, character by character, extracting lexemes that are then represented by tokens.

Interpreter. Scanner. Parser. Tree Walker. read. request token. send token. send AST I/O. Console

CS Lecture 2. The Front End. Lecture 2 Lexical Analysis

CS 314 Principles of Programming Languages. Lecture 3

CSCI312 Principles of Programming Languages!

Announcements! P1 part 1 due next Tuesday P1 part 2 due next Friday

CS 314 Principles of Programming Languages

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

Theory and Compiling COMP360

MIT Specifying Languages with Regular Expressions and Context-Free Grammars

Lexical Analysis. Introduction

Introduction to Lexing and Parsing

Program Analysis ( 软件源代码分析技术 ) ZHENG LI ( 李征 )

Formal Grammars and Abstract Machines. Sahar Al Seesi

Homework & Announcements

Theory of Programming Languages COMP360

CSCE 314 Programming Languages

Formal Languages. Formal Languages

CPS 506 Comparative Programming Languages. Syntax Specification

CD Assignment I. 1. Explain the various phases of the compiler with a simple example.

CS 321 IV. Overview of Compilation

Theory of Computations Spring 2016 Practice Final Exam Solutions

Compiling Regular Expressions COMP360

Part 5 Program Analysis Principles and Techniques

TAFL 1 (ECS-403) Unit- V. 5.1 Turing Machine. 5.2 TM as computer of Integer Function

2. Lexical Analysis! Prof. O. Nierstrasz!

Languages and Compilers

SYED AMMAL ENGINEERING COLLEGE (An ISO 9001:2008 Certified Institution) Dr. E.M. Abdullah Campus, Ramanathapuram

CS 4201 Compilers 2014/2015 Handout: Lab 1

CSE 3302 Programming Languages Lecture 2: Syntax

Outline. 1 Scanning Tokens. 2 Regular Expresssions. 3 Finite State Automata

Lexical Analyzer Scanner

Chapter 3. Describing Syntax and Semantics ISBN

Lexical and Syntax Analysis

COLLEGE OF ENGINEERING, NASHIK. LANGUAGE TRANSLATOR

Lexical Analysis 1 / 52

Introduction to Automata Theory. BİL405 - Automata Theory and Formal Languages 1

The Front End. The purpose of the front end is to deal with the input language. Perform a membership test: code source language?

Syntax Analysis Part I

Question Points Score

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

Concepts Introduced in Chapter 3. Lexical Analysis. Lexical Analysis Terms. Attributes for Tokens

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Compiler Design

for (i=1; i<=100000; i++) { x = sqrt (y); // square root function cout << x+i << endl; }

Formal languages and computation models

Formal Languages and Grammars. Chapter 2: Sections 2.1 and 2.2

CS 403: Scanning and Parsing

Syntax. In Text: Chapter 3

Chapter 4. Lexical and Syntax Analysis

Lexical Analyzer Scanner

COP 3402 Systems Software Syntax Analysis (Parser)

CS 403 Compiler Construction Lecture 3 Lexical Analysis [Based on Chapter 1, 2, 3 of Aho2]

A simple syntax-directed

CT32 COMPUTER NETWORKS DEC 2015

Chapter 3: CONTEXT-FREE GRAMMARS AND PARSING Part 1

Non-deterministic Finite Automata (NFA)

THE COMPILATION PROCESS EXAMPLE OF TOKENS AND ATTRIBUTES

Universal Turing Machine Chomsky Hierarchy Decidability Reducibility Uncomputable Functions Rice s Theorem Decidability Continued

Turing Machine Languages

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

1. The output of lexical analyser is a) A set of RE b) Syntax Tree c) Set of Tokens d) String Character

Lexical Analysis. COMP 524, Spring 2014 Bryan Ward

Derivations of a CFG. MACM 300 Formal Languages and Automata. Context-free Grammars. Derivations and parse trees

CS164: Midterm I. Fall 2003

CS415 Compilers. Lexical Analysis

LL(k) Parsing. Predictive Parsers. LL(k) Parser Structure. Sample Parse Table. LL(1) Parsing Algorithm. Push RHS in Reverse Order 10/17/2012

Lexical Scanning COMP360

Chapter 4. Lexical and Syntax Analysis. Topics. Compilation. Language Implementation. Issues in Lexical and Syntax Analysis.

CMSC 330: Organization of Programming Languages. Context Free Grammars

Question Bank. 10CS63:Compiler Design

Part 3. Syntax analysis. Syntax analysis 96

Lexical Analysis. Lexical analysis is the first phase of compilation: The file is converted from ASCII to tokens. It must be fast!

Programming Language Syntax and Analysis

CSE 130 Programming Language Principles & Paradigms Lecture # 5. Chapter 4 Lexical and Syntax Analysis

The Structure of a Syntax-Directed Compiler

Compilers and Interpreters

for (i=1; i<=100000; i++) { x = sqrt (y); // square root function cout << x+i << endl; }

CMPS Programming Languages. Dr. Chengwei Lei CEECS California State University, Bakersfield

1. Draw the state graphs for the finite automata which accept sets of strings composed of zeros and ones which:

Week 2: Syntax Specification, Grammars

Context Free Languages and Pushdown Automata

CSE450 Translation of Programming Languages. Lecture 4: Syntax Analysis

CS 536 Introduction to Programming Languages and Compilers Charles N. Fischer Lecture 2

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

COMPILER DESIGN LECTURE NOTES

Parsing. source code. while (k<=n) {sum = sum+k; k=k+1;}

2068 (I) Attempt all questions.

Multiple Choice Questions

UNIT -2 LEXICAL ANALYSIS

Formal Languages and Compilers Lecture VI: Lexical Analysis

R10 SET a) Construct a DFA that accepts an identifier of a C programming language. b) Differentiate between NFA and DFA?

Theoretical Part. Chapter one:- - What are the Phases of compiler? Answer:

LANGUAGE PROCESSORS. Presented By: Prof. S.J. Soni, SPCE Visnagar.

CS 315 Programming Languages Syntax. Parser. (Alternatively hand-built) (Alternatively hand-built)

Figure 2.1: Role of Lexical Analyzer

Dr. D.M. Akbar Hussain

11. a b c d e. 12. a b c d e. 13. a b c d e. 14. a b c d e. 15. a b c d e

LECTURE 3. Compiler Phases

Two hours UNIVERSITY OF MANCHESTER SCHOOL OF COMPUTER SCIENCE. Date: Friday 20th May 2016 Time: 14:00-16:00

Transcription:

CS 441G Fall 2018 Exam 1 Matching: match the best term from the following list to its definition by writing the LETTER of the term in the blank to the left of the definition. All 31 definitions are given on this practice exam. It will probably be reduced to 20 definitions but with all 31 terms to match on the actual exam. A Accepts L Lexeme W Rejects B Assembly M Lexical X Scanner C Code Generator N Linear Bounded Y Source D Compiler O Machine Code Z String Table E Constrainer P Non-Deterministic AA Symbol Table F Deterministic Q Non-Terminals AB Target G Finite State R Optimization AC Terminal H Goal (or Start) S Parser AD Token I Grammar T Phrase/Structure AE Turing Machine J High Level Language U Productions K Interpreter V Push Down D 1. software that translates a program written in a source file into a program stored in a target file, reporting errors when found. Y 2. program written in a High Level Language AB 3. program translated into a Low Level Language, usually Assembly, Machine Code or Virtual Machine Code. K 4. software that translates statements of a source (usually) one statement at a time into Machine Code, then executes the translated statement before translating/executing the next. O 5. binary representation simple commands - differs by CPU model knowledge of the CPU/HW required to program in this language. B 6. text representation simple commands (usually 1:1 with Machine Code) - differs by CPU model - knowledge of the CPU/HW required to program in this language. J 7. has more-complex commands translates 1:many Machine Code instructions same language across CPU models and Operating Systems (with some minor differences) in depth knowledge of the CPU/HW not required to program in these languages. X 8. reads a source, character by character, extracting lexemes that are then represented by tokens. S 9. extracts tokens from the Scanner and builds an Abstract Syntax Tree of the tokens, based on the rules of the language. E 10. adds context-sensitive and other information to the tokens of the AST produced by the Parser, producing a Decorated Abstract Syntax Tree. This DAST represents the full meaning (Semantics) of the source program being translated.

C 11. given the DAST produced by the Constrainer, writes code in the Target Language with the same meaning (semantics) as the source program. Z 12. stores the exact spelling of identifiers and literals discovered by the scanner. AA 13. stores semantic information on tokens. L 14. the string representation of a single word or symbol extracted from the source. AD 15. simplified (integer) representation of a Lexeme. It may be an object/structure containing members/fields describing a single word or symbol from the source. R 16. changes to the DAST and/or Target Code generated to make the Target program more efficient. I 17. defines the correct forms of sentences (programs) of a language. M 18. Grammar defines the correct forms for Lexemes in terms of characters. T 19. Grammar that defines the correct formation of tokens into sentences (programs) for the language. AC 20. individual word/symbol/character that can be used to create sentences (programs) in a language (Alphabet) Q 21. a symbols that represent possible combinations of words/symbols/characters in a language U 22. a set of rules where each rule specifies a string of terminals/non-terminals that can substitute for another set of terminals/non-terminals H 23. a special Non-Terminal that represents all possible valid sentences (programs) in a language. F 24. describes a grammar where, for any given situation, only one production may be chosen as a substitution. P 25. describes a grammar where, for at least one situation, two or more productions may be chosen as a substitution. A 26. Action of a grammar when a derivation can be found for a sentence W 27. Action of a grammar when a derivation can NOT be found for a sentence AE 28. automata that has an infinite tape, can read/write/advance/rewind its tape, and uses an Unrestricted grammar.

N 29. automata that has a finite tape, can read/write/advance/rewind its tape, and uses a Context Sensitive grammar. V 30. automata that has a finite tape, can only read its tape, and only one time, and uses a Stack to implement a Context Free Grammar. G 31. automata that has a finite tape, can only read its tape, and only one time, and uses a Regular Grammar 32. Draw and label the Structure of a Compiler Diagram, including - The four major components (label with their name) - The input/output files (label with their name) - The two major data structures (tables) (label with their name) - Arrows showing the flow of information (label with the information transferred) Answer: 33. Draw a diagramof the results of inserting items into a Hash Table as coded for Proj. 2. - items consist of only digits - hash function: sums the digits and mods by 10. Ex: hash(441441) = 4+4+1+4+4+1 = 18; 18 mod 10 = 8 - the hash table is an array of 10 buckets, indexed 0-9. - each bucket is a linked list of nodes - collisions are attached at the end of the linked list. Insert in order: 441441 12345 54321 007 99 102 430 Note: a slightly different hash function may be used on the exam Answer to the right

34. Complete the following table of the Chomsky Hierarchy, where Class 0 is the least restrictive classification. For the Production column, give an example of a grammar production for the class that would not satisfy the requirements of a higher class. Use lower-case letters for terminals and upper-case letters for non-terminals. (do not answer with an empty production, even though that would be correct in some cases). Level Grammar Recognizer Production Example 0 Unrestricted Turing Machine abcxy d 1 Context Sensitive Linear Bounded Automata axb cdyzef 2 Context Free Push Down Automata X ayczd 3 Regular Finite State Automata X ay 35. List and describe the four elements of the formal definition of a General Grammar: - set of terminals (alphabet) N set of non-terminals P set of productions S Goal Symbol S N 35. Draw an FSA (graphical form) for string literals in C/C++ (simplified). The rules are: - must start and end with a double quote - may contain \ to represent the quote character, and \\ to represent the \ character. - \<anything else> is considered invalid (an error) - must not contain an EOF character. - use to represent all characters other than EOF, double quote, and backslash - you may use empty productions if you wish Answer:

36. Given the following graphical FSA, write the formal/mathematical definition of the language. Use the (N,t) = N format to write the productions. Answer: = { a, b, c, d, e, f } Q = { S, X, Y, Z } = { (S,a) = X, (X,b) = X, (X,e) = X (X,d) = Z, (X,c) = Y, (Y,c) = Y (Y,f) = Z } q0 = S F = { Z } 37. Given the FSA in #36, rewrite the productions using LHS RHS format. S ax or, removing Z S ax X bx X bx X ex X ex X dz X d X cy X cy Y cy Y cy Y fz Y f Z 38. Using the productions in #37, draw or write a derivation showing the sentence abbccf is accepted by the language. S Start ax S ax abx X bx abbx X bx abbcy X cy abbccy Y cy abbccfz Y fz or Y f and drop the last step abbccf Z 39. Given the FSA in #36, express the FSA in Table Form. Mark halt states with * a b c d e f S X X X Y Z X Y Y Z Z*

40. Using the FSA in #36, write a Regular Expression to define the language. Use only the formal metasymbols used in class do not use symbols from computing languages, etc. Alternative correct answers (there are others): a(b e) * (d c + f) a(b e) * (d (cc * f)) cc * is equivalent to c + a(b e) * (d (c + f)) concatenation of c + f overrides the, but adding parens is OK 41. Write the Algorithm for implementing an FSA. Assume productions and halt states are somehow identified. Use readchar() to represent reading the next character from the input file, and that it returns an EOF character at the end of file. state = start c = readchar() while c!=eof and state!= error { state = get production based on state and c to get the next state if no production found state = error else c = readchar() } if c==eof and state is a halt state ACCEPT else REJECT