-
Notifications
You must be signed in to change notification settings - Fork 3
Compiler
This document is incomplete! Help us to expand it.
This document is for documentating compiler functionality and some guidelines for future development.
Code compilation is done in ... steps.
The lexer.js is used to tokenize the source code. Tokenization is done with regular expression for detecting keywords and more complicated patterns. Lexers returns Token objects which have variables type
, line
and val
.
Following token types are supported and checked in this order:
-
End Of Source (eos) Emited in case of end of source code
-
Comment (comment) Comments are string literals begining with single quote and ending at the end of line
-
Number (number) Numbers are string literals possibly starting with a minus sign (-), then containing zero or more desimal figits, an optional dot (.) and then one or more desimal digits
-
String (string) A string is as short as possible text literal starting and ending with double quote ("). For string literals
val
doesn't contain quotes. -
Operator An operator is one of the following:
-
<
(lt) -
<=
(lte) -
>
(gt) -
>=
(gte) -
=
(eq) -
<>
(neq) -
and
(and) -
or
(or) -
xor
(xor) -
+
(plus) -
-
(minus) -
*
(mul) -
/
(div) -
mod
(mod) -
&
(concat)
-
-
Comma (comma) Just a regular comma (,).
-
Parenthesis Either
(
(lparen) or)
(rparen). -
To (to) A string literal equals to
TO
.
...TODO! Complete the list
Parser reads tokens via lexer and creates an Abstract Syntax Tree (ast) of tokens.
Checks types of every expression.
Checks for every expression if it is atomic i.e. if it doesn't call DRAWSCREEN
in any of its branches.
Compiles ast into an asm.js compatible code.