Download presentation
Presentation is loading. Please wait.
1
CPSC 311: Definitions of Programming Languages
Instructor: Steven Wolfman (and this is one of the only sets of slides you'll see all term!) Welcome to CPSC 311, where we'll metaphorically dig our hands into the metaphorical guts of programming languages! But first, what's the most common security flaw in a program?
2
Digression: Security Once upon a time...
...buffer overflows were the most common security vulnerability in programs. Can you overflow an array in Java? If yes: how? If no: why not? Image from Wikipedia article on buffer overflows.
3
Digression: Security And now...
...cross-site scripting (a type of code injection, not in SQL and less funny) vulnerabilities are the most common security vulnerability in programs. How should we protect against these? xkcd.org Facebook was running into these kinds of problems and other related straightforward bugs. Show example from FaceBook talk. Turns code like: $div = '<div id="console" class="consoleLog">'. htmlspecialchars($logEntry). '</div>'; Into code more like: <div id="console" class="consoleLog"> {$logEntry} </div>; Facebook XHP (among other things)
4
Outline Why should you care about this course?
How will this course work? Why Racket? How are Scheme and Racket related? Why Scheme/Racket? Start learning Racket
5
Why should you care about this course?
Programming languages are the key tools that define how we think about computations, and what we're able to create. What you learn during this course will give you the power to learn, choose, and craft your tools effectively.
6
How would you draw this picture ...
... using a computer? Source Code Compiler Object Code (Running example from “Little Languages” by Jon Bentley.)
7
Which way is better? Slideware, graphics library, or... Source Code
Compiler Object Code Describe using the PIC language, and compile: ellipse “Source” “Code” arrow box “Compiler” ellipse “Object” “Code” PIC is a “domain specific” language for describing pictures.
8
Which way is better? What if the picture you wanted to draw looks like this ?
9
Which way is better? What if the picture you wanted to draw looks like this ? PIC description of this picture: pi = ; n = 10; r = .5 s = 2*pi/n for i = 1 to n-1 do { for j = i + 1 to n do { line from r*cos(s*i), r*sin(s*i) to r*cos(s*j), r*sin(s*j) }
10
Which way is better? A C program that draws the same picture:
#include “graphics.h” // A graphics library main() { double pi = ; int n = 10; double r = 0.5; double s = 2*pi/n; for (int i = 1; i<=n-1; i++) for j = i + 1; j<=n; j++) line(r*cos(s*i), r*sin(s*i), r*cos(s*j), r*sin(s*j) ); }
11
Three Ways to Describe a Picture
Use a Picture Drawing program like PowerPoint. Use a Special “Domain Specific” Picture Language Use a General Purpose Programming Language and a “Graphics Library”. Which is “best” under what circumstances and why?
12
Another example... What if the picture you wanted to draw looks like this ?
13
The CHEM Language CHEM = “Molecule Picture” Language
special constructs for this specific purpose compiled to PIC code Excerpt from picture's CHEM description: R1: ring4 pointing 45 put N at 2 doublebond -135 from R1.V3 ; O backbond up from R1.V1 ; H frontbond -45 from R1.V4; N H above N bond left from N ; C ...
14
How PIC is Implemented PIC input TROFF PostScript Lexical Analysis
Syntax Analysis Code Generation TROFF Print PostScript
15
How PIC is Implemented “Little” Languages Everywhere! PIC input
PIC Language Lexical Analysis Syntax Analysis Code Generation TROFF TROFF Language Print PostScript PostScript Language
16
How PIC is Implemented “Little” Languages Everywhere! PIC input
PIC Language Lexical Analysis Lexer C Code LEX Tool Lex input Lex Language Syntax Analysis Compile Parser C Code YACC Tool Yacc input Yacc Language Code Generation Code Gen C Code TROFF TROFF Language Print PostScript PostScript Language
17
Outline Why should you care about this course?
How will this course work? Why Racket? How are Scheme and Racket related? Why Scheme/Racket? Start learning Racket
18
Definition of Programming Languages
We'll study programming languages: how they work how they let us say the things they let us say what different design features languages can have how those features fit together
19
Approach 1. Play with programs that exploit some language design choice. 2. Deeply explore the choice by building an interpreter that executes the language (defining an “interpreter semantics”). 3. Ask questions like: How would programmers perceive/use these design choices differently? How are they defined differently in the interpreter? 4. Tinker with the language and interpreter. And.. repeat!
20
Outline Why should you care about this course?
How will this course work? Why Racket? How are Scheme and Racket related? Why Scheme/Racket? Start learning Racket
21
Racket's plai module plai is a module (a “#lang option”) in Racket that supports several useful structures for building interpreters. Racket is a rich and flexible (and compatible) extension of Scheme. Scheme is a simple, elegant, yet extremely powerful language uniquely suited to “interpreter semantics”. So we have to learn plai. Let's get started!
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.