https://github.com/schachte/tartufo
Experimental interpreter written in Typescript
https://github.com/schachte/tartufo
interpreter language programing programming-languages typescript typescript-interpreter
Last synced: over 1 year ago
JSON representation
Experimental interpreter written in Typescript
- Host: GitHub
- URL: https://github.com/schachte/tartufo
- Owner: Schachte
- Created: 2024-04-08T03:23:12.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2024-04-24T03:45:35.000Z (about 2 years ago)
- Last Synced: 2025-01-14T13:37:17.664Z (over 1 year ago)
- Topics: interpreter, language, programing, programming-languages, typescript, typescript-interpreter
- Language: TypeScript
- Homepage: https://ryan-schachte.com
- Size: 79.1 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# TuffieLang
WIP interpreter for a dynamic scripting language built using Typescript to play around with lexers and parsers.
## Tests
`npm run test`
## Usage
```ts
import { Lexer } from "./lexer";
import { Parser } from "./parser";
const sourceCode = `
let hello = 2;
let test = 'sup';
`;
const lexer = new Lexer(sourceCode);
const tokens = lexer.tokenize();
const parser = new Parser(tokens);
const program = parser.parse();
for (const node of program.body) {
console.log(
`AST: ${JSON.stringify(node, null, 2)}\nSerialized output: ${
node.debug && node.debug()
}\n`
);
}
```
## REPL Demo
```
──────▄▀▄─────▄▀▄
─────▄█░░▀▀▀▀▀░░█▄
─▄▄──█░░░░░░░░░░░█──▄▄
█▄▄█─█░░▀░░┬░░▀░░█─█▄▄█
-----------------------
-- TUFFIE LANG --
-----------------------
(Interactive REPL v1.0)
+ c to exit
🐈 > let dat=6+6*2/9;
{
variables: [
{
dat: 7.333333333333333
}
]
}
```
## Output
```
AST: {
"type": "LetStatement",
"identifier": "hello",
"expression": {
"type": "NumberExpression",
"literal": 2
}
}
Serialized output: let hello = 2;
AST: {
"type": "LetStatement",
"identifier": "test",
"expression": {
"type": "StringExpression",
"literal": "sup"
}
}
Serialized output: let test = 'sup';
```