Full file at

Similar documents
CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

CSCI312 Principles of Programming Languages!

More Assigned Reading and Exercises on Syntax (for Exam 2)

High Level Languages. Java (Object Oriented) This Course. Jython in Java. Relation. ASP RDF (Horn Clause Deduction, Semantic Web) Dr.

Lecture 3 Tao Wang 1

Programming Languages Third Edition. Chapter 9 Control I Expressions and Statements

Using an LALR(1) Parser Generator

CSC 467 Lecture 3: Regular Expressions

Syntax Intro and Overview. Syntax

Contents. Jairo Pava COMS W4115 June 28, 2013 LEARN: Language Reference Manual

The PCAT Programming Language Reference Manual

corgi Language Reference Manual COMS W4115

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

IPCoreL. Phillip Duane Douglas, Jr. 11/3/2010

G Programming Languages - Fall 2012

Motivating Examples (1.1) Selections. Motivating Examples (1.2) Learning Outcomes. EECS1022: Programming for Mobile Computing Winter 2018

Key Differences Between Python and Java

MIT Specifying Languages with Regular Expressions and Context-Free Grammars

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

Selections. EECS1021: Object Oriented Programming: from Sensors to Actuators Winter 2019 CHEN-WEI WANG

22c:111 Programming Language Concepts. Fall Syntax III

Chapter 3: CONTEXT-FREE GRAMMARS AND PARSING Part2 3.3 Parse Trees and Abstract Syntax Trees

1 Lexical Considerations

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

Lexical and Syntax Analysis

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

CPS 506 Comparative Programming Languages. Syntax Specification

Typescript on LLVM Language Reference Manual

ECE251 Midterm practice questions, Fall 2010

Control Structures. CIS 118 Intro to LINUX

More on Syntax. Agenda for the Day. Administrative Stuff. More on Syntax In-Class Exercise Using parse trees

COP 3402 Systems Software Top Down Parsing (Recursive Descent)

Pace University. Fundamental Concepts of CS121 1

Chapter 8. Statement-Level Control Structures

UNIT I Programming Language Syntax and semantics. Kainjan Sanghavi

Decaf Language Reference

This book is licensed under a Creative Commons Attribution 3.0 License

programming languages need to be precise a regular expression is one of the following: tokens are the building blocks of programs

Lexical Considerations

3. Context-free grammars & parsing

COP4020 Programming Languages. Syntax Prof. Robert van Engelen

CS313D: ADVANCED PROGRAMMING LANGUAGE

Mandatory Exercise 1 INF3110

A Simple Syntax-Directed Translator

There are four numeric types: 1. Integers, represented as a 32 bit (or longer) quantity. Digits sequences (possibly) signed are integer literals:

CSE P 501 Exam 8/5/04

Chapter 3. Describing Syntax and Semantics

UNIT I Programming Language Syntax and semantics. Kainjan Sanghavi

SQL User Defined Code. Kathleen Durant CS 3200

Syntax. A. Bellaachia Page: 1

Computer Science Department Carlos III University of Madrid Leganés (Spain) David Griol Barres

Sprite an animation manipulation language Language Reference Manual

Sir Muhammad Naveed. Arslan Ahmed Shaad ( ) Muhammad Bilal ( )

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

C and C++ I. Spring 2014 Carola Wenk

COP4020 Programming Languages. Syntax Prof. Robert van Engelen

Chapter 3. Describing Syntax and Semantics ISBN

Lexical and Syntactic Analysis

GNU ccscript Scripting Guide IV

Specifying Syntax. An English Grammar. Components of a Grammar. Language Specification. Types of Grammars. 1. Terminal symbols or terminals, Σ

Topic 2: Making Decisions

Topic 2: Making Decisions

Language Reference Manual

FotoScript: The Language Reference Manual

2.2 Syntax Definition

CA4003 Compiler Construction Assignment Language Definition

Chapter 2: Functions and Control Structures

What are compilers? A Compiler

Crayon (.cry) Language Reference Manual. Naman Agrawal (na2603) Vaidehi Dalmia (vd2302) Ganesh Ravichandran (gr2483) David Smart (ds3361)

MIDTERM EXAMINATION - CS130 - Spring 2003

Chapter 7. - FORTRAN I control statements were based directly on IBM 704 hardware

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 8: SEP. 29TH INSTRUCTOR: JIAYIN WANG

PHP 1. Introduction Temasek Polytechnic

Introduction to Bioinformatics

Previously. Iteration. Date and time structures. Modularisation.

ITEC2620 Introduction to Data Structures

ucalc Patterns Examine the following example which can be pasted into the interpreter (paste the entire block at the same time):

Syntactic Analysis. The Big Picture Again. Grammar. ICS312 Machine-Level and Systems Programming

Activity Guide - Will it Crash?

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

APCS Semester #1 Final Exam Practice Problems

Java Bytecode (binary file)

The newcommand.py utility

Binghamton University. CS-211 Fall Syntax. What the Compiler needs to understand your program

12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments.

1. The programming language C is more than 30 years old. True or False? (Circle your choice.)

CS 251 Intermediate Programming Java Basics

Fall 2017 CISC124 9/16/2017

Expr Language Reference

JavaCC Parser. The Compilation Task. Automated? JavaCC Parser

An Introduction to Python (TEJ3M & TEJ4M)

Java: Classes. An instance of a class is an object based on the class. Creation of an instance from a class is called instantiation.

Principles of Programming Languages COMP251: Syntax and Grammars

Decision Making in C

Exercise 1: Balanced Parentheses

(Not Quite) Minijava

Object oriented programming. Instructor: Masoud Asghari Web page: Ch: 3

Principles of Programming Languages COMP251: Syntax and Grammars

COBOL 13. Language Summary. Version 0.01

Learning Language. Reference Manual. George Liao (gkl2104) Joseanibal Colon Ramos (jc2373) Stephen Robinson (sar2120) Huabiao Xu(hx2104)

Transcription:

2 Syntax Exercises 2.1 Integer Integer Digit Integer Digit Digit Integer Digit Digit Digit Digit Digit Digit Digit 4 Digit Digit Digit 4 Digit Digit 4 2 Digit 4 2 0 2.2 This has the same number of steps as above, except that each digit is immediately derived when it appears. E.g., Integer IntegerDigit Integer 0... 2.3 Identif ier Letter Digit Letter a Digit Letter a 2 Letter a 2 i 2.4 Letter Digit Letter Letter Digit i Letter 2 i a 2 i 2. The solution to part (a) appears below. The solutions to parts (b) and

6 2. SYNTAX Assignment = ession ; x Conjunction Equality Relation Addition AddOp AddOp! Primary Primary Primary Literal x a 1 2.6 The solution to part (a) appears below. The solutions to parts (b) and

7 3 4 2.7 The solution to part (a) appears below. The solutions to parts (b) and 4 3 2.8 The solution to part (a) appears below. The solutions to parts (b) and

8 2. SYNTAX 3 4 2.9 There are two solutions to part (a), one of which appears below. The other is a simple variation of this one. (Note that this grammar is ambiguous.) The solutions to parts (b) and (c) are also similar. 3 4 2.10 The solution to part (a) appears below. The solutions to parts (b) and

9 4 3 2.11 To derive the ession - 4 3, we must use the rules ession ession T erm and ession ession T erm. (These are the only ones that generate the - and signs, respectively.) So the first three steps in the derivation give: ession ession T erm ession T erm T erm T erm T erm T erm Since no later step in the derivation can reduce the length of this string, each of the three instances of must derive one of the constants, 4, and 3, respectively. 2.12 Consider the Java rules: IfT henstatement if ( ession ) Statement If T henelsestatement if ( ession ) StatementN oshortif else Statement These rules force the innermost IfStatement in if (x < 0) if (x == 0) y = y - 1; else y = 0; not to have an else part, so that the only feasible parse tree for this statement is has the following shape:

10 2. SYNTAX 2.13 The rules can be changed by adding the delimiter fi as shown below: IfStatement if ( ession ) Statement fi if ( ession ) Statement else Statement fi 2.14 (a) Perl if statements (from perl.com) If Statement if ( ession ) BLOCK { elsif ( ession ) BLOCK } [ else BLOCK ] Here, BLOCK is a sequence of statements (enclosed in curly braces). (b) Python if statements (from python.org) If Statement if ession : BLOCK { elif ession : BLOCK } [ else BLOCK ] (c) Ada if statements (from www.adahome.com/rm9) If Statement if ession then BLOCK { elsif ession then BLOCK } [ else BLOCK ] end if; 2.1 The rule a b { c } is equivalent to: a b b d d c d c The rule a b [ c ] is equivalent to: a b b c 2.16 The diagram below omits the syntax of Integer.

Op 11 ( ) Integer Op! / % 2.17 This should be an essay question if it is answered carefully. 2.18 This type of information can usually be found in an on-line language reference for each language. The number of reserved words we found for each language is: Python 28, Ada9 69, C 32, C 67, and Java 0. Because Perl prefixes identifiers with a symbol such as $, @, %, or &, there are no reserved words in Perl. Except for subroutine calls, Perl does not permit bareword identifiers. 2.19 See Section 12.7 for an introduction to Perl. In particular, see the program in Figure 12.13 for an example of a variable declaration, which you can use to define a grammar rule like the following: variabledeclaration my variablename [ = value ] ; 2.20 The solution to part (a) appears below. The solutions to parts (b) and

12 2. SYNTAX Assignment x Binary Operator Binary Literal! 1 Operator x a