Project 1 Using Lex and Yacc for Higher Level Abstraction CISC 471 Compiler Design

Similar documents
Hello world. 2. Stack-based Programming. Oscar Nierstrasz

WARNING for Autumn 2004:

Postscript Intro. References. What is Postscript? Hello World! in Ghostscript. CSE 413, Autumn 2005 Programming Languages. Page description language

Informatique Graphique. Traitement de l'information et automatisation. Traitement de l'information et automatisation

Emulation of the setstrokeadjust Operator

Drawing curves automatically: procedures as arguments

Drawing polygons: loops and arrays

Lecture P5: Abstract Data Types

A Short Introduction to PostScript

CS 6353 Compiler Construction Project Assignments

Lab 6: P.S. it s a stack Due 11:59 pm Monday, Mar 31, 2008

Postscript Control Flow

Drawing polygons: loops and arrays

Decaf PP2: Syntax Analysis

References. Topic #15: Postscript Intro. What is Postscript? Hello World! in Ghostscript. Page Description Language. Hello World!

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

CS 6353 Compiler Construction Project Assignments

Timing Techniques. Adobe Developer Support. Technical Note # March Adobe Systems Incorporated

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

Emulation of the execform Operator

Evaluation of postfix

Package epsdice a scalable dice font

CS /534 Compiler Construction University of Massachusetts Lowell

Recognizer/Parser Module

Everything You Wanted to Know About Adobe Acrobat Annotation Handlers But Were Afraid to Ask

Uniface Printing A White Paper by Debbra Mullen

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

Decision Making in C

Structure of a compiler. More detailed overview of compiler front end. Today we ll take a quick look at typical parts of a compiler.

Project 2 Interpreter for Snail. 2 The Snail Programming Language

Additional Guidelines and Suggestions for Project Milestone 1 CS161 Computer Security, Spring 2008

Finish Lec12 TREES, PART 2. Announcements. JavaHyperText topics. Trees, re-implemented. Iterate through data structure 3/7/19

SOFTWARE ARCHITECTURE 4. TEXT FORMATTING SYSTEM

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

Turtle Tango (TT) Language Reference Manual

COLLEGE OF ENGINEERING, NASHIK. LANGUAGE TRANSLATOR

Lexical and Syntax Analysis

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

COMP 412, Fall 2018 Lab 1: A Front End for ILOC

CSSE 304 Assignment #13 (interpreter milestone #1) Updated for Fall, 2018

Compiler Design (40-414)

Compilers and Interpreters

A programming language requires two major definitions A simple one pass compiler

A simple syntax-directed

CS 2210 Programming Project (Part I)

Supporting Device Features

Reader. PDF Writer. PostScript File. Distiller. Control whether or not the Save File As dialog box is displayed.

Color Separation Conventions for PostScript Language Programs

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

CSCI 3155: Lab Assignment 2

IN4305 Engineering project Compiler construction

Text and Graphics. Postcript is a Page Description Language! Paths

Programming Assignment III

All program statements you write should be syntactically correct. Partial credit is not guaranteed with incorrect use of syntax.

TDDD55 - Compilers and Interpreters Lesson 3

MIDTERM EXAM (Solutions)

Control Structures. Lecture 4 COP 3014 Fall September 18, 2017

RYERSON POLYTECHNIC UNIVERSITY DEPARTMENT OF MATH, PHYSICS, AND COMPUTER SCIENCE CPS 710 FINAL EXAM FALL 96 INSTRUCTIONS

Optimizing Finite Automata

1 The Var Shell (vsh)

Yacc: A Syntactic Analysers Generator

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

Properties of Regular Expressions and Finite Automata

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

Crafting a Compiler with C (II) Compiler V. S. Interpreter

Problem Set 1 Due: 11:59pm Wednesday, February 7

INTRODUCTION PRINCIPLES OF PROGRAMMING LANGUAGES. Norbert Zeh Winter Dalhousie University 1/10

CS164: Programming Assignment 2 Dlex Lexer Generator and Decaf Lexer

What is a compiler? Xiaokang Qiu Purdue University. August 21, 2017 ECE 573

What is a compiler? var a var b mov 3 a mov 4 r1 cmpi a r1 jge l_e mov 2 b jmp l_d l_e: mov 3 b l_d: ;done

Minecraft 101. Sandbox game Fighting Survival Building. (Quick demo)

Mandatory Exercise 1 INF3110

Programming Assignment I Due Thursday, October 7, 2010 at 11:59pm

Introduction to Compiler Design

CS 164, Spring 2010 CS 164: Test #1 Solutions P. N. Hilfinger DO NOT. Copyright (c) 2010 by P. N. Hilfinger. Copying and reproduction prohibited.

Stars around I PostScript straightaway

15-110: Principles of Computing, Spring 2018

Compilers. Computer Science 431

Undergraduate Compilers in a Day

Lab copy. Do not remove! Mathematics 152 Spring 1999 Notes on the course calculator. 1. The calculator VC. The web page

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

CS131 Compilers: Programming Assignment 2 Due Tuesday, April 4, 2017 at 11:59pm

4. Semantic Processing and Attributed Grammars

CS1600 Lab Assignment 1 Spring 2016 Due: Feb. 2, 2016 POINTS: 10

Jim Lambers ENERGY 211 / CME 211 Autumn Quarter Programming Project 4

CMPE 152 Compiler Design

CMPE 152 Compiler Design

Compiler I: Syntax Analysis

CS/SE 153 Concepts of Compiler Design

Appendix A: Syntax Diagrams

Stacks and Queues. !stacks!dynamic resizing!queues!generics!applications. Stacks and Queues

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

TPC Desktop Series. Alignments Learning Guide 1/18

Parsing and Pattern Recognition

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

"Digital Media Primer" Yue- Ling Wong, Copyright (c)2011 by Pearson EducaDon, Inc. All rights reserved.

Object-oriented Compiler Construction

CMPSC 111 Introduction to Computer Science I Fall 2016 Lab 8 Assigned: October 26, 2016 Due: November 2, 2016 by 2:30pm

CSE302: Compiler Design

Left to right design 1

Transcription:

Project 1 Using Lex and Yacc for Higher Level Abstraction CISC 471 Compiler Design This is an individual assignment, other than the partner for deliverable D5. You may discuss your ideas with others, but your work should be your own. Deliverables and Deadlines: Th, 2/21 D0: Create an svn repository M, 2/25 D1: Understanding a lex spec F, 2/29 D2: Extending a lex spec to augment the language lexeme set F, 3/7 D3: Understanding a yacc spec M, 3/17 D4: Extending a yacc spec to become a translator F, 3/21 D5: Create test cases to break another person s translator F, 3/28 D6: Test and Refine cycle demo and svn/cvs directory Project Objectives: The student who completes this project should (1) be able to write regular expression specifications for a programming language s lexemes, (2) be able to write context free grammar specifications for a programming language s syntactic elements, (3) be able to construct a scanner and parser that accepts syntactically correct programs and rejects syntactically incorrect programs of a given programming language. Procedure: The major task of this project is to build a software system to translate programs written in a Turtle graphics-like programming language into Postscript. Turtle graphics, part of the LOGO programming language, is based on a relative cursor (the turtle ) moving and drawing on a Cartesian grid. The cursor has three attributes: position, orientation, and pen (which has color, width, up and down on the display), and moves with commands relative to its position. Here is an example of a simple small program in Turtle graphics. // the recursive dragon curve PROCEDURE a(level,dist) { IF (level > 0) THEN { TURN -45; a(level-1,dist); TURN 90; b(level-1,dist); TURN -45; ELSE GO dist; PROCEDURE b(level,dist) { IF (level > 0) THEN { TURN 45; a(level-1,dist); TURN -90; b(level-1,dist); TURN 45;

ELSE GO dist; UP; NORTH; GO 400; EAST; GO 150; DOWN; a(12, 5); This is translated into the following PostScript program, which is perfectly illegible: %!PS-Adobe % generated by the simple turtle program /sinphi 0.0 def /cosphi 1.0 def /state true def /pi 4 1 1 atan mul def newpath 0 0 moveto /turtlea { 20 dict begin /turtledist exch def /turtlelevel exch def turtlelevel 0 gt { 45 neg 180 div pi mul sinphi cosphi atan add dup sin /sinphi exch store cos /cosphi exch store turtlelevel 1 sub turtledist turtlea 90 180 div pi mul sinphi cosphi atan add dup sin /sinphi exch store cos /cosphi exch store turtlelevel 1 sub turtledist turtleb 45 neg 180 div pi mul sinphi cosphi atan add dup sin /sinphi exch store cos /cosphi exch store { turtledist dup cosphi mul exch sinphi mul state {rlineto {rmoveto ifelse ifelse end bind def /turtleb { 20 dict begin /turtledist exch def /turtlelevel exch def turtlelevel 0 gt { 45 180 div pi mul sinphi cosphi atan add dup sin /sinphi exch store cos /cosphi exch store turtlelevel 1 sub turtledist turtlea 90 neg 180 div pi mul sinphi cosphi atan add dup sin /sinphi exch store cos /cosphi exch store turtlelevel 1 sub turtledist turtleb 45 180 div pi mul sinphi cosphi atan add dup sin /sinphi exch store cos /cosphi exch store { turtledist dup cosphi mul exch sinphi mul state {rlineto {rmoveto ifelse ifelse end bind def /state false def /sinphi 1.0 store /cosphi 0.0 store 400 dup cosphi mul exch sinphi mul state {rlineto {rmoveto ifelse /sinphi 0.0 store /cosphi 1.0 store

150 dup cosphi mul exch sinphi mul state {rlineto {rmoveto ifelse /state true def 12 5 turtlea 2 setlinewidth stroke showpage Using a PostScript Viewer such as psviewer or Adobe Acrobatreader, the generated postscript looks like: This project is based on the paper and corresponding project - ``Teaching Compiler Construction and Language Design - Making the Case for Unusual Compiler Projects with PostScript as the Target Language, by Martin Ruckert, Munich University of Applied Sciences, Germany. The overall end deliverable is a working scanner and parser that generate equivalent postscript for a drawing language that you partially design. The final product should accept and translate correctly specified drawing programs, and graciously terminate with an error message for incorrectly specified drawing programs. The files for this project are located on orioles.acad.ece.udel.edu in /usa/pollock/cis471/project1. Deliverables and Assessment: D0: Svn repository. Create yourself an svn repository, and a folder in the svn repository that you will use for this project assignment. See http://www.eecis.udel.edu/wiki/ececisdocs/index.php/faq/subversion for instructions. You should create your own repository, and give me (username pollock) and the TA (username thorpe), access to it. You will doing a manual start/stop on the service, so you give the port# when you start the process, and access the repository on that same port#. We will give our port# s

in class, all above 10000. You will be accessing svn.acad.ece.udel.edu by ssh from orioles. Email Pollock@cis.udel.edu and Thorpe@cis.udel.edu when you have your repository set up with the information for us to access it. D1: Understanding a lex spec Go to the scanning under the project1 directory. Read the lex spec turtle.l, and create an extensive legal test case, and 3 illegal test cases. Name your test case files by yourlastname_legal-lex, yourlastname_ill0-lex, yourlastname_ill1-lex, yourlastname_ill2- lex. Email test cases as one email with attachments to the TA. - Abides by spec on number and naming of test cases - complexity/thoroughness of test cases D2: Extending a lex spec to augment the language lexeme set Design your own variation of the current drawing language, by changing rules to change the names of lexemes to your preferred names, and by adding rules to the lex spec to create a complete turtle-yourname.l spec that includes commands for conditionals, whileloops, procedures with parameters. - extent of change to lexemes to demonstrate knowledge of lex spec - completeness of new spec for new features - correctness of spec in handling correct lexemes - correctness of spec in error handling for illegal lexemes D3: Understanding a yacc spec Read the yacc spec turtle.y and create an extensive syntactically legal test case, and 3 illegal test cases. Name your test case files by yourlastname_legal-syn, yourlastname_ill0-syn, yourlastname_ill1-syn, yourlastname_ill2-syn. Email test cases as one email with attachments to the TA. - Abides by spec on number and naming of test cases - Complexity/thoroughness of test cases D4: Extending a yacc spec to augment the language syntax and postscript generation Design you own variation of the syntax of the current drawing language, by changing the grammar rules and by adding rules to the yacc spec to create a complete turtleyourname.y that includes features for conditionals, while-loops, procedures with parameters. Add actions to your parser to generate the correct postscript. Test your translator on many test files. Be sure to include your test suite with your submission. - completeness of new spec for new features - correctness of spec in handling correct syntax - correctness of spec in error handling for illegal syntax D5: Create test cases in attempt to break another person s scanner/parser

Choose a partner, and on your own, create a test suite with the goal of breaking your partner s translator. This part is graded based on the extensiveness of the test cases. - Complexity/thoroughness of test cases - Success in breaking the software D6: Test and Refine cycle Perform the tests provided by your partner, and refine your translator. Test, refine, test, Your cvs/svn directory of versions and test cases will be the deliverable as well as a scheduled demo with the TA. - Demonstration of revision process using svn/cvs. - Demo of working translator to TA: o Correctness of handling correct programs o Correctness of handling illegal programs o Extensiveness of test suite