Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jyotindersingh/jtok
Java interpreter for a programming language called Tok.
https://github.com/jyotindersingh/jtok
Last synced: about 6 hours ago
JSON representation
Java interpreter for a programming language called Tok.
- Host: GitHub
- URL: https://github.com/jyotindersingh/jtok
- Owner: JyotinderSingh
- Created: 2021-05-22T19:31:47.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-06-05T08:15:36.000Z (over 3 years ago)
- Last Synced: 2023-09-10T13:36:05.596Z (about 1 year ago)
- Language: Java
- Homepage:
- Size: 125 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# jtok
This repository is an effort to build an interpreter for a programming language called **Tok** *(pronounced 'talk')*.
jtok *(pronounced 'jay-talk')* is a Tree-Walk Java interpreter for Tok.
The implementation includes a **REPL** and a **CLI interpreter.**
Head over to the [Documentation](/DOCUMENTATION.md) to see code examples and other language features!
```
jtok architecture
------------
| Parser | <- Front End
------------
v
------------
| AST | <- Representation
------------
v
------------
| Interpreter| <- Execution
------------
```## The Tok Language Spec
The Tok grammar looks something like this, in order of associativity and precedence:
```
program → statement* EOF ;declaration → classDecl
| funDecl
| varDecl
| statement ;classDecl → "class" IDENTIFIER ( "<" IDENTIFIER )?
"{" function* "}" ;
funDecl → "fun" function ;function → IDENTIFIER "(" parameters? ")" block ;
parameters → IDENTIFIER ( "," IDENTIFIER )* ;
varDecl → "var" IDENTIFIER ( "=" expression )? ";" ;statement → exprStmt
| forStmt
| ifStmt
| printStmt
| returnStmt
| whileStmt
| block ;returnStmt → "return" expression? ";" ;
forStmt → "for" "(" ( varDecl | exprStmt | ";" )
expression? ";"
expression? ")" statement ;whileStmt → "while" "(" expression ")" statement ;
ifStmt → "if" "(" expression ")" statement
( "else" statement )? ;block → "{" declaration* "}" ;
exprStmt → expression ";" ;
printStmt → "print" expression ";" ;
expression → assignment ;
assignment → ( call "." )? IDENTIFIER "=" assignment
| logic_or ;
logic_or → logic_and ( "or" logic_and )* ;logic_and → equality ( "and" equality )* ;
equality → comparison ( ( "!=" | "==" ) comparison )* ;
comparison → term ( ( ">" | ">=" | "<" | "<=" ) term )* ;
term → factor ( ( "-" | "+" ) factor )* ;
factor → unary ( ( "/" | "*" ) unary )* ;
unary → ( "!" | "-" ) unary | call ;
call → primary ( "(" arguments? ")" | "." IDENTIFIER )* ;
arguments → expression ( "," expression )* ;
primary → "true" | "false" | "nil" | "this"
| NUMBER | STRING | IDENTIFIER | "(" expression ")"
| "super" "." IDENTIFIER ;```
I started working on this after reading [Bob Nystrom](https://journal.stuffwithstuff.com/) 's book, Crafting
Interpreters.