v1.2.0
A tiny JS/TS compiler written in vanilla TS.
Repository
Current version released
3 years ago
π€ TinyCompTS
A tiny (~ 26kb) Javascript/Typescript compiler written in vanilla Typescript as a hobby project.
π¦Ύ Capabilities
- Tokens: Maximum Munch, RegEx matching
- Syntax:
- Recursive descent parser
- β linear time complexity
- β support for LL-Type Context Free Grammars
- Quantifier support (β see example SyntaxRuleset):
?
= zero or one*
= zero or more+
= one or more
- Recursive descent parser
- Semantics: Bottom-up, demand driven evaluation
- β support for arbitrary, non-recursive Attribute Grammars
π Guide
1. Define an attribute grammar
Create an object that implements AttributeGrammar:
- Define a lexical ruleset by creating an object that implements LexicalRuleset
- Define a syntax ruleset by creating an object that implements SyntaxRuleset
- Define a semantic ruleset by creating an object that implements SemanticRuleset
2. Configure TinyComp
- Create an object that implements TinyCompOptions
- Create an instance of TinyComp using the AttributeGrammar and TinyCompOptions object
- Use
compiler.compile(input: string)
to compile input
π Example
β see example.ts
Import
π¦ Denoland
import TinyComp, {AttributeGrammar, LexicalRuleset, SemanticRuleset, SyntaxRuleset, TinyCompOptions}
from "https://deno.land/x/tiny_comp_ts@v1.1.1/ts/TinyComp.ts";
β€οΈ Npm
Coming soon?
π§ͺ Just test
- Install the JS/TS runtime Deno
- Clone this repo & navigate into the root directory
deno run ./example.ts
Alternatively, run via docker
- Clone this repo & navigate into the root directory
docker run -it -v $PWD:/app denoland/deno:1.17.1 run --allow-net /app/example.ts
π¨βπ» Development
Contributing
Feel free to make a pull request if you like. Keep it minimal and efficient.