Programming Language Concepts

Slides:



Advertisements
Similar presentations
Switch code for Lab 4.2 switch (input) { /* input is a variable that we will test. */ case 'M': printf("The prefix is equal to 1E6.\n"); break; case 'k':
Advertisements

Overview of programming in C C is a fast, efficient, flexible programming language Paradigm: C is procedural (like Fortran, Pascal), not object oriented.
Prepared by Abdullah Mueen and Eamonn Keogh
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.
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.
Chapter 2: Design of Algorithms
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.
Shorthand operators.
Attribute Grammars Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 17.
Hello World 2 What does all that mean?.
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 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.
By Chad Blankenbeker.  The for-loop is best used when you know how many times it is going to be looped  So if you know you want it to only loop 10 times,
CMP 131 Introduction to Computer Programming Violetta Cavalli-Sforza Week 6, Lecture 1 (Monday)
CS 153: Concepts of Compiler Design September 16 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved X1 Chapter 3 Control Statements.
Week 6(10.7): The TINY sample language and it ’ s compiler The TINY + extension of TINY Week 7 and 8(10.14 and 10.21): The lexical of TINY + Implement.
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.
Program Development C# Programming January 30, 2007 Professor J. Sciame.
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.
Atholton High School Columbia, Maryland Nifty Assignments: Mighty Cabbage Patch Micro.
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
IST 210: PHP Logic IST 210: Organization of Data IST2101.
 Type Called bool  Bool has only two possible values: True and False.
1 Outline Review Introduction to LISP Symbols and Numbers Lists Writing LISP Functions LISPWorks.
Copyright © 2014 Pearson Addison-Wesley. All rights reserved. 4 Simple Flow of Control.
Programming Language Concepts
Building AST's for RPAL Programs
6.001 SICP Compilation Context: special purpose vs. universal machines
Overview of Compilation The Compiler BACK End
An Attribute Grammar for Tiny
Introduction to C Programming Language
Programming Language Principles
Software Programming J. Holvikivi 2014.
Object-Oriented Programming
CMPE 152: Compiler Design September 11/13 Lab
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 Language Principles
CMPE 152: Compiler Design February 21/26 Lab
Assignment #3 Programming Language, Spring 2003
Optimizations for the CSE Machine
Relational and Logical Operators
Relational and Logical Operators
EXP file structure.
Programming Language Principles
Programming Language Concepts
Intro to Programming (in JavaScript)
Presentation transcript:

Programming Language Concepts Extending Tiny Programming Language Concepts 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 Concepts Extending Tiny Programming Language Concepts Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida