Programming Language Principles

Slides:



Advertisements
Similar presentations
Overview of programming in C C is a fast, efficient, flexible programming language Paradigm: C is procedural (like Fortran, Pascal), not object oriented.
Advertisements

AST Generation Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Concepts Lecture 9.
Type Checking, Inference, & Elaboration CS153: Compilers Greg Morrisett.
Chapter 8 ICS 412. Code Generation Final phase of a compiler construction. It generates executable code for a target machine. A compiler may instead generate.
1 Compiler Construction Intermediate Code Generation.
White-Box Testing Techniques IV
School of Computing and Engineering, University of Huddersfield CHA2545: WEEK 14 - SYNTAX LECTURE: ABSTRACT SYNTAX SIMPLE EXAMPLE OF SEMANTICS DEFINITION.
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
XP 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial 10.
Lecture 12 Another loop for repetition The while loop construct © 2007 Daniel Valentine. All rights reserved. Published by Elsevier.
Chapter 3 Program translation1 Chapt. 3 Language Translation Syntax and Semantics Translation phases Formal translation models.
1 Shortcuts for Lazy Programmers! Topics Increment and Decrement Operators Assignment Operators.
C PROGRAMMING LECTURE C-language Computer Fundamentals.
The Stack and Queue Types Lecture 10 Hartmut Kaiser
Shorthand operators.
Attribute Grammars Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 17.
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.
Programming Language Principles Lecture 24 Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Subroutines.
Programming Language Principles Lecture 26 Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Denotational Semantics.
The TINY sample language and it’s compiler
Iteration and Recursion Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 21.
CMP 131 Introduction to Computer Programming Violetta Cavalli-Sforza Week 6, Lecture 1 (Monday)
Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved X1 Chapter 3 Control Statements.
Standardizing RPAL AST’s Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 10.
Writing RPAL Programs Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Concepts Lecture 13.
Winter Compilers Software Eng. Dept. – Ort Braude Compiling Assignments and Expressions Lecturer: Esti Stein brd4.ort.org.il/~esti2.
WHAT IS THE VALUE OF X? x = 0 for value in [3, 41, 12, 9, 74, 15] : if value < 10 : x = x + value print x.
An Attribute Grammar for Tiny Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 18.
Code Generation How to produce intermediate or target code.
Overview of Compilation Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 2.
CSCI 3328 Object Oriented Programming in C# Chapter 4: C# Control Statement – Part I – Exercises 1 Xiang Lian The University of Texas Rio Grande Valley.
Learning Javascript From Mr Saem
Copyright © 2014 Pearson Addison-Wesley. All rights reserved. 4 Simple Flow of Control.
Programming Language Concepts
The Ohio State University
White-Box Testing Techniques IV
COMPILER CONSTRUCTION
CS1022 Computer Programming & Principles
Building AST's for RPAL Programs
An Attribute Grammar for Tiny
Programming Language Principles
Programming Language Concepts
Object-Oriented Programming
CMPE 152: Compiler Design September 11/13 Lab
The Metacircular Evaluator
Lecture 23 Pages : Separating Syntactic Analysis from Execution. We omit many details so you have to read the section in the book. The halting.
CSCI 3328 Object Oriented Programming in C# Chapter 4: C# Control Statement – Part I – Exercises UTPA – Fall 2012 This set of slides is revised from lecture.
The University of Texas – Pan American
The Metacircular Evaluator
Govt. Polytechnic,Dhangar
Programming Language Principles
Compiling Control Statements
3.4 Local Binding Recall Scheme's let: > (let ((x 5)‏ (y 6))
Building AST's for RPAL Programs
Programming Language Principles
Programming Languages
CS 432: Compiler Construction Lecture 11
The RPAL Functional Language
Programming Language Principles
Name Binding and Object Lifetimes
Assignment #3 Programming Language, Spring 2003
Optimizations for the CSE Machine
Relational and Logical Operators
Relational and Logical Operators
EXP file structure.
Lecture 18 Compilers and Language Translation (S&G, ch. 9)
Programming Language Principles
Programming Language Concepts
Intro to Programming (in JavaScript)
Structural Program Development: If, If-Else
Presentation transcript:

Programming Language Principles Extending Tiny Programming Language Principles Lecture 19 Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida

Extending Tiny Let's add a few more constructs to Tiny. The repeat statement (a la Pascal). Code: n: E1 E2 iffalse n

The Repeat Statement (a la Pascal) E → <repeat E E > code () = gen(code (2), "iffalse",next ()) next () = next (2) + 1 top () = top (2) - 1 error () = if type (2)="bool" then error (2) else gen(error (2), "non-bool exp") type () = "statement"

Extending Tiny (cont’d) The one-armed "if". Code: E1 iffalse n E2 n:

The One-Armed "if" E → < if E E > code (2) = gen(code (1), "iffalse",next (2)) next (2) = next (1) + 1 top (2) = top (1) - 1 error (2) = if type (1)="bool" then error (1) else gen(error (1), "non-bool exp") type () = "statement”

Extending Tiny (cont’d) Conditional Expression Code: E1 iffalse n E2 goto m n: E3 m:

Conditional Expression E → < cond E E E > code (2) = gen(code (1), "iffalse",next (2)+1) next (2) = next (1) + 1 top (2) = top (1) - 1 error (2) = if type (1)="bool" then error (1) else gen(error (1), "non-bool exp")

Conditional Expression (cont’d) code (3) = gen(code (2), “goto",next (3)) next (3) = next (2) + 1 error () = if type (2)= type (3) then error (3) else gen(error (3), “type mismatch") top () = top (3) - 1 type () = type (2) ??? type (3) ???

Extending Tiny Prefix auto-increment. Problematic. If x has not been defined, what location do we reserve for it on the stack ? Code: load n lit 1 add save n load n n = lookup(x)

Prefix Auto-Increment E → < ++p ‘<identifier:x>’ > code () = if lookup(x)=0 then code () else gen( gen( gen(code (), "load", lookup(x)), "lit", 1), "add"), "save", lookup(x)), "load", lookup(x))

Prefix Auto-Increment (cont’d) error () = if lookup(x) !=0 then error () else gen(error (), "var undefined") next () = next () + 5 top () = top () + 1 ??? type () = ???

A Sample "Compilation" Using Tiny's AG To save time (and space), we'll track only code, next, top

A Sample "Compilation" Using Tiny's AG (cont’d) Tiny program: program teeny: assign x := read; if x=1 then assign x:=0 else output x end teeny. Code file: read load 1 lit 1 equal iffalse 9 lit 0 save 1 goto 11 print stop.

Programming Language Principles Extending Tiny Programming Language Principles Lecture 19 Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida