Stage (Null) Language James Lin, Alex Liu, Daniel Maxson, Andre - - PowerPoint PPT Presentation

stage null language
SMART_READER_LITE
LIVE PREVIEW

Stage (Null) Language James Lin, Alex Liu, Daniel Maxson, Andre - - PowerPoint PPT Presentation

Stage (Null) Language James Lin, Alex Liu, Daniel Maxson, Andre Paiva Motivation START You see a kitten on the street. Take it home Leave it At home, the kitten But it looks so lonely! there mews with hunger. Feed it milk Ignore it


slide-1
SLIDE 1

Stage (Null) Language

James Lin, Alex Liu, Daniel Maxson, Andre Paiva

slide-2
SLIDE 2

Motivation

You see a kitten on the street. At home, the kitten mews with hunger. But it looks so lonely! You monster! You can’t do that! It purrs with satisfaction. Leave it there Take it home Feed it milk Ignore it START

slide-3
SLIDE 3

SNL

is…

  • imperative
  • dynamically typed
  • garbage collected

but not…

  • free-form
  • object-oriented
slide-4
SLIDE 4

SNL

has…

  • int, float, bool, string, and list types
  • stages and a next keyword
  • functions (called “recipes”)

but not…

  • pointers
  • objects or structs
  • for/while loops
slide-5
SLIDE 5

Example: GCD

start main: x is do gcd to 5, 10 do show to x done

stage, variable, and user-defined recipe names assignment recipe application stage and recipe keywords library recipes constants

slide-6
SLIDE 6

recipe gcd to x, y:

Example: GCD

start begin: if x != y (next loop) else (return x) done loop: if x > y (x is x - y) else (y is y - x) next begin done done

slide-7
SLIDE 7

Implementation

.snl file Scanner Parser Analyzer Codegen AST SAST .java files

slide-8
SLIDE 8

Scanning and Parsing

  • Standard ocamllex and ocamlyacc
  • Challenges:

○ Whitespace whitespace everywhere! ○ Creating an unambiguous grammar for a language that looks ambiguous if y > 15.9 (y is y + 7 z is z - 53.8) else (local x is false) if y > 15.9 (y is y + 7 z is z - 53.8)

VS.

slide-9
SLIDE 9

Java Generation

  • Walk SAST and convert each element to a

string that is written to a Java file

  • Challenges

○ Compiling from a dynamically-typed language to a statically-typed language ○ Modularizing Java generation and Java files

  • No IR used, but instead SNLObject, a class

that acts as an abstraction of type in our language

slide-10
SLIDE 10

Tests

  • Exhaustive regression testing suite
  • Interactive testing script

○ Allows for assurance of quality for each compiler component

  • Specific tests for each stage of the compiler
  • Over 50 tests for final compiled code

○ Run compiled Java code and compare with expected output

  • Prevented many subtle errors in the

generation of Java code

slide-11
SLIDE 11

Conclusion

SNL is a simple language designed to teach programming (and we tested this!). Lessons learned:

  • Use github!
  • OCaml is actually AMAZING!
  • Use regression testing!
  • Pair program!
  • Unresolved: To procrastinate or not?