npm run build
Runsnpx turbo build-src build-bins
npx turbo test
Runs all testsnpx turbo coverage
Runs all tests with coverage
npx turbo typecheck
Typecheck codenpx turbo lint
Runs eslintnpx turbo format
Format code with prettiernpm run verify
Runsnpx turbo typecheck test lint
npm run cli
Runsapps/cidlang/dist/lib/cidlang.js
. Must runnpm run build
first.npm run repl
Runsapps/cidrepl/dist/lib/cidrepl.js
. Must runnpm run build
first.apps/cidlang/dist/bins/cidlang-{linux|macos|windows.exe}
Runs cidlang binary. Must runnpm run build
first.apps/cidrepl/dist/bins/cidrepl-{linux|macos|windows.exe}
Runs cidrepl binary. Must runnpm run build
first.
- Tokenize source code in to tokens
- Parse tokens in to expressions
- Interpret expressions
Tokens are mappings of syntax value from the source code. They have a tokenType
, lexeme
and literal
values. The tokenType
is the type of syntax the token represents. The lexeme
is the raw string from the source code while literal
is the literal value the lexeme
represents.
The Tokenizer
will take an input string of source code and return Token[]
for the Parser
.
class Token {
private readonly tokenType: TokenType;
private readonly lexeme: string;
private readonly literal: unknown;
}
enum TokenType {
LeftBracket = "LeftBracket",
RightBracket = "RightBracket",
Quote = "Quote",
Symbol = "Symbol",
Number = "Number",
Boolean = "Boolean",
String = "String",
Eof = "Eof",
}
The Parser
will take an input Token[]
and generate expressions Expression[]
for the Interpreter
.
export type NumericExpression = number;
export type StringExpression = string;
export type BooleanExpression = boolean;
export type SymbolExpression = Sym;
/**
* Single value, non list expressions
*
* - 123
* - "Hello World"
* - Sym.of("a")
* - true/false
*/
type AtomicExpression =
| NumericExpression
| StringExpression
| SymbolExpression
| BooleanExpression;
/**
* Tuple/pair value expression
*
* - Cell.of(1, 2) => (1 . 2)
* - Cell.list(1, 2) => (1 . (2 . ())) => (1 2)
*/
type PairExpression = Cell;
/**
* Null/empty list expression
*
* - ()
* - '()
* - (list)
* - Cell.list()
*/
type NullExpression = [];
/**
* Pair or empty list expression
*
* () '() (1 . 2) (1 2 3) (list 1 2 3)
*/
type ListExpression = PairExpression | NullExpression;
/**
* Atomic or list expression
*/
type Expression = AtomicExpression | ListExpression;
/**
* One or more expressions
*/
type Program = Expression[];
The Tokenizer
reads in a source code string and returns Token[]
.
The Parser
reads in a Token[]
and returns Exression[]
.
The Interpreter
reads in and executes an Exression[]
returning the result of the last Exression
.