CS2112 Fall Assignment 4 Parsing and Fault Injection. Due: March 18, 2014 Overview draft due: March 14, 2014

Similar documents
CS4120/4121/5120/5121 Spring /6 Programming Assignment 4

Intro. Scheme Basics. scm> 5 5. scm>

Question Points Score

Grammars & Parsing. Lecture 12 CS 2112 Fall 2018

Optimizing Finite Automata

(Provisional) Lecture 22: Rackette Overview, Binary Tree Analysis 10:00 AM, Oct 27, 2017

Introduction to Syntax Analysis Recursive-Descent Parsing

Grammars and Parsing, second week

CSE P 501 Compilers. Parsing & Context-Free Grammars Hal Perkins Spring UW CSE P 501 Spring 2018 C-1

ASTs, Objective CAML, and Ocamlyacc

Derivations vs Parses. Example. Parse Tree. Ambiguity. Different Parse Trees. Context Free Grammars 9/18/2012

Parsing II Top-down parsing. Comp 412

CSCI 3155: Lab Assignment 6

CS152 Programming Language Paradigms Prof. Tom Austin, Fall Syntax & Semantics, and Language Design Criteria

Lecture 1: Overview

CSE 12 Abstract Syntax Trees

Parsing. Note by Baris Aktemur: Our slides are adapted from Cooper and Torczon s slides that they prepared for COMP 412 at Rice.

PRINCIPLES OF COMPILER DESIGN UNIT I INTRODUCTION TO COMPILERS

Compilers. Prerequisites

A clarification on terminology: Recognizer: accepts or rejects strings in a language. Parser: recognizes and generates parse trees (imminent topic)

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

Context-Free Grammar. Concepts Introduced in Chapter 2. Parse Trees. Example Grammar and Derivation

CS558 Programming Languages

CS 314 Principles of Programming Languages

If you are going to form a group for A2, please do it before tomorrow (Friday) noon GRAMMARS & PARSING. Lecture 8 CS2110 Spring 2014

CSCI 3155: Lab Assignment 2

CSE 3302 Programming Languages Lecture 2: Syntax

CS153: Compilers Lecture 1: Introduction

A Simple Syntax-Directed Translator

Announcements. Written Assignment 1 out, due Friday, July 6th at 5PM.

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division

CS164: Programming Assignment 2 Dlex Lexer Generator and Decaf Lexer

Chapter 4. Abstract Syntax

MIDTERM EXAMINATION - CS130 - Spring 2003

Control Flow. COMS W1007 Introduction to Computer Science. Christopher Conway 3 June 2003

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

1 Lexical Considerations

CSE 401 Midterm Exam Sample Solution 2/11/15

Class Information ANNOUCEMENTS

Project Compiler. CS031 TA Help Session November 28, 2011

CSE 413 Languages & Implementation. Hal Perkins Winter 2019 Structs, Implementing Languages (credits: Dan Grossman, CSE 341)

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming

EDAN65: Compilers, Lecture 04 Grammar transformations: Eliminating ambiguities, adapting to LL parsing. Görel Hedin Revised:

Syntax Analysis Check syntax and construct abstract syntax tree

Announcements. Application of Recursion. Motivation. A Grammar. A Recursive Grammar. Grammars and Parsing

Programming II (CS300)

CSE 401/M501 18au Midterm Exam 11/2/18. Name ID #

CS164: Midterm I. Fall 2003

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

Exercises: Instructions and Advice

CSE P 501 Compilers. Parsing & Context-Free Grammars Hal Perkins Winter /15/ Hal Perkins & UW CSE C-1

Important Project Dates

CSCI 3155: Lab Assignment 2

UNIVERSITY OF CALIFORNIA

School of Computer Science CPS109 Course Notes 5 Alexander Ferworn Updated Fall 15

Programming Assignment III

There are many other applications like constructing the expression tree from the postorder expression. I leave you with an idea as how to do it.

Project 1: Scheme Pretty-Printer

Compilers and computer architecture From strings to ASTs (2): context free grammars

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

COMP 181 Compilers. Administrative. Last time. Prelude. Compilation strategy. Translation strategy. Lecture 2 Overview

CSCE 314 Programming Languages

Properties of Regular Expressions and Finite Automata

This course supports the assessment for Scripting and Programming Applications. The course covers 4 competencies and represents 4 competency units.

Lecture Notes on Shift-Reduce Parsing

Stating the obvious, people and computers do not speak the same language.

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

EECS 311: Data Structures and Data Management Program 1 Assigned: 10/21/10 Checkpoint: 11/2/10; Due: 11/9/10

Parsing III. (Top-down parsing: recursive descent & LL(1) )

CSCI 3155: Lab Assignment 6

Parsing Techniques. CS152. Chris Pollett. Sep. 24, 2008.

Comp 411 Principles of Programming Languages Lecture 3 Parsing. Corky Cartwright January 11, 2019

Lecture 14: Parser Conflicts, Using Ambiguity, Error Recovery. Last modified: Mon Feb 23 10:05: CS164: Lecture #14 1

TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA

Programming Assignment 2 LALR Parsing and Building ASTs

CS 132 Compiler Construction

CSCI312 Principles of Programming Languages!

Lab 3. A Multi-Message Reader

CS 330 Homework Comma-Separated Expression

CPSC 411, 2015W Term 2 Midterm Exam Date: February 25, 2016; Instructor: Ron Garcia

First-Order Translation Checklist

Introduction to Parsing. Lecture 5

CMSC 330: Organization of Programming Languages

Review main idea syntax-directed evaluation and translation. Recall syntax-directed interpretation in recursive descent parsers

Lesson 1A - First Java Program HELLO WORLD With DEBUGGING examples. By John B. Owen All rights reserved 2011, revised 2015

EECS 6083 Intro to Parsing Context Free Grammars

CS558 Programming Languages

Introduction to Parsing. Lecture 5

Functional abstraction. What is abstraction? Eating apples. Readings: HtDP, sections Language level: Intermediate Student With Lambda

Functional abstraction

CSCI312 Principles of Programming Languages

Lecture 02, Fall 2018 Friday September 7

Computing and compilers

ADTS, GRAMMARS, PARSING, TREE TRAVERSALS. Regrades 10/6/15. Prelim 1. Prelim 1. Expression trees. Pointers to material

Homework 6. What To Turn In. Reading. Problems. Handout 15 CSCI 334: Spring, 2017

Introduction to Compilers and Language Design

2.2 Syntax Definition

CTI-TC Working Session

Compiler construction

Action Table for CSX-Lite. LALR Parser Driver. Example of LALR(1) Parsing. GoTo Table for CSX-Lite

Transcription:

CS2112 Fall 2014 Assignment 4 Parsing and Fault Injection Due: March 18, 2014 Overview draft due: March 14, 2014 Compilers and bug-finding systems operate on source code to produce compiled code and lists of possible bugs detected. This software needs a lot of test cases, and test cases which are programs are expensive to generate. Fault injection is a technique for inexpensively generating such test cases. The idea is to take a valid program and make small random changes to it to produce many useful test cases. For testing a compiler, we want both test cases that are valid programs in the programming language, and also test cases that are invalid programs (however, you will only produce valid programs in this assignment). For bug finders, the test cases are valid programs that contain bugs. In this assignment, you will be building the latter kind of fault injector, in which a valid program is changed into another valid program. You will use fault injection on programs to implement mutations on the behavior of a simulated critter. In this assignment, you will also build a parser for a simple language and a pretty-printer that can print out parsed programs in a nicely formatted form. 0 Changes Fixed parse tree example diagram to match grammar (3/16) Added explicit overview draft due date (3/13) The source code (Token.java, Tokenizer.java) was updated with support for the serve token. (3/10) 1 Instructions 1.1 Group Project This assignment is the first part of the group project for the course. The programming language you will be parsing, pretty-printing, and injecting faults into will be the language controlling simulated creatures. You will need to read the CritterWorld Project Specification to find out more about the final project and the language you will be working with in this assignment. The faults that are being injected are those corresponding to the mutations in Section 10 of the project specification. CS2112 Spring 2014 1/7 Assignment 4

1.2 Partners You will work in a group of two students for this assignment. Obviously, it is important that you find your partner very soon. Piazza has support for finding a partner. 1.3 Overview Document Starting with this assignment, we expect your group to submit an overview document. You will want to read the Overview Document Specification to learn what we are expecting. Writing a clear document with good use of language is important. We are requiring you to submit an early draft of your design overview document on Friday before the assignment is due. You may not be able to predict what your design and testing strategy will look like in full at that point, but we want to see how far you have gotten. We will aim to give you quick feedback on this draft. 1.4 Version Control One of the key learning goals for this project is how to work with a partner effectively. As such, we would like you to use version control in managing your partnership. You may choose to use any system you like - common industry standards include Git, Subversion, and Mercurial. One or more of these systems will be covered in lab. You must submit along with your project a file called log.txt which shows us your commits from your time together with your partner. Don t think of this as extra work. While it may require some learning, you will reap the benefits as you delve further into this and upcoming projects. Furthermore, it is a valuable skill to have, as any large piece of modern software is always managed with version control. 1.5 Restrictions You may use any standard Java libraries from the Java SDK. However, you may not use a parser generator. 2 Parsing 2.1 Overview Parsing involves converting an input sequence of text, such as a program, into a tree structure according to a grammar. The Java compiler, for example, is a parser that converts programs you write into an executable form. You will apply this same idea to parse a program written in a critter language into an internal abstract syntax tree representation that your program can understand, execute, and modify. The grammar for the language you will be parsing is given in the project specification. The grammar describes the concrete syntax of critter programs, including all the tokens that are part of the input. CS2112 Spring 2014 2/7 Assignment 4

+ expr 2 * term + term 3 4 factor factor number(2) ( expr ) BinaryOp(+) term Num(2) Num(3) BinaryOp(*) Num(4) factor * factor number(3) number(4) abstract syntax tree parse tree Figure 1: Abstract and concrete syntax trees for 2+(3*4) However, the job of the parser is not construct the concrete syntax tree; instead, it should build an abstract syntax tree. 2.2 Abstract Syntax Trees An abstract syntax tree (AST) represents the syntax of some input while avoiding representing parts of the syntax that do not affect the meaning of the input. For example, the expressions (2+3*4), 2+(3*4), and (2) + (3)*(4) all would have the same abstract syntax tree, because the parentheses are only there to guide the construction of the tree. Figure 1 shows this abstract syntax tree, along with the concrete syntax tree (parse tree) for 2+(3*4). The AST is shown on the left in two different forms: the top represents how we might think of the AST, while the bottom corresponds more closely to the code, and uses some of the classes we have supplied to you for use in AST construction. Because the tree structure implicitly represents many syntax details, it omits any syntax that is unnecessary. This is what makes it different from a concrete syntax tree or a parse tree, which include all syntax included in a program. This distinction will become critically important when you implement fault injection. Fault injection will be much more difficult if your abstract syntax tree has concrete parse tree nodes such as parentheses in it, or nonterminals that exist only to represent different levels of precedence. CS2112 Spring 2014 3/7 Assignment 4

You will need to design and implement a class hierarchy to represent this tree, in which the leaves are subclasses of Node. By giving Node the right methods, it will be possible to recursively implement various useful functionality, including fault injection and in a later assignment, evaluation. 2.3 Provided Classes We have provided an implementation of a Tokenizer as well as interfaces and some classes to get you started with defining your AST. You may not need to use all of these but you will probably need to add more. 3 Fault Injection Since we are using fault injection to simulate a genome mutation for a critter, see the project specification for how this mutation is to be done. The key to correct fault injection is that for this project, it will mutate a program in such a way that the resulting program is still a legal critter program, though it does not, perhaps, do what it was originally intended to do. There is some flexibility in how to interpret the mutation rules given in the project specification. You should identify any ambiguities you see and explain how you have resolved them. One rule of thumb is that it should be possible, though some sequence of mutations, to change any program into any other program. There are many different kinds of nodes in the AST, so implementing mutation for each of them could involve a lot of tedious code and opportunities for mistakes. Think about how to abstract the various kind of mutations so that you can share mutation code across multiple node types. Can you create a common framework so that most mutation types can be implemented in a common way, rather than creating complex logic specific to each combination of node type and mutation type? The supplied code suggests some method signatures that might be useful starting points, but you can change them. You have a lot of flexibility about how to implement this. 4 Pretty-Printing You should be able to print out programs in the same syntax they were written in, meaning that the programs you print would generate the same abstract syntax tree if you were to parse them again. Pretty-printing should make use of indentation (though not the ASCII tab character!) and line breaks in order to make output readable and, well, pretty. 5 User Interface Your program must be able to be run from the command line as follows: CS2112 Spring 2014 4/7 Assignment 4

java -jar <your jar> <input file> parse the file input file as a critter program and pretty-print the the program to standard output. java -jar <your jar> --mutate <n> <input file> parse the file input file as a critter program and apply n mutations. After each mutation, print a description of the kind of mutation that has been applied and pretty-print the program. 6 Overview of Programming Tasks Because you will want to figure out with your partner how to break up the work involved in this assignment, it is good to start thinking about some of the major tasks involved: Implementing the main program and command-line handling. Designing and implementing a class hierarchy of classes for representing abstract syntax trees. These will be subclasses of Node. We have given you a start on some of these classes, but you will likely need to add more. Implementing the Parser class to generate abstract syntax trees. Implementing pretty-printing functionality, as methods on AST nodes. Implementing a class or classes to perform fault injection. It is up to you to design the interfaces for these classes. CS2112 Spring 2014 5/7 Assignment 4

7 Written problem Recall that a function f(n) is O(g(n)) if there exist constants k and n 0 such that for all n n 0, f(n) kg(n). The constants k and n 0 together are a witness to the fact that f(n) is O(g(n)). For each of the following functions, show by giving a witness that it is O(n 2 ), or else show that it isn t O(n 2 ) by arguing that no such witness can exist. 3n 2 + 10n + 1 2 n n lg n n 3 / lg n f(n) + h(n), where each of f(n) and h(n) are O(n 2 ). 8 Submission You should compress exactly these files into a zip file that you will then submit on CMS: Source code: You should include all source code required to compile and run the project. Tests: You should include code for all your test cases. overview.txt/html/pdf: This file should contain your overview document. log.txt: A dump of your commit log from the version control system of your choice. Do not include any files ending in.class. You should also separately submit your work on the written problems in written-problems.txt (.doc and.pdf also permitted). 9 Tips The key to success on this assignment will be for both partners to contribute effectively. However, working with a partner may be challenging. Some tips: Meet with your partner as early as possible to work out the design and to divide up the responsibilities for the assignment. Keep meeting and talking as the project progresses. Be prepared for your meetings. Be ready to present proposals to your partner for what to do, and to explain the work you have done. The way to partition an assignment into parts that can be worked on separately is to first agree on what the different modules will be, and further, exactly what their interfaces are, including detailed specs. CS2112 Spring 2014 6/7 Assignment 4

Drop by office hours and explain your design to a member of course staff as early as possible. This will help you avoid big design errors that will cost you as you try to implement. This project is a great opportunity to try out pair programming, in which you program in a pilot/copilot mode. It can be more fun. It also tends to result in fewer bugs. A key ingredient is to give the person typing the job of convincing the other person that the code meets the spec. Of course, you need to agree on a spec first. It will be tempting to let the person who is more confident about how to implement the code the pilot/typist role; you will probably be more successful if you do the reverse. This project is also a great time to start doing code reviews with your partner. Walk through your code and explain to your partner what you ve done, and convince your partner your design is good. Be ready to give and to accept constructive criticism! Sometimes people feel that they are working much harder than their partner. Remember that when you go to implement something, it tends to take about twice aas long as you thought it would. So what your partner is doing is also twice as hard as it looks. If you think you are working twice as hard as your partner, you re probably about even! As usual, we encourage you to read all Piazza posts because often your questions have already been asked by someone else even before it occurs to you to ask. You will save a lot of time this way. CS2112 Spring 2014 7/7 Assignment 4