The primitive language
Editor
Result
The primitive language has three basic types of statements:
AssgStmt
Assign the result of an expression to a variable.
PrintStmt
Issue printing of (the result of) an expression to an output.
ConfigStmt
Set a configuration. Only one option is available: changing the number base. A base can be either decimal, hexadecimal or binary. Affects subsequent printing statements.
Additionally, there are expressions:
MathExp
A mathematical expression. Valid operands are numbers (integers) and variables. Valid operators are the basic arithmetic operators, +–*/. Additionally, parentheses are allowed to define scopes for nested expressions.
Example source and output
Input:
| source code | Statement type |
|---|---|
|
config dec print 1 + 1 print 3 + 3 * 3 print ( 3 + 3 ) * 3 var1 = 2 - -2 var2 = var1 var3 = var2 * ( 16 / ( var2 - 2 ) ) print var1 print var2 print var3 config hex print var3 config bin print var3 |
ConfigStmt PrintStmt PrintStmt PrintStmt AssgStmt AssgStmt AssgStmt PrintStmt PrintStmt PrintStmt ConfigStmt PrintStmt ConfigStmt PrintStmt |
Output:
2
12
18
4
4
32
20
100000
Other rules
Config
You must set the config at the beginning.
Config can be dec, bin, and hex.
If you set it to dec then values will be displayed as decimal number.
If you set it to bin then values will be displayed as binary number.
If you set it to hex then values will be displayed as hexadecimal numbers.
Spacing
There must be spacing between every character
Every keyword must be lowercase.