Project phase 1 Scanner front-end assigned Tuesday 2 September, due Tuesday 16 September

Similar documents
Compilers. History of Compilers. A compiler allows programmers to ignore the machine-dependent details of programming.

Important Project Dates

CS 536. Class Meets. Introduction to Programming Languages and Compilers. Instructor. Key Dates. Teaching Assistant. Charles N. Fischer.

What do Compilers Produce?

Project 1: Scheme Pretty-Printer

History of Compilers The term

CS164: Programming Assignment 2 Dlex Lexer Generator and Decaf Lexer

Disclaimer. A Bit About Forth. No Syntax. Outline. I don't know Forth Typical Forth tutorial. Dave Eckhardt

CSCI 2010 Principles of Computer Science. Data and Expressions 08/09/2013 CSCI

Homework 5 ML module language assigned Thursday 20 March, due Friday 4 April

Formats of Translated Programs

The Structure of a Syntax-Directed Compiler

COP4020 Programming Languages. Compilers and Interpreters Robert van Engelen & Chris Lacher

A Bit About Forth. Dave Eckhardt

Computational Expression

Lab 03 - x86-64: atoi

Syntax and Grammars 1 / 21

Data and Expressions. Outline. Data and Expressions 12/18/2010. Let's explore some other fundamental programming concepts. Chapter 2 focuses on:

Lecture 03 Bits, Bytes and Data Types

27-Sep CSCI 2132 Software Development Lecture 10: Formatted Input and Output. Faculty of Computer Science, Dalhousie University. Lecture 10 p.

When do We Run a Compiler?

Programming Languages & Translators. XML Document Manipulation Language (XDML) Language Reference Manual

H212 Introduction to Software Systems Honors

Project #1 rev 2 Computer Science 2334 Fall 2013 This project is individual work. Each student must complete this assignment independently.

Little Language [Grand]

COMP 110 Introduction to Programming. What did we discuss?

Compiling and Interpreting Programming. Overview of Compilers and Interpreters

The Structure of a Compiler

1/16/2013. Program Structure. Language Basics. Selection/Iteration Statements. Useful Java Classes. Text/File Input and Output.

Variables, Constants, and Data Types

Programming Assignment 0

corgi Language Reference Manual COMS W4115

PRINCIPLES OF COMPILER DESIGN UNIT I INTRODUCTION TO COMPILING

CS321 Languages and Compiler Design I. Winter 2012 Lecture 1

Module 8 - Lexical Analyzer Generator. 8.1 Need for a Tool. 8.2 Lexical Analyzer Generator Tool

Assignment 1 Expressions Data Types Formatted Printing Variables Scanning CSC 123 Fall 2018 Answer Sheet Short Answers

CS 426 Fall Machine Problem 1. Machine Problem 1. CS 426 Compiler Construction Fall Semester 2017

CS 541 Spring Programming Assignment 2 CSX Scanner

CS 415 Midterm Exam Spring 2002

Project 3: Base64 Content-Transfer-Encoding

Lecture 22. Java Input/Output (I/O) Streams. Dr. Martin O Connor CA166

CHAPTER 1 Introduction to Computers and Java

CS 6353 Compiler Construction Project Assignments

CSCI B522 Lecture 11 Naming and Scope 8 Oct, 2009

Program Elements -- Introduction

ECE 122 Engineering Problem Solving with Java

Full file at

Short Notes of CS201

Reversing. Time to get with the program

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

CS52 - Assignment 8. Due Friday 4/15 at 5:00pm.

Compilers and Interpreters

COMPILER DESIGN LECTURE NOTES

CS Programming I: Using Objects

CS201 - Introduction to Programming Glossary By

Table of Contents Date(s) Title/Topic Page #s. Abstraction

Pace University. Fundamental Concepts of CS121 1

CS 374 Fall 2014 Homework 2 Due Tuesday, September 16, 2014 at noon

Introduction to Programming Using Java (98-388)

Supporting Level 2 Functionality

CS 209 Spring, 2006 Lab 11: Files & Streams Instructor: J.G. Neal

CS 4240: Compilers and Interpreters Project Phase 1: Scanner and Parser Due Date: October 4 th 2015 (11:59 pm) (via T-square)

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)


CS /534 Compiler Construction University of Massachusetts Lowell

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

CSE 143, Winter 2013 Programming Assignment #8: Huffman Coding (40 points) Due Thursday, March 14, 2013, 11:30 PM

Parsing and Pattern Recognition

Number Systems Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. Indian Institute of Technology Kharagpur Number Representation

Review Chapters 1 to 4. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

CS664 Compiler Theory and Design LIU 1 of 16 ANTLR. Christopher League* 17 February Figure 1: ANTLR plugin installer

Midterm Reminders. Design Pattern #6: Facade. General Idea. The Situation

Java Bytecode (binary file)

CS 553 Compiler Construction Fall 2009 Project #1 Adding doubles to MiniJava Due September 8, 2009

Important Project Dates

CS143 Handout 05 Summer 2011 June 22, 2011 Programming Project 1: Lexical Analysis

Why are there so many programming languages? Why do we have programming languages? What is a language for? What makes a language successful?

CISC-124. This week we continued to look at some aspects of Java and how they relate to building reliable software.

Formatting Output & Enumerated Types & Wrapper Classes

The Structure of a Syntax-Directed Compiler

Topics. Hardware and Software. Introduction. Main Memory. The CPU 9/21/2014. Introduction to Computers and Programming

Compiling Regular Expressions COMP360

Peer Instruction 1. Elementary Programming

COP 3402 Systems Software. Lecture 4: Compilers. Interpreters

CSI32 Object-Oriented Programming

UNIVERSAL SERIAL INTERFACE

Parsing CSCI-400. Principles of Programming Languages.

Programming Project 1: Lexical Analyzer (Scanner)

C17a: Exception and Text File I/O

1 Lexical Considerations

Lexical Considerations

9/5/17. The Design and Implementation of Programming Languages. Compilation. Interpretation. Compilation vs. Interpretation. Hybrid Implementation

introduction week 1 Ritsumeikan University College of Information Science and Engineering Ian Piumarta 1 / 20 imperative programming about the course

Chapter 4 Defining Classes I

Language Reference Manual

Chapter 2. Lexical Elements & Operators

Java Primer 1: Types, Classes and Operators

Computing Science 114 Solutions to Midterm Examination Tuesday October 19, In Questions 1 20, Circle EXACTLY ONE choice as the best answer

Introduction to Compiler Construction

Lexical Considerations

Transcription:

CS 351 Design of Large Programs, Fall 2003 1 Project phase 1 Scanner front-end assigned Tuesday 2 September, due Tuesday 16 September 1.1 Task Write Java classes and interfaces to implement the scanner component of a PostScript interpreter. 1.2 Task in detail Study the syntax of PostScript as defined in the PostScript Language Reference Manual, Second Edition (PLRM2) in Section 3.2. The scanner (Section 3.2.1) conceptually has two components: a front-end, which consumes a list of characters and produces a stream of tokens, and a back-end, which consumes a list of tokens and assembles the tokens into PostScript objects. In this assignment, you will only write the front-end. 1 Additionally, you must write a wrapper that consumes a string, opens a file the name of which is given by the string, reads in the characters of the file into a list and then invokes the scanner, returning a list of tokens as the final result. If there is any problem opening the file, a suitable exception should be raised. Additionally, you must write a pretty-printer that accepts a list of tokens and prints the tokens one to a line. You should write the pretty-printer before you write the scanner itself, so that you can use the pretty-printer for debugging the scanner. Features to pay attention to: correct handling of comments correct handling of white space correct recognition of numbers, including integers, reals, and radix numbers correct handling of integer numbers that exceed the implementation s limit on integer size correct handling of strings, including strings in parentheses and hexadecimally encoded strings correct handling of all string escape sequences (PLRM2, p. 29) Deviations from PLRM2: You do not need to implement the standard PostScript behavior when errors in the input are discovered (such as PostScript limitcheck and syntaxerror errors. Instead, you should declare and raise corresponding Java exceptions. No specific recovery mechanism needs to be implemented. When these errors are raised, a suitable error message must be printed, and then the interpreter may quit. 2 Features in PLRM2 that need not be implemented: binary token and binary object sequence encoding (see Section 3.2 and Section 3.12): only the ASCII encoding (Section 3.2.2) needs to be implemented ASCII base-85 strings 1 For the back-end, we will have to implement a substantial part of the PostScript interpreter first; specifically, we need PostScript virtual memory (VM) in order to store components of composite objects in it. 2 This simplified treatment of errors will apply in all future phases of the interpreter as well.

CS 351 Design of Large Programs, Fall 2003 2 1.3 Hints on the Java implementation You need to choose a Java representation for PostScript integers and reals. I recommend the types int and double. You need to choose a Java representation for PostScript names. I recommend the type String. You need to choose some way of representing lists of characters and lists of tokens. You need to choose a Java representation for tokens. One possibility, which I recommend, is an abstract class of tokens with several concrete variants for integers, reals, names, delimiters, etc., as follows (here equipped with a visitor class interface): abstract class TokenD abstract ; interface TokenVisitorI Object fortokeninteger (Integer i); Object fortokenreal (Double d); Object fortokenstring (String s); Object fortokenexecutablename (String n); Object fortokenliteralname (String n); Object fortokenimmediatelyevaluatedname (String n); Object fortokenleftbracket (); Object fortokenrightbracket (); Object fortokenleftbrace (); Object fortokenrightbrace (); Object fortokenleftdoubleangle (); Object fortokenrightdoubleangle (); class TokenExecutableName extends TokenD private final String n; TokenExecutableName (String _n) n = _n; return ask.fortokenexecutablename (n); class TokenImmediatelyEvaluatedName extends TokenD private final String n; TokenImmediatelyEvaluatedName (String _n) n = _n;

CS 351 Design of Large Programs, Fall 2003 3 return ask.fortokenimmediatelyevaluatedname (n); class TokenInteger extends TokenD private final Integer i; TokenInteger (Integer _i) i = _i; return ask.fortokeninteger (i); class TokenLeftBrace extends TokenD return ask.fortokenleftbrace (); class TokenLeftBracket extends TokenD return ask.fortokenleftbracket (); class TokenLeftDoubleAngle extends TokenD return ask.fortokenleftdoubleangle (); class TokenLiteralName extends TokenD private final String n; TokenLiteralName (String _n)

CS 351 Design of Large Programs, Fall 2003 4 n = _n; return ask.fortokenliteralname (n); class TokenReal extends TokenD private final Double d; TokenReal (Double _d) d = _d; return ask.fortokenreal (d); class TokenRightBrace extends TokenD return ask.fortokenrightbrace (); class TokenRightBracket extends TokenD return ask.fortokenrightbracket (); class TokenRightDoubleAngle extends TokenD return ask.fortokenrightdoubleangle (); class TokenString extends TokenD private final String s; TokenString (String _s)

CS 351 Design of Large Programs, Fall 2003 5 s = _s; return ask.fortokenstring (s); class TokenToStringV implements TokenVisitorI public Object fortokeninteger (Integer i) return "Integer " + i; public Object fortokenreal (Double d) return "Real " + d; public Object fortokenstring (String s) return "String " + s; public Object fortokenexecutablename (String n) return "ExecutableName " + n; public Object fortokenliteralname (String n) return "LiteralName " + n; public Object fortokenimmediatelyevaluatedname (String n) return "ImmediatelyEvaluatedName " + n; public Object fortokenleftbracket () return "["; public Object fortokenrightbracket () return "]"; public Object fortokenleftbrace () return ""; public Object fortokenrightbrace () return "";

CS 351 Design of Large Programs, Fall 2003 6 public Object fortokenleftdoubleangle () return "<<"; public Object fortokenrightdoubleangle () return ">>"; How to turn in Turn in your code by running barrick/handin your-file on a regular UNM CS machine. You should use whatever filename is appropriate in place of your-file. You can put multiple files on the command line, or even directories. Directories will have their entire contents handed in, so please be sure to clean out any cruft.