Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TuffieLang

WIP interpreter for a dynamic scripting language built using Typescript to play around with lexers and parsers.

Tests

npm run test

Usage

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)

  <ctrl> + 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';

Used by

Contributors

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.