by: jake tenberg chelsea shipp project review: jgibberish

14
By: Jake Tenberg & Chelsea Shipp Project review: JGibberish

Upload: sherilyn-fitzgerald

Post on 19-Jan-2018

242 views

Category:

Documents


0 download

DESCRIPTION

CONCEPTS IMPLEMENTED

TRANSCRIPT

Page 1: BY: JAKE TENBERG  CHELSEA SHIPP PROJECT REVIEW: JGIBBERISH

By: Jake Tenberg & Chelsea Shipp

Project review: JGibberish

Page 2: BY: JAKE TENBERG  CHELSEA SHIPP PROJECT REVIEW: JGIBBERISH

Basic syntax• Types:• Integers: 6, 5• Strings: [HelloWorld]• Functions: <~name,?(param1),body>

• Function call:• @name@

• Variable declaration:• (param1,value)

• Variable reference/call:• #param1#

• Enode and Fnode• Single characters “e” and “f”

• Execution node• ^

Page 3: BY: JAKE TENBERG  CHELSEA SHIPP PROJECT REVIEW: JGIBBERISH

Concepts implemented

Page 4: BY: JAKE TENBERG  CHELSEA SHIPP PROJECT REVIEW: JGIBBERISH

Concepts implemented (listed)

Page 5: BY: JAKE TENBERG  CHELSEA SHIPP PROJECT REVIEW: JGIBBERISH

Project requirements

• Substitution -- ✔• First-class functions -- ✔•Static scoping with dynamic scoping if appropriate -- ✔• Static or dynamic typing -- ✔• Interpretation of an abstract syntax tree -- ✔

Page 6: BY: JAKE TENBERG  CHELSEA SHIPP PROJECT REVIEW: JGIBBERISH

Substitution

• Implemented through use of a variable table.• When a function is called, the old variable table is

pushed onto the runtime stack.• Loop through the function’s parameters and get

the values for those variables from the internal stack. These name and value pairs are put into the variable table.• After the function is run, pop the old variable

table off of the runtime stack.

Page 7: BY: JAKE TENBERG  CHELSEA SHIPP PROJECT REVIEW: JGIBBERISH

First-class functions

• As seen in FirstClassMeows.gib (example file included in the project), functions can be passed as parameters to other functions.• They are handled just like other variables• Pushed onto the internal stack and popped off when

needed

Page 8: BY: JAKE TENBERG  CHELSEA SHIPP PROJECT REVIEW: JGIBBERISH

Static scoping

• Every time a variable is encountered, it is added to the variable table.• When a function is encountered:• Old variable table pushed onto runtime stack• Parameters from the function are substituted with values

popped from the stack• These values are then added/changed in the variable table• After the function finishes executing, the variable table is

replaced with the one popped from the runtime stack• This ensures that the same named variables have

different values in different scopes

Page 9: BY: JAKE TENBERG  CHELSEA SHIPP PROJECT REVIEW: JGIBBERISH

Static/Dynamic typing

• Mainly dynamically typed• We throw exceptions at runtime if things aren’t the type

we want (e.g. value instanceof String)• However, the types are defined when things are

declared (the syntax for declaration)• Strings: enclosed in brackets• Integers: plain numbers• Functions: enclosed in angle brackets with special syntax

distinguishing the name and parameters from the body• In addition, Java is statically typed

Page 10: BY: JAKE TENBERG  CHELSEA SHIPP PROJECT REVIEW: JGIBBERISH

Interpretation of abstract syntax tree

• Example AST of Double.gib (given a number in the program, outputs two times that number)

Page 11: BY: JAKE TENBERG  CHELSEA SHIPP PROJECT REVIEW: JGIBBERISH

Output of runtime stack

• Example runtime stack of FirstClassMeows.gib

Page 12: BY: JAKE TENBERG  CHELSEA SHIPP PROJECT REVIEW: JGIBBERISH

Some example programs

• HelloWorld.gib : simple Hello World program. Good introduction to Gibberish syntax.• FirstClassMeows.gib : uses first-class functions to

output a series of meows.• expGib.gib : uses variables “g” and “v”, which

represent numbers, and compute g^v recursively.• fibGib.gib : gets the given term of the Fibonacci.• scopeGib.gib : shows static scoping! The value of

the variable “a” changes depending on the scope.• It has different values based on which function is being

called.

Page 13: BY: JAKE TENBERG  CHELSEA SHIPP PROJECT REVIEW: JGIBBERISH

Improvements for the future

• Allow more types• Right now we allow Strings, Integers (including multiple

digits), and functions.• Possible inclusions: doubles, booleans, arrays

• Allow the program to pass in parameters• e.g. instead of hardcoding a value to find the Fibonacci

number of, allow the user to pass in a value on the command line.

• SQL commands• We tried to implement a few basic commands

• Better way of implementing errors, rather than just runtime exceptions

Page 14: BY: JAKE TENBERG  CHELSEA SHIPP PROJECT REVIEW: JGIBBERISH

Cool features

• Theoretically infinite instruction sets• Only limited by the size of an integer in java (2^32)• The fifth instruction set is meows!

• We fully implemented the Gibberish language, from scratch• Our implementation has features like static scoping,

variables, and functions that other implementations don’t have

• Optional flags to toggle the following options:• Seeing abstract syntax tree, runtime stack• Not seeing output