BY: JAKE TENBERG CHELSEA SHIPP PROJECT REVIEW: JGIBBERISH.

Post on 19-Jan-2018

242 views 0 download

description

CONCEPTS IMPLEMENTED

Transcript of BY: JAKE TENBERG CHELSEA SHIPP PROJECT REVIEW: JGIBBERISH.

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• ^

Concepts implemented

Concepts implemented (listed)

Project requirements

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

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.

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

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

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

Interpretation of abstract syntax tree

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

Output of runtime stack

• Example runtime stack of FirstClassMeows.gib

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.

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

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