This is a monorepo managed by Turborepo, having the following published packages:
- @alakir/core
- @alakir/cli
probably other tools to come(bullshit topic is not motivating)
Install the package globally with npm i -g @alakir/cli
or pnpm add -g @alakir/cli
and then run alakir --help
to see the list of commands.
- Have Node.js 16+ installed.
- Install pnpm with
npm i -g pnpm
- Install dependencies with
pnpm i --frozen-lockfile
- Run
pnpm run build
to build all the packages
pnpm run test
orpnpm run test:coverage
for coverage
. - any symbol
if
,else
,while
,print
,define
,const
(
,)
,{
,}
,[
,]
,;
,,
,=
,==
,!=
,>
,<
,>=
,<=
,+
,-
,*
,/
,%
,:
,.
,!
,&&
,||
<digit> ::= [
0-9
]
<alpha> ::= [
a-z
] | [A-Z
]
<alphanumeric> ::= <alpha> | <digit>
- <BooleanLiteral> ::=
true
|false
- <StringLiteral> ::=
"
(.|[^"])*"
|'
(.|[^'])*'
- <NumberLiteral> ::= (
0
|([1-9
][0-9
]*))(.[0-9]+)? - <DateLiteral> ::=
D
<digit>4-
<digit>2-
<digit>2 - <Identifier> ::= (<alpha>|
_
|$
) (<alphanumeric>|_
|$
)* - <Literal> ::= <BooleanLiteral> | <StringLiteral> | <NumberLiteral> | <DateLiteral> | <Identifier>
<binaryOperator> ::=
+
|-
|*
|/
|%
|==
|!=
|>
|<
|>=
|<=
|&&
|||
- <ArrayExpression> ::=
[
<Expression> (,
<Expression>)*]
- <ObjectExpression> ::=
{
<Identifier>:
<Expression> (,
<Identifier>:
<Expression>)*}
- <CallExpression> ::= <Identifier>
(
<Expression> (,
<Expression>)*)
- <AssignmentExpression> ::= <Expression>
=
<Expression> - <BinaryExpression> ::= <Expression> <binaryOperator> <Expression> | <AssignmentExpression>
- <IndexingExpression> ::= <Expression>
[
<Expression>]
- <MemberAccessExpression> ::= <Expression>
.
<Identifier> - <Expression> ::= <Literal> | <ArrayExpression> | <ObjectExpression> | <CallExpression> | <BinaryExpression> | <IndexingExpression> | <MemberAccessExpression>
<declarator> ::= <Identifier> (
=
<Expression>)?
- <ExpressionStatement> ::= <Expression>
;
- <BlockStatement> ::=
{
<Statement>*}
- <IfStatement> ::=
if
(
<Expression>)
<Statement> (else
<Statement>)? - <WhileStatement> ::=
while
(
<Expression>)
<Statement> - <PrintStatement> ::=
print
(
<Expression>)
;
- <VariableDeclaration> ::=
const
|declare
<declarator> (,
<declarator>)*;
- <Statement> ::= <ExpressionStatement> | <BlockStatement> | <IfStatement> | <WhileStatement> | <PrintStatement> | <VariableDeclaration>
- <Program> ::= <Statement>*
-
Lexer (Add more keywords and symbols if you want)
-
Parser
- Basic keywords
- Declarations & assignments
- Binary expressions
- Expressions
- Function calls
- Array/Object element accessing
- Control flow
- Ast generation
-
Function definitionsIgnored for simplicity
-
Cli (some demo scripts are in the parser 'demo' folder)
- Read from file
- Repl
- Lex
- Parse
- Interpret
- Error handling for incomplete parsing
-
Interpreter
- Assignments and declarations
- Block scoped variables
- IO
- Function calls
- Predefined functions support
- Predefined functions
- lucky(
string
) gets someone's name's lucky number - len(
array
) used with arrays - str(
number
) converts number to string - now() returns current date
- getMoonPhase(
date
) - getZodiacSign(
date
) - getZodiacEmoji(
string
) - areZodiacSignsCompatible(
string
,string
)
- lucky(
- Global constants
- PI
number
- ZODIAC_COLORS
object
- PI
- Control flow
- Loops
- Array and objects
- Indexing & property access