1 / 10

CS 476 – Programming Language Design

CS 476 – Programming Language Design. William Mansky. Structure of a Language. Syntax Abstract – what are the pieces of a program? Concrete – what do programs look like? Semantics Static – what are acceptable programs? Dynamic – what do programs do when we run them? Pragmatics

jvernon
Download Presentation

CS 476 – Programming Language Design

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS 476 – Programming Language Design William Mansky

  2. Structure of a Language • Syntax • Abstract – what are the pieces of a program? • Concrete – what do programs look like? • Semantics • Static – what are acceptable programs? • Dynamic – what do programs do when we run them? • Pragmatics • Implementation – how can we actually make the semantics happen? • IDE, tool support, etc.

  3. Context-Free Grammars • Terminals: a, b, c, +, *, (, … • Nonterminals: A, B, C, … • Productions: A -> aAc | B | ef

  4. BNF Grammars • A convenient notation for context-free grammars A ::= a | aA B ::= b | bB S ::= A | B | (S) | SS

  5. BNF Grammars • A convenient notation for context-free grammars …that looks a lot like a datatype! A ::= a | aA B ::= b | bB S ::= A | B | (S) | SS type S = cA of A | cB of B | cParen of S | c2 of S * S

  6. BNF Grammars for Syntax E ::= <#> | E + E | E – E | E * E | – E type_E = cInt of int | cAdd of type_E * type_E | … C ::= <var> = E | if E then C else C | C; C | while(E) C type_C = cIf of type_E * type_C * type_C | …

  7. Notes on tuples f (x, y) = x + y (1, 2) : int * int int * int * int = int * (int * int) let fst x = match x with (a, b) -> a let snd x = match x with (a, b) -> b let third x = match (a, b, c, d) -> c

  8. BNF Grammars for Syntax (example)

  9. Abstract Syntax Trees E ::= <#> | E + E | E – E | E * E | – E E + + E E 3 * E 9 E 5 3 * Add(Int 3, Mul (Int 5, Int 9)) 9 5

  10. Abstract Syntax Trees (example)

More Related