Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

CS 553 Compiler Construction Project 1: Building Scanners, Parsers, and ASTs with SableCC , Study Guides, Projects, Research of Computer Science

In this assignment for the cs 553 compiler construction course, students will learn how to build scanners and parsers using the tool sablecc. The goal is to write the token specifications, concrete syntax grammar, abstract syntax grammar, and conversion from concrete syntax to abstract syntax for the straight-line programming language. Students will also learn about abstract syntax trees, visitors over abstract syntax trees, and visualizing graphs with the dot tool. The report should describe the solution, assumptions, difficulties, insights, and results.

Typology: Study Guides, Projects, Research

Pre 2010

Uploaded on 03/11/2009

koofers-user-6ri
koofers-user-6ri 🇺🇸

2

(1)

10 documents

1 / 3

Toggle sidebar

Related documents


Partial preview of the text

Download CS 553 Compiler Construction Project 1: Building Scanners, Parsers, and ASTs with SableCC and more Study Guides, Projects, Research Computer Science in PDF only on Docsity! CS 553 Compiler Construction — Fall 2006 Project #1 Scanners, Parsers, and ASTs with SableCC Due September 1, 2005 In this assignment you will review or learn how to build scanners and parsers using the tool SableCC. SableCC is also capable of generating an abstract syntax tree with corresponding visitor classes. The goal for this assignment is to write the token specifications, concrete syntax grammar, abstract syntax grammar, and the conversion from the concrete syntax to abstract syntax for the straight-line programming language specified on page 7 in the book. You will do this assignment individually. 1 Motivation The MiniJava compiler that we will be working with for Projects 2 through 4 uses SableCC. The SableCC tool automates a significant amount of the work needed in the front-end of a compiler. This project will help you review lexical analysis and parsing concepts that are typically covered in an undergraduate compilers course. You will also learn about abstract syntax trees, visitors over abstract syntax trees, and how to visualize graphs with the dot tool that is part of Graphviz. 2 The Assignment • Starting with the SampleParser provided in Project 0, create a parser for the straightline programming language specified on page 7 in the Appel book. You will need to create two .scc files. – straightline.scc – straightline-ast.scc The first file should just have the concrete syntax grammar. The second file should have the same concrete syntax grammar, but also include an abstract syntax grammar and a translation from the concrete syntax to the abstract syntax. Keep in mind that abstract syntax grammars can be ambiguous, therefore you can just copy the grammar from page 7. Notice in the sample file that I append all of the non-terminals in the concrete syntax grammar with cst . This helps keep the concrete syntax and the abstract syntax grammars organized. • Use ParserDot.java to create dot files to visualize the difference between the concrete and abstract syntax. You will describe the illustrate and describe the difference in your report. • Create at least two test input programs. Each concrete and abstract syntax node should occur in at least one test file. 1 3 Getting Started 1. Java, jar files, SableCC, and dot are all covered in Project 0. Information about converting from concrete syntax to abstract syntax in SableCC can be found at the following websites: • http://nat.truemesh.com/archives/000531.html • http://sablecc.org/documentation/cst-to-ast.html 2. Review lexing and parsing, especially read the section on ambiguous grammars in Chapter 3 of the Appel book. Keep in mind that SableCC generates LR parsers. The online Bergman Book for Java (http://elvis.rowan.edu/∼bergmann/books.html) includes more examples, see Chapters 3 and 5. 3. Get a copy of the SampleParser discussed in the Project 0 setup notes. Notice that the SampleParser provides a significant head start. There is a main in ParserTest.java and ParserDot.java. You will need ParserDot.java to generate dot files. 4 Your Report The report is an essential part of your completed assignment. Use it to describe your solution, assumptions, difficulties, insights, and results. Organize and present your document as if it were the only basis for your assignment’s grade. The format of your writeup is up to you, but it should minimally answer the following questions: • How did you resolve the ambiguities in the straight-line programming language grammar? Provide references. • Illustrate the difference between the concrete syntax of the straight-line programming lan- guage and the abstract syntax using dot. • Describe the differences between the concrete and abstract syntax. What are the benefits of converting to an abstract syntax? • What problems did you encounter while developing your program? If you knew someone who was just about to start work on this assignment, what advice would you give them? • What, if any, outside sources did you use (e.g., articles, books, other students)? This is particularly important. It’s OK to look at books and articles and speak with your professor and fellow students (although sharing code and working together is strictly forbidden), but as with any scientific document, you should always cite your references and collaborations. You can either cite collaborations in footnotes or in a separate Acknowledgment section. 2
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved