(superscript) Sam Jayasinghe | Tommy Orok | Uday Singh Yu Wang | - - PowerPoint PPT Presentation

superscript
SMART_READER_LITE
LIVE PREVIEW

(superscript) Sam Jayasinghe | Tommy Orok | Uday Singh Yu Wang | - - PowerPoint PPT Presentation

(superscript) Sam Jayasinghe | Tommy Orok | Uday Singh Yu Wang | Michelle Zheng The Question The Answer The Answer Preprocessor Caramel -> Superscript Indentation counting via stack ./preprocessor [file].[extension]


slide-1
SLIDE 1

(superscript)

Sam Jayasinghe | Tommy Orok | Uday Singh Yu Wang | Michelle Zheng

slide-2
SLIDE 2

The Question

slide-3
SLIDE 3

The Answer The Answer

slide-4
SLIDE 4

Preprocessor

  • Caramel -> Superscript
  • Indentation counting via stack
  • ./preprocessor [file].[extension]
  • creates [file].ss
slide-5
SLIDE 5

Lexer

  • /* Comments */
  • ;; terminates expressions
  • int vs. float operators ( + vs +. )
  • Identifiers: start with letter, can contain [0-9] ad _
  • Reserved keywords: fn, if, do, eval
  • Report line & character where Lexer error occurs
slide-6
SLIDE 6

Parser

  • Program: expr list
  • expr:

– atom

  • int, float, boolean, string, empty list
  • identifier

– built-in function identifier

– quoted list

  • eaple:

– s-expression

  • (if a b c)
  • (fn … e
  • unquoted list – function call

– infix expression

  • example: {1 * foo({2 – 3}) + {4 * 5}}
slide-7
SLIDE 7

Parser Error Recovery

  • At error, continue parsing and report multiple errors:

– Missig ;; – Uathed i s-expressions – Function call on inappropriate object, e.g. (true 4);; – Incorrect usage of assignment, e.g. (= 3 4);;

slide-8
SLIDE 8

AST

slide-9
SLIDE 9

Static Type Inference

Type Example int, float, boolean, string 42, ., true, Hello orld unit (prn hello;;

  • : unit

list of sometype true hello;; sometype (head function (fn (x) (+ x 5));;

  • : int -> int

(= foo (fn () (foo)));; /* recursion */ val foo : unit -> 'a type parameter (for let-polymorphism) (fn (x) x);;

  • : a -> a

exception eeptio ide out of ouds;; JavaScript object including external JS libraries

Algorithm W, Hindley-Milner type system

slide-10
SLIDE 10

Built-In Functions

  • arithmetic, comparison, logic, string concatenation
  • cons, head, tail
  • do, eval
  • call, dot, module
  • exception
  • type conversion, e.g. string_of_float
  • type annotation: (inthead
  • type: returns run-time typeof
  • These functions dictate many of the constraints we use in static

type inference.

slide-11
SLIDE 11

Run-Time Type Checking

  • Eval ID a aoids stati tpe iferee
  • For built-in functions in generated JavaScript Code:
-

check arguments number
- check arguments type

  • Ensure that annotated type matches runtime type

– e.g. (int head

  • Throw instructive runtime type errors
slide-12
SLIDE 12

JavaScript Code Generator

slide-13
SLIDE 13

Executor

  • ./geb –s [iput]; or ./geb [filename]
  • Concatenate standard library onto beginning of input
  • Scan and parse input
  • Type-check each expression

– Assign(id, e) -> type check [e], add (id, type) to symbol table

  • Generator translates input to JavaScript

– Writes output to a.js

slide-14
SLIDE 14
  • List manipulation functions

– Examples: length, nth, map, fold_left, reverse, drop, member

  • Printing / stringify functions:

format_[type], stringify_list, print_list

slide-15
SLIDE 15

Testing Engine

slide-16
SLIDE 16

Test Subset

slide-17
SLIDE 17

Demo

slide-18
SLIDE 18

The Future of Superscript