Simple programming language made in order to learn the basics of creating programming languages.
- declaring variables with optional initial value
- creating binary expressions with operators:
+,-,*,/ - creating assignment expressions
- printing values to the console
var x = 3
var y = 2
var z = x * y
print x, y, z
var - variable declaration
var IDENTIFIER (PUNCTUATOR(=) BINARY_EXPRESSION)?
print - prints values to the console
print EXPRESSION (PUNCTUATOR(,) BINARY_EXPRESSION)*
White space code points are used for tokens separation and to improve source text readability. They may occur between any two tokens and on the start or end of input.
| Code Points | Name | Abbreviation |
|---|---|---|
| U+0009 | CHARACTER TABULATION | TAB |
| U+000B | LINE TABULATION | VT |
| U+000C | FORM FEED | FF |
| U+FEFF | ZERO WIDTH NO-BREAK SPACE | ZWNBSP |
| any code point from "Space_Separator" category | USP |
Line Terminator code points are used for tokens separation and to improve source text readability. As white space code points, they may occur between any two tokens and on the start or end of input.
| Code Points | Name | Abbreviation |
|---|---|---|
| U+000A | LINE FEED | LF |
| U+000D | CARRIAGE RETURN | CR |
| U+2028 | LINE SEPARATOR | LS |
| U+2029 | PARAGRAPH SEPARATOR | PS |
Only the Unicode code points in Table 2 are treated as line terminators. Other new line or line breaking Unicode code points are not treated as line terminators but are treated as white space if they meet the requirements listed in Table Table 1. The sequence CR+LF is commonly used as a line terminator. It should be considered as single character for the purpose of reporting line numbers.
Tokens are the smallest indivisible syntactic units of a language
| Name | Syntax |
|---|---|
| KEYWORD | (var|print) |
| IDENTIFIER | [$_a-zA-Z][$_a-zA-Z0-9]* |
| NUMBER | [0-9] |
| PUNCTUATOR | (+|-|*|/|**|,) |
Binary expression consists of two operands and one operator. The operand can be any number or identifier, but it can also be another binary expression.
(IDENTIFIER|NUMBER|BINARY_EXPRESSION) (PUNCTUATOR(+|-|*|/|**) (IDENTIFIER|NUMBER|BINARY_EXPRESSION))*
Assignment expressions are used to assign Binary Expression to the variable.
IDENTIFIER PUNCTUATOR(=) BINARY_EXPRESSION
Variable declarations are initated with var Keyword and they create new variable in memory, which can be accesed by supplied Identifier. It is also possible to assign initial value to the variable, which is Binary Expression.
var IDENTIFIER (PUNCTUATOR(=) BINARY_EXPRESSION)?
Printing to the console allows to see results of computations.
print (IDENTIFIER|BINARY_EXPRESSION) (PUNCTUATOR(,) (IDENTIFIER|BINARY_EXPRESSION))*