This is a two part project that allows to create a lexer and a parser (with syntax directed translation) for an arbitrary LL(1) programming language.
MIT License
This is a two part project that allows to create a lexer and a parser (with syntax directed translation) for an arbitrary LL(1) programming language.
You might also be interested in Alia - a compiler and interpreter for my programming language.
Install dependencies:
npm install
Lexer is a Scanner-Generator. It's syntax is based on that of Flex.
Example spec is provided in ./fixtures/lexer.spec
:
Spec file consists of list of rules. Each rule begins with a regular expression.
Second part could be one of:
(SKIP)
- throws out matching text.(ERR)
- emits an error. Error will include token position. An errorTo see available options, run the script with the --help
argument:
./lexer --help
Example call:
./lexer --spec ./fixtures/lexer.spec --input ./fixtures/in.leto --output ./fixtures/out.tokens
Where, ./fixtures/in.leto
is:
1 / (1
+ 4)
This is how resulting token steam looks like (outputted in ./fixtures/out.tokens
):
Syntax-directed translator-generator written in TypeScript.
Implements an LL(1) parser.
To see available options, run the script with the --help
argument:
./parser --help
Example call (using fixtures/out.tokens
generated by lexer in the previous step):
./parser --grammar ./fixtures/parser.spec --tokens ./fixtures/out.tokens --executable fixtures/executable.js
Where ./fixtures/parser.spec
contains the grammar and syntax-directed
translation rules:
The file is split into 3 sections (using %%
as a separator):
Running the parser will generate JavaScript file that, when executed, will print the result of the syntax-directed translation:
node ./fixtures/executable.js
Output:
Calculation: 0.2
You might also be interested in Alia - a compiler and interpreter for my programming language.
Jest is used for unit testing.
You can run it like this:
npm test
Project name comes from Leto Atreides II from the Dune science fiction series.