https://github.com/malted/aqa-pseudocode
An AQA Pseudocode transpiler & interpreter
https://github.com/malted/aqa-pseudocode
Last synced: 12 months ago
JSON representation
An AQA Pseudocode transpiler & interpreter
- Host: GitHub
- URL: https://github.com/malted/aqa-pseudocode
- Owner: malted
- Created: 2022-09-20T16:23:14.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-09-20T16:33:10.000Z (almost 4 years ago)
- Last Synced: 2025-03-06T12:47:07.452Z (over 1 year ago)
- Language: TypeScript
- Homepage:
- Size: 4.88 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Translation reference
### Comments
#### Single-line comments
| AQA | JavaScript |
| -------------------- | --------------------- |
|
# comment
| // comment
|
#### Multi-line comments
| AQA | JavaScript |
| ------------------------------------------- | --------------------------------------------- |
|
# comment
# comment and so on
| // comment
// comment and so on
|
### Variables and constants
#### Variable assignment
| AQA | JavaScript |
| ---------------------------- | ----------------------------------- |
|
Identifier <- Exp
| **let** Identifier = Exp
|
#### Constant assignment
| AQA | JavaScript |
| ----------------------------------------- | ------------------------------------- |
|
**CONSTANT** Identifier <- Exp
| **const** Identifier = Exp
|
### Arithmetic operations
#### Standard arithmetic operations
| AQA | JavaScript |
| ----------------------------- | ----------------------------- |
|
Exp {+,-,\*,/} Exp | Exp {+,-,\*,/} Exp |
#### Integer division
| AQA | JavaScript |
| ---------------------------- | -------------------------------- |
|
IntExp DIV IntExp
| Math.floor(Exp / Exp)
|
#### Modulus operator
| AQA | JavaScript |
| ---------------------------- | -------------------- |
|
IntExp MOD IntExp
| Exp % Exp
|
### Relational operators for types that can be clearly ordered
#### Less than
| AQA | JavaScript |
| -------------------- | -------------------- |
|
Exp < Exp
| Exp < Exp
|
#### Greater than
| AQA | JavaScript |
| -------------------- | -------------------- |
|
Exp > Exp
| Exp > Exp
|
#### Equal to
| AQA | JavaScript |
| -------------------- | ---------------------- |
|
Exp = Exp
| Exp === Exp
|
#### Not equal to
| AQA | JavaScript |
| -------------------- | ---------------------- |
|
Exp ≠ Exp
| Exp !== Exp
|
#### Less than or equal to
| AQA | JavaScript |
| -------------------- | --------------------- |
|
Exp ≤ Exp
| Exp <= Exp
|
#### Greater than or equal to
| AQA | JavaScript |
| -------------------- | --------------------- |
|
Exp ≥ Exp
| Exp >= Exp
|
### Boolean operations
#### Logical AND
| AQA | JavaScript |
| ------------------------------ | ----------------------------- |
|
BoolExp AND BoolExp
| BoolExp && BoolExp
|
#### Logical OR
| AQA | JavaScript |
| ----------------------------- | ------------------------------- |
|
BoolExp OR BoolExp
| BoolExp \|\| BoolExp
|
#### Logical NOT
| AQA | JavaScript |
| ---------------------- | ------------------- |
|
NOT BoolExp
| !BoolExp
|
### Indefinite (condition controlled) iteration
#### REPEAT-UNTIL (repeat the statements until the Boolean expression is True).
| AQA | JavaScript |
| ------------------------------------------------------------------- | -------------------------------------------------------------------- |
|
REPEAT
# statements here
UNTIL BoolExp
| while (!BoolExp) {
// statements here
} |
#### WHILE-ENDWHILE (while the Boolean
expression is True, repeat the
statements).
| AQA | JavaScript |
| --------------------------------------------------------------------- | ------------------------------------------------------------------- |
|
WHILE BoolExp
# statements here
ENDWHILE
| while (BoolExp) {
// statements here
} |
### Definite (count controlled) iteration
#### FOR-TO-[STEP]-ENDFOR (If STEP IntExp is missing it is considered to be 1).
##### Note:
- If STEP IntExp is omitted the step value is 1.
- Note that in STEP IntExp the value of IntExp
- can be negative (see the third example)
| AQA | JavaScript |
| ---------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
|
**FOR** Identifier <- IntExp **TO** IntExp [**STEP** IntExp]
# statements here
**ENDFOR**
| for (Identifier = IntExp₁; IntExp₁ (IntExp₁ < IntExp₂ ? < : >) IntExp₂; IntExp₁ += **STEP** ?? 1) {
// statements here
} |
#### FOR-IN-ENDFOR (repeat the statements the number of times that there are characters in a string).
| AQA | JavaScript |
| --------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------- |
|
**FOR** Identifier **IN** StringExp
# statements here
**ENDFOR**
| for (Identifier of StringExp) {
// statements here
} |
### Selection
#### IF-THEN-ENDIF (execute the statements only if the Boolean expression is True).
| AQA | JavaScript |
| -------------------------------------------------------------------------------- | ---------------------------------------------------------------- |
|
**IF** BoolExp **THEN**
# statements here
**ENDIF**
| if (BoolExp) {
// statements here
} |
#### IF-THEN-ELSE-ENDIF (execute the statements following the THEN if the Boolean expression is True, otherwise execute the statements following the ELSE).
| AQA | JavaScript |
| ----------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- |
|
**IF** BoolExp **THEN**
# statements here
**ELSE**
# statements here
**ENDIF**
| if (BoolExp) {
// statements here
} else {
// statements here
} |
#### NESTED IF-THEN-ELSE ENDIF (use nested versions of the above to create more complex conditions). Note that IF statements can be nested inside the THEN part, the ELSE part or both.
| AQA | JavaScript |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
**IF** BoolExp **THEN**
# statements here
**ELSE**
**IF** BoolExp **THEN**
# statements here
**ELSE**
# statements here
**ENDIF**
**ENDIF**
| if (BoolExp) {
// statements here
} else {
if (BoolExp) {
// statements here
else {
// statements here
}
} |
#### IF-THEN-ELSE IF ENDIF (removes the need for multiple indentation levels).
| AQA | JavaScript |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
**IF** BoolExp **THEN**
# statements here
**ELSE IF BoolExp** **THEN**
# statements here
# possibly more ELSE IFs
**ELSE**
# statements here
**ENDIF**
| if (BoolExp) {
// statements here
} else if (BoolExp) {
// statements here
} else {
// statements here
} |
### Arrays
#### Assignment
| AQA | JavaScript |
| ---------------------------------------- | ------------------------------------------- |
|
Identifier <- [Exp, ..., Exp]
| let Identifier = [Exp, ..., Exp]
|
#### Accessing an element
| AQA | JavaScript |
| ----------------------------- | ----------------------------- |
|
Identifier[IntExp]
| Identifier[IntExp]
|
#### Updating an element
| AQA | JavaScript |
| ------------------------------------ | ----------------------------------- |
|
Identifier[IntExp] <- Exp
| Identifier[IntExp] = Exp
|
#### Accessing an element in a two-dimensional array
| AQA | JavaScript |
| ------------------------------------- | ------------------------------------- |
|
Identifier[IntExp][intexp]
| Identifier[IntExp][intexp]
|
#### Updating an element in a two-dimensional array
| AQA | JavaScript |
| -------------------------------------------- | ------------------------------------------- |
|
Identifier[IntExp][intexp] <- Exp
| Identifier[IntExp][intexp] = Exp
|
#### Array length
| AQA | JavaScript |
| -------------------------- | ---------------------------- |
|
LEN(Identifier)
| Identifier.length
|
#### FOR-IN-ENDFOR (repeat the statements the number of times that there are elements in an array)
##### Note:
- Array items cannot
be modified using this
method
| AQA | JavaScript |
| ----------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- |
|
**FOR** Identifier **IN** array
# statements here
**ENDFOR**
| array.forEach(Identifier => {
# statements here
}) |
### Records
#### Record declaration
##### Note:
- No point trying to enforce types in JavaScript.
- Would have been nicer to use a plain interfaced object here.
| AQA | JavaScript |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
**RECORD** Record_Identifier
field1 : <data type>
field2 : <data type>
...
**ENDRECORD**
| **class** Record_Identifier {
field1: <data type>;
field2: <data type>;
...
constructor(field1, field2) {
this.field1 = field1;
this.field2 = field2
...
}
} |
#### Variable Instantiation
| AQA | JavaScript |
| ------------------------------------------------------------- | ------------------------------------------------------------------- |
|
varName <- Record_indentifier(value1, value2, ...)
| let varName = new Record_identifier(value1, value2, ...)
|
#### Assigning a value to a field in a record
| AQA | JavaScript |
| ------------------------------- | ------------------------------ |
|
varName.field <- Exp
| varName.field = Exp
|
#### Accessing values of fields within records
| AQA | JavaScript |
| ------------------------ | ------------------------ |
|
varName.field
| varName.field
|
### Subroutines
##### Note: for the purposes of this pseudo-code definition subroutines that contain a RETURN keyword are functions. Those that do not contain a RETURN keyword are procedures.
#### Subroutine definition
| AQA | JavaScript |
| ------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------- |
|
**SUBROUTINE** Identifier(parameters)
# statements here
**ENDSUBROUTINE**
| **function** Identifier(parameters) {
# statements here
} |
#### Subroutine return value
| AQA | JavaScript |
| ------------------------- | ------------------------- |
|
**RETURN** Exp
| **return** Exp
|
#### Calling subroutines
| AQA | JavaScript |
| --------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
# Subroutines without a return value
Identifier(parameters)
# Subroutines with a return value
Identifier ← Identifier(parameters)
| // Subroutines without a return value
Identifier(parameters)
// Subroutines with a return value
Identifier = Identifier(parameters)
|
### String handling
#### String length
| AQA | JavaScript |
| ----------------------------- | --------------------------- |
|
**LEN**(StringExp)
| StringExp.length
|
#### Position of a character
| AQA | JavaScript |
| ------------------------------------------- | ------------------------------------- |
|
**POSITION**(StringExp, CharExp)
| StringExp.indexOf(CharExp)
|
#### Substring
##### Note:
- Created by the first parameter indicating the start position within the string, the second parameter indicating the final position within the string and the third parameter being the string itself.
| AQA | JavaScript |
| --------------------------------------------------- | -------------------------------------------------- |
|
**SUBSTRING**(IntExp, IntExp, StringExp)
| StringExp.substring(IntExp, IntExp + 1)
|
#### Concatenation
| AQA | JavaScript |
| -------------------------------- | -------------------------------- |
|
StringExp + StringExp
| StringExp + StringExp
|
### String and character conversion
#### Converting string to integer
| AQA | JavaScript |
| --------------------------------------- | ---------------------------------- |
|
**STRING_TO_INT**(StringExp)
| **parseInt**(StringExp)
|
#### Converting string to real
| AQA | JavaScript |
| ---------------------------------------- | ---------------------------------- |
|
**STRING_TO_REAL**(StringExp)
| **parseInt**(StringExp)
|
#### Converting integer to string
| AQA | JavaScript |
| ------------------------------------ | ---------------------------- |
|
**INT_TO_STRING**(IntExp)
| IntExp.toString()
|
#### Converting real to string
| AQA | JavaScript |
| ------------------------------------- | ----------------------------- |
|
**REAL_TO_STRING**(IntExp)
| RealExp.toString()
|
#### Converting character to character code
| AQA | JavaScript |
| ------------------------------------ | -------------------------------- |
|
**CHAR_TO_CODE**(CharExp)
| CharExp.charCodeAt(0)
|
#### Converting character code to character
| AQA | JavaScript |
| ------------------------------------ | --------------------------------------- |
|
**CODE_TO_CHAR**(CharExp)
| String.fromCharCode(CharExp)
|