Code Monkey home page Code Monkey logo

interpreter's Introduction

Interpreter for Gavagai

An interpreter for an imperative programming language, called Gavagai, I designed for fun and exploration.

Instructions to run

Must install Haskell Stack first (refer to https://docs.haskellstack.org/en/stable/README/)

source buildScript.sh to build the interpreter.
gavagai <source_filename>.txt to interpret a program.

Grammar

prog ::= (expr ";")*
expr ::= "!" expr | "-" expr | "+" expr
       | expr "*" expr | expr "/" expr
       | expr "+" expr | expr "-" expr
       | expr "<" expr | expr "<=" expr | expr ">" expr | expr ">=" expr
       | expr "==" expr | expr "!=" expr
       | expr "&&" expr
       | expr "||" expr
       | term
term ::= func
       | define
       | lit
       | block
       | "(" expr ")"
       | cond
       | loop
       | input
       | print
       | call
       | array_mod
       | array_access
       | assign
       | var
func ::= type ident "(" params ")" expr
define ::= type ident "=" expr
lit ::= integer | float | character | boolean | array | string | null
block ::= "{" (expr ";")+ "}"
cond ::= "if" "(" expr ")" expr "else" expr
loop ::= "while" "(" expr ")" expr
input ::= "input" type
print ::= "print" "(" args ")"
call ::= ident "(" args ")"
array_mod ::= ident "[" expr "->" expr "]"
array_access ::= ident "[" expr "]"
assign ::= ident "=" expr
var ::= ident
integer ::= \d+
float ::= \d+\.\d+
character ::= "'" [^'] "'"
boolean ::= "true" | "false"
array ::= "[" ( (lit ("," lit)*) | <empty> ) "]"
string ::= "\"" [^"]* "\""
null ::= "null"
ident ::= [_a-zA-Z][_a-zA-Z0-9]*
type ::= "int" | "float" | "char" | "bool" | "ints" | "floats" | "chars" | "bools" | "void"
params ::= ( type ident ("," type ident)* ) | <empty>
args ::= ( expr ("," expr)* ) | <empty>

interpreter's People

Contributors

jchenche avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

archaephyrryx

interpreter's Issues

Improvement TODOs

Things to do to make the codebase better:

  • Merge two ASTs into one AST.
  • Leverage the type-checker more (lot of pattern-matching cases are duplicated in type-checking and evaluation).
  • Add unit and e2e tests.
  • Enable multi-dimensional arrays.
  • Add lines for errors.
  • Add example code for documentation.
  • Add typing rules and formal semantics.

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.