Giter VIP home page Giter VIP logo

tiffilore / monkey-business Goto Github PK

View Code? Open in Web Editor NEW
0.0 0.0 0.0 10.63 MB

This repository extends the code from the book "Writing an Interpreter in Go" (https://interpreterbook.com/) by adding to it an interactive environment that offers features for analysing and visualizing the ast and its evaluation process in such a way that it is flexible with regard to changes in the implementation. In addition, there is some material provided that may give rise to changes in the implementation of the interpreter; analysis, documentation and tests.

License: Other

Go 93.96% TeX 6.04%
asts evaluation-trace

monkey-business's People

Contributors

tiffilore avatar

Watchers

 avatar  avatar

monkey-business's Issues

Bugs

The intent is to make the bugs into tests; Fixing them is a later task

To-do-list

  • add virgin monkey code
  • add tests for bugs
  • fix bugs
  • add extended-repl
  • add ast-extension for latex-trees

add test to ast: test the Stringer-function

The Stringer-fct for asts basically mirrors the input - with some brackets for clarification.

In some cases, however, it is not readable any more.

expl:

>> let remainder = fn(x, y) { if(y > 0){let p = (x/y) * y; x - p}}
let remainder = fn(x, y) if(y > 0) let p = ((x / y) * y);(x - p);

more general:

>> if(cond){a;b} 
ifcond ab
>> if(cond){a}; b 
ifcond ab

it's also not always valid Monkey code:

>> let remainder = fn(x, y) { if(y > 0){let p = (x/y) * y; x - p}}
let remainder = fn(x, y) if(y > 0) let p = ((x / y) * y);(x - p);
>> let remainder = fn(x, y) if(y > 0) let p = ((x / y) * y);(x - p);
            __,__
   .--.  .-"     "-.  .--.
  / .. \/  .-. .-.  \/ .. \
 | |  '|  /   Y   \  |'  | |
 | \   \  \ 0 | 0 /  /   / |
  \ '- ,\.-"""""""-./, -' /
   ''-' /_   ^ ^   _\ '-''
       |  \._   _./  |
       \   \ '~' /   /
        '._ '-=-' _.'
           '-----'
Woops! We ran into some monkey business here!

Test (in pseudocode):

let ast1 = result of parsing input
let mirror = ast1.String()
let ast2 = result of parsing mirror

Then we want: ast1 == ast2

Scope considerations

let mod(x,y) = fn(x,y){
   let d = x/y
   let p = d * y
   x-p
}


mod(2,1); r
  • and why does a function point to an environment???

add doc: colorcode

implements expression --> yellow
implements statement --> blue
program --> darker blue

determine command set

  • get rid of set prompt - was only there to play with settings at the beginning
  • make pdfs single [mulit-dimensional] commands, not logging!

add (hidden) settings: indent + showToken

  • "hidden" means that they are not displayed in the help menu
  • indent is just for the indentation of the console ast-trees
  • showToken decides whether the tokens are shown or not
  • mark them as hidden in the code (e.g. at settings)

rewrite repl

  • decide on (initial) command set

  • add infractructure for commands (:command)

  • implement :t <statement> (only shows the type of the object)

    • or t: <expression>
  • implement :<show-tree-command>

  • implement :<show-tree-with-eval>

  • implement :<show environment-history> for last input

  • implement :set historyand :unset history

deal with runtime errors in the repo

since the repo mainly servers to catch runtime-errors, it might be considered to not let the repo crash if the evaluator does, but let it output a message and maybe some stack trace.

  • what do we do with partial side-effects?
    • e.g. if there is an embedded let statement that succeeds before the evaluator crashes?
    • solutions:
      • set environment to empty one
      • before evaluation, save state of environment in a copy

add test to evaluator - condition

environment setup:
let f = fn(){}
let null = if(false){}
let nil = if(true){}

X = {true, false, 5, f, null, nil}

input = setup + if(X){1} else {2}

--> discuss results

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.