๐ค 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, {...} from "https://deno.land/x/tiny_comp_ts/ts/TinyComp.ts";
โค๏ธ Npm
npm i tiny-comp
import TinyComp, {...} from "tiny-comp";
๐งช 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.