Pseudocode-to-Javascript compiler
npm install pseudo-js

----
var keyword. At the declaration, an initial value may or may not be set. A variable only needs to be declared the first time it is referenced; declaring a variable with the same name of another previously declared will result in overriding the previous value of the same name variable.var NUMBER is 2var NUMBERis, which is equivalent to using the operator =. The variable to be assigned is the left-hand side operand, while the value to assign is on the right-side, with the assignment keyword between both. NUMBER is 2NUMBER = 1true or false.HOUSE has DOOR = 1, HOUSE has WINDOW = 2NUMBERS = [1, 2, 3]SUM(NUMA, NUMB){...}for each NUMBER in NUMBERSwhile NUMBER < 10if NUMBER < 10if NUMBER < 10 ... else ...if NUMBER < 10 ... else if NUMBER > 100 ...Blocks are wrapped with curly brackets ( '{' and '}' ). { ... }
Although not necessary, for the sake of readability we recommend to separate the brackets from the first and last lines of code with a line break, such as:
... {
var NUMBER is 2
}
rather than
... {var NUMBER is 2}
... {
EXTNUMBER is 10
// INNUMBER is not 'known' as a variable in this scope
{
INNUMBER is 20
// Within this block, both INNUMBER and EXTNUMBER are accessible variables.
// If EXTNUMBER were to be re-declared in this scope,
// it's value (if defined in the superior block) would be overriden
}
}
`Functions
Functions are essentially named blocks, which may receive _parameters_ to be used as variables by the sencentes within said block.$3
- Functions are to be named as any other variable, as they _are_ variables
- The name of a function must precede the opening of a block SUM { ... }
- Functions _can_ receive parameters, which are to be listed and named within parenthesis ( '(' and ')') _between_ the name of the function and the opening of the block SUM(NUMA, NUMB) { ... }
- If not specified or empty, it will be considered that the function has no parameters. SUM { ... } _is equivalent to_ SUM() { ... }$3
- A function is to be called by its name, followed by the parameters to pass to it between parenthesis (parameters will be passed to the function in the order defined at its declaration; parenthesis are to be used even if no parameters are passed)
- Call with parameters: SUM(A, B)
- Call without parameters: SUM()
- Functions can be called without passing parameters even when it's declaration does define them. If one or more parameters are not passed, its values within the function's block will be void. SUM() _is equivalent to_ SUM(void, void)$3
- All functions return a value on completing its execution. To explicitly define the return value of a function, it must contain a statement in the form of return VALUE, where value can be a variable, an operation, or a call to another function. If not explicitly declared, the return value of a function will be void.
- The return statement ends the execution of the function, whether it is the last statement or not.Sentences
- A sentence can be composed of
- The declaration of a [new] variable NUMBER is 10
- A basic operation NUMA + NUMB
- A function call SUM(NUMA, NUMB)
- Sentences are separated by line-breaks. For the sake of readability, not more than one sentence can be in the same line. The only exceptions to this rule are array declarations and key-value assignations for objects, as several values can be assigned within what is considered in this draft to be a single statement; these multiple value assignations must be comma-separated. LIST has 1, 2, 3 or OBJ has PROPA = 1, PROPB = 2
Operators
Operators perform operations between a left-hand side and a right-hand side operands, or over one single operand (depending on the definition of the operation). These operands can be variables, function calls (taking its return value), or other operations, which may be enclosed within parenthesis ('(' and ')'). Parenthesis in operations are used in the same manner as in Mathematics.
$3
- is (or '=')
- Basic value assignment operator. Assigns right-hand side value to the left-hand side variable. Using _is_ or '_=_' has the same result. NUM is 10 _is equivalent to_ NUM = 10.
- has
- _has_ defines the left-hand side variable as an object, and the right-hand side variable as a property of that object. In the sentence HOUSE has DOORS = 2, we are defining a variable HOUSE as an object, which has a property DOORS, to which we assign the value 2. Shown as a key-value map: HOUSE = {DOORS: 2}.
- of (or in)
- _of_ and _in_ are synonims used to access a property of an object. Take for example the object HOUSE defined above. DOORS of HOUSE or DOORS in HOUSE would reference the property DOORS in it, to be used as any other variable in a statement, such as a new value assignment or an operation. DOORS of HOUSE = 4, SUM(1, DOORS of HOUSE).$3
Arithmetic operators return a number value, with the only exception of the _addition_ operator, which may return a _String_ value if one or both of the operands was also a _String_.
- + : Addition.
- \- : Substraction
- \* : Multiplication.
- \\ : Division.
- % : Remainder.$3
Comparison operations return a boolean value.
- == or equals : Equals.
- \>= or greater than or equals : Greater than or equals.
- <= or lesser than or equals : Lesser than or equals.
- != or not equals : Not equals.
- \> or greater than : Greater than.
- < or lesser than : Lesser than.$3
Boolean operations take boolean values as operands and return another boolean value.
- and : Takes two boolean operands, and evaluates to true only if both operands are true.
- or : Takes two boolean operands, and evaluates to true if either of both operands are true`.