tiny-comp
v1.3.0
Published
A tiny JS/TS compiler written in vanilla TS.
Downloads
14
Readme
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.