1 / 14

Project review: JGibberish

Project review: JGibberish. By: Jake Tenberg & Chelsea Shipp. 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

dewei
Download Presentation

Project review: JGibberish

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. Project review: JGibberish By: Jake Tenberg & Chelsea Shipp

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

  3. Concepts implemented

  4. Concepts implemented (listed) • Token • Terminal • Non-terminal • Lexical analysis • Syntactic analysis • BNF • Parse tree • Abstract syntax • Abstract syntax tree • Interpretation • Substitution • Variables • Static and dynamic scoping • Types • Type system • Static and dynamic typing • Functions • Parameters and arguments • Parameter passing • Activation records • Runtime stack • First-class functions • Recursion

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

  6. 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.

  7. 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

  8. 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

  9. 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

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

  11. Output of runtime stack • Example runtime stack of FirstClassMeows.gib

  12. 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.

  13. 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

  14. 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

More Related