# CS 164 Programming Languages and Compilers Handout 8. Midterm I

Save this PDF as:

Size: px
Start display at page:

## Transcription

2 1. Regular Expressions (1) The following description of integer constants in C++ appears on page 480 of \The C++ Programming Language." An integer constant consisting of a sequence of digits is taken to be decimal (base ten) unless it begins with 0 (digit zero). A sequence of digits starting with 0 is taken to be an octal integer (base eight). The digits 8 and 9 are not octal digits. A sequence of digits preceded by 0x or 0X is taken to be a hexadecimal integer (base sixteen). The hexadecimal digits include a or A through f or F : : :. The type of an integer depends on its : : : sux. [An integer may have no sux.] : : :If [the integer] is suxed by u or U, its type is : : :. If it is suxed by l or L, its type is : : :. [Either or both suxes may appear at most once each in either order.] Give a regular expression for C++ integer constants. Use only the operations +,, and concatenation in your expression (no special ex notation). You may also use parentheses and (which are not operations). For convenience, you may name a regular expression R by writing name = R. [spaces are not significant] octal = nonzero = decimal = 0 + nonzero hex = decimal + a + A + b + B + c + C + d + D + e + E + f + F optu = u + U + epsilon optl = l + L + epsilon suffix = (optu optl)+(optl optu) number = (octal octal*) + (nozero decimal*) + ((0x + 0X) hex hex*) integer = number suffix [Note: We also allowed (0x hex*)] Fall 95 page 2 of 11

3 2. Finite Automata and Regular Expressions (1) For each of the following nite automata, give an equivalent regular expression. Clearly mark your answer to each part. As in the previous problem, use only the basic regular expression notation. (a) 0 1 RE: 0*1 (b) 0 1 RE: (0 + 1)* (c) RE: ((10 (10)*) + (01 (01)*)) 10 Fall 95 page 3 of 11

4 3. Grammars (20 points) Give a context-free grammar for each of the following languages. (a) Any string of x's followed by an equal number of y's. 7 points -> xy epsilon (b) Any string of x's of length n followed by a string of y's of length 2n + 1, for any n 0. 7 points -> xyy y (c) Any string of x's and y's with an equal number of x's and y's. The x's and y's may appear in any order. 6 points -> xy yx epsilon Fall 95 page 4 of 11

5 4. Top-Down Parsing (20 points) Conser the following grammar for a subset of English sentences. The nonterminals are ; NP; VP; AP. The terminals are the, noun, adective, verb. The start symbol is.! NP VP NP VP NP NP! the AP noun AP! AP adective VP! verb Give an LL(1) grammar that generates the same language as this grammar. how the parsing table for the grammar you produce. a) Left factor! NP VP NP opt NP opt! NP NP! the AP noun AP! AP adective VP! verb b) Eliminate left recursion! NP VP NP opt NP opt! NP NP! the AP noun AP! adective AP VP! verb c) Construct table the noun verb adective \$! NP VP NP opt NP opt NP opt! NP NP opt! NP NP! the AP noun AP AP! AP! adective AP VP VP! verb Fall 95 page 5 of 11

6 5. LALR Parsing and Conicts (30 points) Conser the following DFA of LR(1) items for a LALR(1) parser. The states are numbered; refer to these numbers where appropriate in the following questions. [ ->., \$ ] [ ->. :=, \$ ] [ ->. +, \$ ] [ ->., \$ ] [ ->. string, \$ ] [ ->., \$ ] [ ->. +, \$ ] [ -> +., \$/+ ] [ ->. :=, \$/+ ] [ ->. +, \$/+ ] [ ->., \$/+ ] [ ->. string, \$/+ ] 1 string [ ->. :=, \$/+ ] [ ->., \$/+ ] [ -> string., \$/+ ] string + 4 string 2 [ -> :=., \$/+ ] [ ->. +, \$/+ ] := [ -> :=., \$/+ ] [ ->. :=, \$/+ ] [ ->. +, \$/+ ] [ ->., \$/+ ] [ ->. string, \$/+ ] [ -> +., \$/+ ] [ ->. +, \$/+ ] Fall 95 page 6 of 11

7 (a) Give the grammar used in constructing the DFA. -> string + := (b) how that the grammar is ambiguous. The string + + has two parse trees: (c) Which of the following strings are viable prexes? For each string that is a viable prex, give a sux that produces a right sentential form. i. 2 points Yes: suffix: \$ ii point No. iii. + := 2 points Yes: suffix: \$ (d) Which states of the DFA have conicts and of what kind (shift-reduce or reduce-reduce)? Be sure to state clearly the cause of the conict in each case. tate 7 has a shift-reduce conflict on input +. tate 8 has a shift-reduce conflict on input +. Fall 95 page 7 of 11

8 (e) Which conicts should be resolved in which way to give the := operator higher precedence than +? Reduce should be chosen in state 8. (f) Which conicts should be resolved in which way to cause the + operator to associate to the right? hift should be chosen in state 7. Fall 95 page 8 of 11

9 6. Error Recovery (30 points) This problem uses the same DFA as the previous problem. You will need to refer to that DFA again to answer the parts of this question. Assume that any shift/reduce conicts are resolved in favor of reducing. (a) Conser the string := string string how the sequence of congurations of the LALR(1) parsing algorithm as it parses this string according to the DFA of the previous problem. Indicate exactly where the error is detected. 10 points (# := string string) ( # := string string) ( := # string string) ( := string # string) Error: cannot reduce. (b) Conser a new action panic N t, where N is a non-terminal and t is a terminal. The meaning of the action is to push N on the stack and discard all input tokens up to, but not including, the next t. If there is no next t, then N is pushed on the stack and all remaining input is discarded. Assume we want the parser to take action panic + whenever it is in conguration + #w and the rst token of w is erroneous. Which entries in the action table should have panic +? (You do not need to give the entire action table to answer the question; ust indicate which entries have the new action.) how the sequence of congurations of the parser on input 10 points + := + + action(6, :=) = panic + action(6, +) = panic + action(6, \$) = panic + (# + := + + ) ( # + := + + ) ( # + := + + ) ( + # := + + ) ( + # + + ) ( # + + ) ( + # + ) ( + # + ) ( # + ) ( + # ) ( + #) Fall 95 page 9 of 11

10 ( + #) ( #) (' #) Fall 95 page 10 of 11

11 (c) Conser a new action insert t where t is a terminal. The meaning of the action is to insert t before the next input token (i.e., t becomes the next input). Give insert actions that implement each of the following local recovery strategies. Be sure to say which entries in the action table have the insert actions. i. If the input contains an followed by a string, insert an := between them. action(2, string) = insert := ii. If the input contains two consecutive strings, insert a + between them. action(4, string) = insert + iii. If the input contains a string followed by an, insert a + between them. action(4, ) = insert + Fall 95 page 11 of 11

### Operator precedence parsing

Operator precedence parsing Bottom-up parsing methods that follow the idea of shift-reduce parsers Several flavors: operator, simple, and weak precedence. In this course, only weak precedence Main di erences

### Bottom-Up Parsing. An Introductory Example

Bottom-Up Parsing Bottom-up parsing is more general than top-down parsing Just as efficient Builds on ideas in top-down parsing Bottom-up is the preferred method in practice Reading: Section 4.5 An Introductory

### Solutions to Written Assignment 2

olutions to Written Assignment 2 1. Give a context-free grammar (CFG) for each of the following languages over the alphabet Σ = a, b: (a) All strings in the language L : a n b m a 2n n, m 0 aaa B B bb

### Parsing IV Bottom-up Parsing

Parsing IV Bottom-up Parsing Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice University have explicit permission to make copies

### If-Then-Else Problem (a motivating example for LR grammars)

If-Then-Else Problem (a motivating example for LR grammars) If x then y else z If a then if b then c else d this is analogous to a bracket notation when left brackets >= right brackets: [ [ ] ([ i ] j,

### CS143 Handout 08 Summer 2008 July 02, 2007 Bottom-Up Parsing

CS143 Handout 08 Summer 2008 July 02, 2007 Bottom-Up Parsing Handout written by Maggie Johnson and revised by Julie Zelenski. Bottom-up parsing As the name suggests, bottom-up parsing works in the opposite

### COMP 356 Programming Language Structures Notes for Chapter 4 of Concepts of Programming Languages Scanning and Parsing

COMP 356 Programming Language Structures Notes for Chapter 4 of Concepts of Programming Languages Scanning and Parsing The scanner (or lexical analyzer) of a compiler processes the source program, recognizing

### Bottom-Up Syntax Analysis LR - metódy

Bottom-Up Syntax Analysis LR - metódy Ján Šturc Shift-reduce parsing LR methods (Left-to-right, Righ most derivation) SLR, Canonical LR, LALR Other special cases: Operator-precedence parsing Backward deterministic

Top-down Parsing Recursive Descent & LL(1) Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved. Roadmap (Where are we?) We set out to study parsing Specifying syntax Context-free grammars

### Grammars & Parsing. Lecture 13 CS 2112 Fall 2014

Grammars & Parsing Lecture 13 CS 2112 Fall 2014 Motivation The cat ate the rat. The cat ate the rat slowly. The small cat ate the big rat slowly. The small cat ate the big rat on the mat slowly. The small

### University of Toronto Department of Electrical and Computer Engineering. Midterm Examination. CSC467 Compilers and Interpreters Fall Semester, 2005

University of Toronto Department of Electrical and Computer Engineering Midterm Examination CSC467 Compilers and Interpreters Fall Semester, 2005 Time and date: TBA Location: TBA Print your name and ID

### Pushdown automata. Informatics 2A: Lecture 9. Alex Simpson. 3 October, 2014. School of Informatics University of Edinburgh als@inf.ed.ac.

Pushdown automata Informatics 2A: Lecture 9 Alex Simpson School of Informatics University of Edinburgh als@inf.ed.ac.uk 3 October, 2014 1 / 17 Recap of lecture 8 Context-free languages are defined by context-free

### Syntaktická analýza. Ján Šturc. Zima 208

Syntaktická analýza Ján Šturc Zima 208 Position of a Parser in the Compiler Model 2 The parser The task of the parser is to check syntax The syntax-directed translation stage in the compiler s front-end

### Parse Trees. Prog. Prog. Stmts. { Stmts } Stmts = Stmts ; Stmt. id + id = Expr. Stmt. id = Expr. Expr + id

Parse Trees To illustrate a derivation, we can draw a derivation tree (also called a parse tree): Prog { Stmts } Stmts ; Stmt Stmt = xpr = xpr xpr + An abstract syntax tree (AST) shows essential structure

### Syntactic Analysis and Context-Free Grammars

Syntactic Analysis and Context-Free Grammars CSCI 3136 Principles of Programming Languages Faculty of Computer Science Dalhousie University Winter 2012 Reading: Chapter 2 Motivation Source program (character

### Programming Language Syntax

Programming Language Syntax Natural language vs. programming language No ambiguity allowed in programming languages in form (syntax) and meaning (semantics) Thus, programming language specifications use

### Programming Languages Third Edition

Programming Languages Third Edition Chapter 6 Syntax Objectives Understand the lexical structure of programming languages Understand context-free grammars and BNFs Become familiar with parse trees and

### FIRST and FOLLOW sets a necessary preliminary to constructing the LL(1) parsing table

FIRST and FOLLOW sets a necessary preliminary to constructing the LL(1) parsing table Remember: A predictive parser can only be built for an LL(1) grammar. A grammar is not LL(1) if it is: 1. Left recursive,

### Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science

Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Fall 2005 Handout 7 Scanner Parser Project Wednesday, September 7 DUE: Wednesday, September 21 This

### Context-Free Grammars

Context-Free Grammars Describing Languages We've seen two models for the regular languages: Automata accept precisely the strings in the language. Regular expressions describe precisely the strings in

### Compiler Construction

Compiler Construction Regular expressions Scanning Görel Hedin Reviderad 2013 01 23.a 2013 Compiler Construction 2013 F02-1 Compiler overview source code lexical analysis tokens intermediate code generation

### NUMBER SYSTEMS CHAPTER 19-1

NUMBER SYSTEMS 19.1 The Decimal System 19. The Binary System 19.3 Converting between Binary and Decimal Integers Fractions 19.4 Hexadecimal Notation 19.5 Key Terms and Problems CHAPTER 19-1 19- CHAPTER

### Base Conversion written by Cathy Saxton

Base Conversion written by Cathy Saxton 1. Base 10 In base 10, the digits, from right to left, specify the 1 s, 10 s, 100 s, 1000 s, etc. These are powers of 10 (10 x ): 10 0 = 1, 10 1 = 10, 10 2 = 100,

### Regular Expressions. Languages. Recall. A language is a set of strings made up of symbols from a given alphabet. Computer Science Theory 2

Regular Expressions Languages Recall. A language is a set of strings made up of symbols from a given alphabet. Computer Science Theory 2 1 String Recognition Machine Given a string and a definition of

### Lecture 5: Context Free Grammars

Lecture 5: Context Free Grammars Introduction to Natural Language Processing CS 585 Fall 2007 Andrew McCallum Also includes material from Chris Manning. Today s Main Points In-class hands-on exercise A

### Computing Functions with Turing Machines

CS 30 - Lecture 20 Combining Turing Machines and Turing s Thesis Fall 2008 Review Languages and Grammars Alphabets, strings, languages Regular Languages Deterministic Finite and Nondeterministic Automata

### CSE 1400 Applied Discrete Mathematics Conversions Between Number Systems

CSE 400 Applied Discrete Mathematics Conversions Between Number Systems Department of Computer Sciences College of Engineering Florida Tech Fall 20 Conversion Algorithms: Decimal to Another Base Conversion

### Quick Look at Using Bison Top-Down Parsers

Syntax Analysis Part II Quick Look at Using Bison Top-Down Parsers EECS 483 Lecture 5 University of Michigan Wednesday, September 20, 2006 Reading/Announcements Reading: Section 4.4 (top-down parsing)

### Scanner. tokens scanner parser IR. source code. errors

Scanner source code tokens scanner parser IR errors maps characters into tokens the basic unit of syntax x = x + y; becomes = + ; character string value for a token is a lexeme

### CSI 333 Lecture 1 Number Systems

CSI 333 Lecture 1 Number Systems 1 1 / 23 Basics of Number Systems Ref: Appendix C of Deitel & Deitel. Weighted Positional Notation: 192 = 2 10 0 + 9 10 1 + 1 10 2 General: Digit sequence : d n 1 d n 2...

### PP2: Syntax Analysis

PP2: Syntax Analysis Date Due: 09/20/2016 11:59pm 1 Goal In this programming project, you will extend your Decaf compiler to handle the syntax analysis phase, the second task of the front-end, by using

### Finite Automata and Formal Languages

Finite Automata and Formal Languages TMV026/DIT321 LP4 2011 Lecture 14 May 19th 2011 Overview of today s lecture: Turing Machines Push-down Automata Overview of the Course Undecidable and Intractable Problems

### Programming Languages: Syntax Description and Parsing

Programming Languages: Syntax Description and Parsing Onur Tolga Şehitoğlu Computer Engineering,METU 27 May 2009 Outline Introduction Introduction Syntax: the form and structure of a program. Semantics:

### Approximating Context-Free Grammars for Parsing and Verification

Approximating Context-Free Grammars for Parsing and Verification Sylvain Schmitz LORIA, INRIA Nancy - Grand Est October 18, 2007 datatype a option = NONE SOME of a fun filter pred l = let fun filterp (x::r,

### Context-Free Grammars (CFG)

Context-Free Grammars (CFG) SITE : http://www.sir.blois.univ-tours.fr/ mirian/ Automata Theory, Languages and Computation - Mírian Halfeld-Ferrari p. 1/2 An informal example Language of palindromes: L

### CHAPTER 3 Numbers and Numeral Systems

CHAPTER 3 Numbers and Numeral Systems Numbers play an important role in almost all areas of mathematics, not least in calculus. Virtually all calculus books contain a thorough description of the natural,

### Binary Which powers of 2 are we adding? Decimal answer 10101

1 CS 105 Lab #1 representation of numbers numbers are the dough we use to represent all information inside the computer. The purpose of this lab is to practice with some binary number representations.

### Context free grammars and predictive parsing

Context free grammars and predictive parsing Programming Language Concepts and Implementation Fall 2012, Lecture 6 Context free grammars Next week: LR parsing Describing programming language syntax Ambiguities

### Modeling Computation

Modeling Computation 11.1.1 Language and Grammars Natural Languages: English, French, German, Programming Languages: Pascal, C, Java, Grammar is used to generate sentences from basic words of the language

### Compilers I - Chapter 2: An introduction to syntax analysis (and a complete toy compiler)

Compilers I - Chapter 2: An introduction to syntax analysis (and a complete toy compiler) Lecturers: Part I: Paul Kelly (phjk@doc.ic.ac.uk) Office: room 423 Part II: Naranker Dulay (nd@doc.ic.ac.uk) Office:

### Context Free and Non Context Free Languages

Context Free and Non Context Free Languages Part I: Pumping Theorem for Context Free Languages Context Free Languages and Push Down Automata Theorems For Every Context Free Grammar there Exists an Equivalent

### Deterministic Push-Down Store Automata

Deterministic Push-Down tore Automata 1 Context-Free Languages A B C D... A w 0 w 1 D...E The languagea n b n : a b ab 2 Finite-tate Automata 3 Pushdown Automata Pushdown automata (pda s) is an fsa with

### Information associated with a grammar symbol Computed using semantic rules associated with grammar rules

Information associated with a grammar symbol Computed using semantic rules associated with grammar rules Attributes Section 5.1 Example: PRODUCTION L E \n E E 1 + T SEMANTIC RULES print E.val E.val = E1.val

### Positional Numbering System

APPENDIX B Positional Numbering System A positional numbering system uses a set of symbols. The value that each symbol represents, however, depends on its face value and its place value, the value associated

### CS 57, Spring 2013 Lecture 7 April 8, 2013

CS 57, Spring 2013 Lecture 7 April 8, 2013 Bison, continued A bison calculator, continued Last time, we saw how to use bison to produce a simple calculator. There s one more things to see here. Let s uncomment

### Number base conversion

Number base conversion The human being use decimal number system while computer uses binary number system. Therefore it is necessary to convert decimal number into its binary equivalent while feeding number

### Properties of Context-Free Languages. Decision Properties Closure Properties

Properties of Context-Free Languages Decision Properties Closure Properties 1 Summary of Decision Properties As usual, when we talk about a CFL we really mean a representation for the CFL, e.g., a CFG

### Our recursive descent parser encodes state. information in its run-time stack, or call. Using recursive procedure calls to implement a

Non-recursive predictive parsing Observation: Our recursive descent parser encodes state information in its run-time stack, or call stack. Using recursive procedure calls to implement a stack abstraction

### Intelligent Systems (AI-2)

Intelligent Systems (AI-2) Computer Science cpsc422, Lecture 25 Nov, 9, 2016 CPSC 422, Lecture 26 Slide 1 Morphology Syntax Semantics Pragmatics Discourse and Dialogue Knowledge-Formalisms Map (including

### Lecture 7: Definite Clause Grammars

Lecture 7: Definite Clause Grammars Theory Introduce context free grammars and some related concepts Introduce definite clause grammars, the Prolog way of working with context free grammars (and other

### Automata and Formal Languages

Automata and Formal Languages Winter 2009-2010 Yacov Hel-Or 1 What this course is all about This course is about mathematical models of computation We ll study different machine models (finite automata,

### Definition: String concatenation. Definition: String. Definition: Language (cont.) Definition: Language

CMSC 330: Organization of Programming Languages Regular Expressions and Finite Automata Introduction That s it for the basics of Ruby If you need other material for your project, come to office hours or

### Discrete mathematics is the study of techniques, ideas and modes

CHAPTER 1 Discrete Systems Discrete mathematics is the study of techniques, ideas and modes of reasoning that are indispensable in applied disciplines such as computer science or information technology.

### SRM UNIVERSITY FACULTY OF ENGINEERING & TECHNOLOGY SCHOOL OF COMPUTING DEPARTMENT OF SOFTWARE ENGINEERING COURSE PLAN

Course Code : CS0355 SRM UNIVERSITY FACULTY OF ENGINEERING & TECHNOLOGY SCHOOL OF COMPUTING DEPARTMENT OF SOFTWARE ENGINEERING COURSE PLAN Course Title : THEORY OF COMPUTATION Semester : VI Course : June

### Reading 13 : Finite State Automata and Regular Expressions

CS/Math 24: Introduction to Discrete Mathematics Fall 25 Reading 3 : Finite State Automata and Regular Expressions Instructors: Beck Hasti, Gautam Prakriya In this reading we study a mathematical model

### Lesson 1C Using the printf and String.format commands. By John B. Owen All rights reserved 2011, revised 2015

Lesson 1C Using the printf and String.format commands By John B. Owen All rights reserved 2011, revised 2015 Table of Contents Objectives printf command printf examples ABCs of printf The rest of the story

### Useful Number Systems

Useful Number Systems Decimal Base = 10 Digit Set = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} Binary Base = 2 Digit Set = {0, 1} Octal Base = 8 = 2 3 Digit Set = {0, 1, 2, 3, 4, 5, 6, 7} Hexadecimal Base = 16 = 2

### Introduction to Automata Theory. Reading: Chapter 1

Introduction to Automata Theory Reading: Chapter 1 1 What is Automata Theory? Study of abstract computing devices, or machines Automaton = an abstract computing device Note: A device need not even be a

### Automata and Computability. Solutions to Exercises

Automata and Computability Solutions to Exercises Fall 25 Alexis Maciel Department of Computer Science Clarkson University Copyright c 25 Alexis Maciel ii Contents Preface vii Introduction 2 Finite Automata

### Probabilistic Context-Free Grammars (PCFGs)

Probabilistic Context-Free Grammars (PCFGs) Michael Collins 1 Context-Free Grammars 1.1 Basic Definition A context-free grammar (CFG) is a 4-tuple G = (N, Σ, R, S) where: N is a finite set of non-terminal

### Peter Donovan Adobe Systems Inc., 345 Park Avenue, San Jose, CA 95110

LR(1) Parser Generation System: LR(1) Error Recovery, Oracles, and Generic Tokens Arthur Sorkin Web Oasis, Inc, 940 N Barkley, Mesa, AZ 85203, USA Email: lr1@web-oasis.com Peter Donovan Adobe Systems Inc.,

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

### Introduction. Compiler Design CSE 504. Overview. Programming problems are easier to solve in high-level languages

Introduction Compiler esign CSE 504 1 Overview 2 3 Phases of Translation ast modifled: Mon Jan 28 2013 at 17:19:57 EST Version: 1.5 23:45:54 2013/01/28 Compiled at 11:48 on 2015/01/28 Compiler esign Introduction

### Chomsky and Greibach Normal Forms. Chomsky and Greibach Normal Forms p.1/24

Chomsky and Greibach Normal Forms Chomsky and Greibach Normal Forms p.1/24 Simplifying a CFG It is often convenient to simplify CFG Chomsky and Greibach Normal Forms p.2/24 Simplifying a CFG It is often

### What s a parser How to use Bison? Practice References. Introduction to GDB. Gregorio Toscano Pulido

Laboratorio de Tecnologías de Información Centro de Investigación y de Estudios Avanzados del IPN Laboratorio de Tecnologías de Investigación Outline 1 What s a parser 2 How to use Bison? 3 Practice 4

### Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science

Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2013 Handout Scanner-Parser Project Thursday, Feb 7 DUE: Wednesday, Feb 20, 9:00 pm This project

### Computational Linguistics: Syntax I

Computational Linguistics: Syntax I Raffaella Bernardi KRDB, Free University of Bozen-Bolzano P.zza Domenicani, Room: 2.28, e-mail: bernardi@inf.unibz.it Contents 1 Syntax...................................................

### Honors Class (Foundations of) Informatics. Tom Verhoeff. Department of Mathematics & Computer Science Software Engineering & Technology

Honors Class (Foundations of) Informatics Tom Verhoeff Department of Mathematics & Computer Science Software Engineering & Technology www.win.tue.nl/~wstomv/edu/hci c 2011, T. Verhoeff @ TUE.NL 1/20 Information

### The gas can has a capacity of 4.17 gallons and weighs 3.4 pounds.

hundred million\$ ten------ million\$ million\$ 00,000,000 0,000,000,000,000 00,000 0,000,000 00 0 0 0 0 0 0 0 0 0 Session 26 Decimal Fractions Explain the meaning of the values stated in the following sentence.

### DIT250 / BIT180 - MATHEMATICS. Number Bases. Decimal numbers (base ten), Decimal numbers (base ten), Decimal numbers (base ten), 3/24/2014

DIT250 / BIT180 - MATHEMATICS ASSESSMENT CA 40% 3 TESTS EXAM 60% LECTURE SLIDES www.lechaamwe.weebly.com Lecture notes DIT250/BIT180 Number Bases In this lesson we shall discuss different Number Bases,

### good.cl and bad.cl These les test a few features of the grammar. You should add tests to ensure that good.cl exercises every legal construction of the

Programming Assignment III First Due Date: (Grammar) March 12, 2005 (submission dated midnight). Second Due Date: (Complete) March 19, 2005 (submission dated midnight). Purpose: This project is intended

### TDDD65 Introduction to the Theory of Computation

TDDD65 Introduction to the Theory of Computation Lecture 3 Gustav Nordh Department of Computer and Information Science gustav.nordh@liu.se 2012-09-05 Outline Context-free Grammars Ambiguity Pumping Lemma

### Computer Science 281 Binary and Hexadecimal Review

Computer Science 281 Binary and Hexadecimal Review 1 The Binary Number System Computers store everything, both instructions and data, by using many, many transistors, each of which can be in one of two

### Theorem (The division theorem) Suppose that a and b are integers with b > 0. There exist unique integers q and r so that. a = bq + r and 0 r < b.

Theorem (The division theorem) Suppose that a and b are integers with b > 0. There exist unique integers q and r so that a = bq + r and 0 r < b. We re dividing a by b: q is the quotient and r is the remainder,

### The Quick Calculator, revisited: Compiler Construction SMD163. Introducing jacc: Parsing in the Quick Calculator:

Compiler Construction SMD163 Lecture 6: Parser generators & abstract syntax Viktor Leijon & Peter Jonsson with slides by Johan Nordlander. Contains material generously provided by Mark P. Jones The Quick

### Formal Languages and Automata Theory - Regular Expressions and Finite Automata -

Formal Languages and Automata Theory - Regular Expressions and Finite Automata - Samarjit Chakraborty Computer Engineering and Networks Laboratory Swiss Federal Institute of Technology (ETH) Zürich March

### Please note that there is more than one way to answer most of these questions. The following only represents a sample solution.

HOMEWORK THREE SOLUTION CSE 355 DUE: 10 MARCH 2011 Please note that there is more than one way to answer most of these questions. The following only represents a sample solution. (1) 2.4 and 2.5 (b),(c),(e),(f):

### OBTAINING PRACTICAL VARIANTS OF LL (k) AND LR (k) FOR k >1. A Thesis. Submitted to the Faculty. Purdue University.

OBTAINING PRACTICAL VARIANTS OF LL (k) AND LR (k) FOR k >1 BY SPLITTING THE ATOMIC k-tuple A Thesis Submitted to the Faculty of Purdue University by Terence John Parr In Partial Fulfillment of the Requirements

### Parsing Challenges in Java 8

Parsing Challenges in Java 8 Erik Hogeman, Jesper Öqvist, Görel Hedin Department of Computer Science Lund University JastAddJ JastAddJ is a full source-to-bytecode modular Java compiler each Java version

### Theory of Computation

Theory of Computation For Computer Science & Information Technology By www.thegateacademy.com Syllabus Syllabus for Theory of Computation Regular Expressions and Finite Automata, Context-Free Grammar s

### 6.045: Automata, Computability, and Complexity Or, Great Ideas in Theoretical Computer Science Spring, 2010. Class 4 Nancy Lynch

6.045: Automata, Computability, and Complexity Or, Great Ideas in Theoretical Computer Science Spring, 2010 Class 4 Nancy Lynch Today Two more models of computation: Nondeterministic Finite Automata (NFAs)

### NUMBER SYSTEMS. William Stallings

NUMBER SYSTEMS William Stallings The Decimal System... The Binary System...3 Converting between Binary and Decimal...3 Integers...4 Fractions...5 Hexadecimal Notation...6 This document available at WilliamStallings.com/StudentSupport.html

### Chapter 23(continued) Natural Language for Communication

Chapter 23(continued) Natural Language for Communication Phrase Structure Grammars Probabilistic context-free grammar (PCFG): Context free: the left-hand side of the grammar consists of a single nonterminal

### Yacc: Yet Another Compiler-Compiler

Stephen C. Johnson ABSTRACT Computer program input generally has some structure in fact, every computer program that does input can be thought of as defining an input language which it accepts. An input

### COMP 356 Sample Midterm Exam I

COMP 356 Sample Midterm Exam I 1. (8 points) What are the relative advantages disadvantages of implementing a programming language with an interpreter as compared with implementing the language with a

### Chapter 2 Numeric Representation.

Chapter 2 Numeric Representation. Most of the things we encounter in the world around us are analog; they don t just take on one of two values. How then can they be represented digitally? The key is that

### Chapter 5 Parser Combinators

Part II Chapter 5 Parser Combinators 5.1 The type of parsers 5.2 Elementary parsers 5.3 Grammars 5.4 Parser combinators 5.5 Parser transformers 5.6 Matching parentheses 5.7 More parser combinators 5.8

### C H A P T E R Regular Expressions regular expression

7 CHAPTER Regular Expressions Most programmers and other power-users of computer systems have used tools that match text patterns. You may have used a Web search engine with a pattern like travel cancun

### Chapter 1. Real Numbers Operations

www.ck1.org Chapter 1. Real Numbers Operations Review Answers 1 1. (a) 101 (b) 8 (c) 1 1 (d) 1 7 (e) xy z. (a) 10 (b) 14 (c) 5 66 (d) 1 (e) 7x 10 (f) y x (g) 5 (h) (i) 44 x. At 48 square feet per pint

### Automata Theory and Languages

Automata Theory and Languages SITE : http://www.info.univ-tours.fr/ mirian/ Automata Theory, Languages and Computation - Mírian Halfeld-Ferrari p. 1/1 Introduction to Automata Theory Automata theory :

### CS 341 Homework 9 Languages That Are and Are Not Regular

CS 341 Homework 9 Languages That Are and Are Not Regular 1. Show that the following are not regular. (a) L = {ww R : w {a, b}*} (b) L = {ww : w {a, b}*} (c) L = {ww' : w {a, b}*}, where w' stands for w

### MT1 Number Systems. In general, the number a 3 a 2 a 1 a 0 in a base b number system represents the following number:

MT1 Number Systems MT1.1 Introduction A number system is a well defined structured way of representing or expressing numbers as a combination of the elements of a finite set of mathematical symbols (i.e.,

### Lexical analysis FORMAL LANGUAGES AND COMPILERS. Floriano Scioscia. Formal Languages and Compilers A.Y. 2015/2016

Master s Degree Course in Computer Engineering Formal Languages FORMAL LANGUAGES AND COMPILERS Lexical analysis Floriano Scioscia 1 Introductive terminological distinction Lexical string or lexeme = meaningful

### Definite Clause Grammar with Prolog. Lecture 13

Definite Clause Grammar with Prolog Lecture 13 Definite Clause Grammar The most popular approach to parsing in Prolog is Definite Clause Grammar (DCG) which is a generalization of Context Free Grammar

### Lexical Analysis. Scanners, Regular expressions, and Automata. cs4713 1

Lexical Analysis Scanners, Regular expressions, and Automata cs4713 1 Phases of compilation Compilers Read input program optimization translate into machine code front end mid end back end Lexical analysis

### Binary Numbers. Binary Octal Hexadecimal

Binary Numbers Binary Octal Hexadecimal Binary Numbers COUNTING SYSTEMS UNLIMITED... Since you have been using the 10 different digits 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9 all your life, you may wonder how

### Context Free Grammars

Context Free Grammars So far we have looked at models of language that capture only local phenomena, namely what we can analyze when looking at only a small window of words in a sentence. To move towards

### CHAPTER TWO. 2.1 Unsigned Binary Counting. Numbering Systems

CHAPTER TWO Numbering Systems Chapter one discussed how computers remember numbers using transistors, tiny devices that act like switches with only two positions, on or off. A single transistor, therefore,