Getting to Know Decaf Goals for Today: Get acquainted with the Decaf language Get experience with ASTs.

Slides:



Advertisements
Similar presentations
Parsing 4 Dr William Harrison Fall 2008
Advertisements

Lesson 6 CDT301 – Compiler Theory, Spring 2011 Teacher: Linus Källberg.
Loops –Do while Do While Reading for this Lecture, L&L, 5.7.
Picture It Very Basic Game Picture Pepper. Original Game import java.util.Scanner; public class Game { public static void main() { Scanner scan=new Scanner(System.in);
AST Generation Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Concepts Lecture 9.
1 JavaCUP JavaCUP (Construct Useful Parser) is a parser generator Produce a parser written in java, itself is also written in Java; There are many parser.
METHOD OVERRIDING Sub class can override the methods defined by the super class. Overridden Methods in the sub classes should have same name, same signature.
SableCC SableCC is developed by professors and graduate students at McGill University and is open source (licensed under the Apache License, Version 2.0)‏
9/27/2006Prof. Hilfinger, Lecture 141 Syntax-Directed Translation Lecture 14 (adapted from slides by R. Bodik)
Parsing Discrete Mathematics and Its Applications Baojian Hua
Abstract Syntax Trees Compiler Baojian Hua
Random (1) Random class contains a method to generate random numbers of integer and double type Note: before using Random class, you should add following.
Chapter 2 A Simple Compiler
Compiler Construction Semantic Analysis I Rina Zviel-Girshin and Ohad Shacham School of Computer Science Tel-Aviv University.
Dr. Philip Cannata 1 Programming Languages. Dr. Philip Cannata 2 10 Java (Object Oriented) ASP RDF (Horn Clause Deduction, Semantic Web) Relation Jython.
Dr. Philip Cannata 1 Programming Languages. Dr. Philip Cannata 2 10 Java (Object Oriented) ACL2 (Propositional Induction) Algorithmic Information Theory.
Concept of Computer Programming November 2, 2011.
ANTLR with ASTs. Abstract Syntax Trees ANTLR can be instructed to produce ASTs for the output of the parser ANTLR uses a prefix notation for representing.
Abstract Syntax Trees Lecture 14 Wed, Mar 3, 2004.
Prof. Bodik CS 164 Lecture 51 Building a Parser I CS164 3:30-5:00 TT 10 Evans.
1 Week 4 Questions / Concerns Comments about Lab1 What’s due: Lab1 check off this week (see schedule) Homework #3 due Wednesday (Define grammar for your.
1 October 1, October 1, 2015October 1, 2015October 1, 2015 Azusa, CA Sheldon X. Liang Ph. D. Computer Science at Azusa Pacific University Azusa.
Java Programming Introduction & Concepts. Introduction to Java Developed at Sun Microsystems by James Gosling in 1991 Object Oriented Free Compiled and.
{ Graphite Grigory Arashkovich, Anuj Khanna, Anirban Gangopadhyay, Michael D’Egidio, Laura Willson.
CISC 471 First Exam Review Game Questions. Overview 1 Draw the standard phases of a compiler for compiling a high level language to machine code, showing.
Interfaces. –An interface describes a set of methods: no constructors no instance variables –The interface must be implemented by some class. 646 java.
COMPILER OVERVIEW. Compiler Phases  Syntactic Analysis (Lexing, Parsing)  c = (a + b) * (a + b);
Compiler Construction Compiler Construction Semantic Analysis I.
Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax.
BUILD ON THE POLYGLOT COMPILER FRAMEWORK MIHAL BRUMBULLI 7th Workshop “SEERE” Montenegro-Risan 9-14 September 2007 SimJ Programming Language.
COMP Parsing 3 of 4 Lectures 23. Using the Scanner Break input into tokens Use Scanner with delimiter: public void parse(String input ) { Scanner.
5-1 5 Compilation  Overview  Compilation phases –syntactic analysis –contextual analysis –code generation  Abstract syntax trees  Case study: Fun language.
Parse & Syntax Trees Syntax & Semantic Errors Mini-Lecture.
Recursive descent parsing 12-Nov-15. Abstract Syntax Trees (ASTs) An AST is a way of representing a computer program It is abstract because it throws.
Prof. Fateman CS 164 Lecture 111 Syntax  Simple Semantics Lecture 11.
Abstract Syntax Trees Compiler Baojian Hua
Introduction Lecture 1 Wed, Jan 12, The Stages of Compilation Lexical analysis. Syntactic analysis. Semantic analysis. Intermediate code generation.
CS412/413 Introduction to Compilers and Translators Spring ’99 Lecture 3: Introduction to Syntactic Analysis.
Overview of Java CSCI 392 Day One. Running C code vs Java code C Source Code C Compiler Object File (machine code) Library Files Linker Executable File.
The assignment expressions. The assignment operator in an assignment statement We have seen the assignment statement: Effect: var = expr; Stores the value.
Compiler Construction Compiler Construction Semantic Analysis I.
Syntax-Directed Definitions and Attribute Evaluation Compiler Design Lecture (02/18/98) Computer Science Rensselaer Polytechnic.
C H A P T E R T W O Linking Syntax And Semantics Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
CPSC 388 – Compiler Design and Construction Parsers – Syntax Directed Translation.
CSC1201: Programming Language 2 1 Functions. 2 Function declaration: return_type FuncName( Type arg1, Type arg2,….. Type argN) { function body } A program.
LECTURE 3 Compiler Phases. COMPILER PHASES Compilation of a program proceeds through a fixed series of phases.  Each phase uses an (intermediate) form.
Print Row Function void PrintRow(float x[ ][4],int i) { int j; for(j=0;j
Syntax-Directed Definitions CS375 Compilers. UT-CS. 1.
Comp 311 Principles of Programming Languages Lecture 2 Syntax Corky Cartwright August 26, 2009.
MiniJava Compiler A multi-back-end JIT compiler of Java.
Open Source Compiler Construction (for the JVM)
Announcements/Reading
Parsing & Context-Free Grammars
Semantic Analysis with Emphasis on Name Analysis
Core Core: Simple prog. language for which you will write an interpreter as your project. First define the Core grammar Next look at the details of how.
Java CUP.
CS 614: Theory and Construction of Compilers
Compiler Construction
Lecture Note Set 1 Thursday 12-May-05
Introduction to Methods in java
4 (c) parsing.
Compiler Designs and Constructions
CPSC 388 – Compiler Design and Construction
Basic Program Analysis: AST
Recursive descent parsing
Syntax-Directed Translation
Bottom-up derivation tree, original grammar
Bottom-up derivation tree, original grammar
CSE401 Introduction to Compiler Construction
Syntax-Directed Translation
Presentation transcript:

Getting to Know Decaf Goals for Today: Get acquainted with the Decaf language Get experience with ASTs

The Decaf Language Activity #1: With a partner: Using the Decaf language specification handout, and comparing with either Java or C++: 1. Create a list of similarities between Decaf and Java/C++ 2. Create a list of differences between Decaf and Java/C++ Be ready to discuss your results, and also turn in your written listings with your names on it at the end of the activity. Timing: 20 minutes – reading and list creation 15 minutes – reporting out – charts on the board, discussion

Abstract Syntax Trees What are they? Give example for some strings of the grammar: E -> E + T | E – T | T T -> T * a | T / a | a

Building an AST during Parsing S -> E{ $$ = $1; root = $$; } E -> E + T{ $$ = makenode( ‘ + ’, $1, $3);} // E is $1, - is $2, T is $3 E -> E - T{ $$ = makenode( ‘ - ’, $1, $3);} E -> T{ $$ = $1;} // $$ is top of stack T -> ( E ){ $$ = $2;} T -> id{ $$ = makeleaf( ‘ idnode ’, $1);} T -> num{ $$ = makeleaf( ‘ numnode ’, $1);} Consider parsing 4 + ( x - y ) state semantic value Parsing Stack S 4 num S

Getting to know the Decaf Compiler AST Representation Consider the Decaf program: void main() { Print("hello world"); }

The Decaf Parser Output Program: 1 FnDecl: (return type) Type: void 1 Identifier: main (body) StmtBlock: PrintStmt: 2 (args) StringConstant: "hello world"

Practice with Decaf ASTs Activity 2: With a partner, draw an AST for the Decaf program using the grammar from the Decaf specification language handout: class Cow { int height; bool isSpotted; void Moo() { Print ( this.height, " ", isSpotted, "\n" ); } void main() { Cow betsy; betsy = New(Cow); betsy.Moo(); }

The Decaf Parser Output Program: 1 ClassDecl: 1 Identifier: Cow 2 VarDecl: Type: int 2 Identifier: height 3 VarDecl: Type: bool 3 Identifier: isSpotted 4 FnDecl: (return type) Type: void 4 Identifier: Moo (body) StmtBlock: PrintStmt: 5 (args) FieldAccess: 5 This: 5 Identifier: height 5 (args) StringConstant: " " 5 (args) FieldAccess: 5 Identifier: isSpotted 5 (args) StringConstant: "\n" 10 FnDecl: (return type) Type: void 10 Identifier: main (body) StmtBlock: 11 VarDecl: 11 NamedType: 11 Identifier: Cow 11 Identifier: betsy 12 AssignExpr: 12 FieldAccess: 12 Identifier: betsy 12 Operator: = 12 NewExpr: 12 NamedType: 12 Identifier: Cow 13 Call: 13 FieldAccess: 13 Identifier: betsy 13 Identifier: Moo