NOTE: The author makes clear that using this tool to complete work where it is not permitted, such as in COMP1521 lab activities and assignments, is not condoned, and takes no responsibility for such events.
- If statementsz
- While/For loops
- Gotos/Labels
- Hexadecimal support
- Functions
- Function arguments
- Global/Local variables
- Arrays (no multidemensional support)
- Indexing
- Int/Char types
- Poke/Peek
- Bitwise operators
- Pre/Post increment/decrement
- Pointers
- String literals
- Input (String, Char, Int)/Print
- Normal mathy stuff and negation
- - + % / *
- Bodmas
- Logical operators (besides || and &&)
- Structs
- Union
- Comments
- typedef
- enums
- break/continue
- switch
- macros
- Array initisaliation
- Local variable initialisation
- Type casting
- octal support
- Sizeof operator
- Ternary operator
- || and && operators
- Function headings (WIP)
- Register spilling (broken at the moment)
- Lazy Evaluation
- Compiler directives
- Including the ability to manually name any label
- Multidimensional arrays
- Namespace
- Inline assembly and registers
- Scopes (probs wont be done)
- scope creation (probs wont be done)
- header comments
- statement commenting
- prints the original statement in assembly file next to instruction as comment
- Heap support
- unsigned types
- Optimization
- Error recovery
- Graph Colouring for spilling registers
The higher the number, the higher the procedence.
Operator | Precedence |
---|---|
( ) | 13 |
< | 12 |
> | 12 |
<= | 12 |
>= | 12 |
== | 11 |
!= | 11 |
% | 10 |
/ | 10 |
* | 10 |
+ | 9 |
- | 9 |
<< | 8 |
>> | 8 |
& | 7 |
^ | 6 |
| | 5 |
&& | 4 |
|| | 3 |
? : | 2 |
= | 1 |
+= | 1 |
-= | 1 |
*= | 1 |
/= | 1 |
%= | 1 |
, | 0 |
<preprocessor> ::= "#" <directive>
<directive> ::= "include" (<string> | "<" <text> ">" ) | "define" <id> <string>
#include "stdio.h"
#include <stdio.h>
#define PI 3.14
NOTE Includes for the standard library is different to C. Also its currently not working as intended.
<statement> ::= <type> <declaration> ( "," <declaration> )* ";"
<declaration> ::= <identifier> [ "[" <number> "]" ] [ "=" <value> | "=" "{" <value> ( "," <value> )* "}" ]
i32 a = 2;
i8 bob;
i32 b, c = 3;
i32 d[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, e;
i32 d[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, e = 2;
i32 d[10], e = 2;
i32 d[10], e;
i8 *a = "Hello";
i8 *deez_nuts = "Gottem";
NOTE: You can only go up to 15 *'s.
<statement> ::= <type> <declaration> ( "," <declaration> )* ";"
<declaration> ::= <identifier> [ "[" <expression> "]" ] | <identifier> [ "=" <expression> ]
i32 a;
i32 a = 2, b;
i32 a[10], b;
i8 *a;
i8 **a;
NOTE: You cannot initialise local arrays.
NOTE: You can only go up to 15 *'s.
<struct> ::= "struct" <id> "{" <statements> "}"
struct Jeff {
i32 money;
i8 *name;
i8 address[120];
struct Jeff *next;
}
NOTE: You cannot initialise values in the struct.
<enum> ::= "enum" <id> "{" <id> [ "=" <number> ] ( "," <id> [ "=" <number> ] )* "}"
enum Jeff {
JEFF = 1,
JEFFERY = 2,
JEFFREY = 3
}
<typedef> ::= "typedef" <type> <id>
typedef i32 Jeff;
typedef i8 *Jeff;
typedef struct Jeff poo;
<union> ::= "union" <id> "{" <statements> "}"
union Jeff {
i32 money;
i8 *name;
i8 address[120];
struct Jeff *next;
}
<func> ::= <type> <id> "(" [ <args> ] ")" "{" <stmts> "}"
i32 Domain_Expansion(i32 a, i32 b) {
print("Nah I'd win", 10);
print("a: ", a, ", b: ", b, 10);
return 0;
}
You can also put void as the parameter.
i32 main(void) {
printf("We also want to make it clear that using this tool to create solutions to lab activities and assignments strictly against the rules of the course and will be treated as academic misconduct.");
}
<call> ::= <id> "(" [ <args> ] ")"
Domain_Expansion(69, 420);
<ptr> ::= "*" <id>
i32 a = 2;
i32 *b = &a;
i32 **c = &b;
print(**c, 10);
NOTE: You can only go up to 15 *'s.
<label> ::= "label" <id> ":"
label start:
print("Hello", 10);
<goto> ::= "goto" <id> ";"
label start;
print("This is gold experience requiem", 10);
goto start;
<if> ::= "if" "(" <expr> ")" "{" <stmts> "}"
i32 a = 2;
if (a == 2) {
print("a is 2", 10);
}
<while> ::= "while" "(" <expr> ")" "{" <stmts> "}"
i32 a = 0;
while (a < 10) {
print(a, 10);
a = a + 1;
}
<for> ::= "for" "(" <set> <expr> ";" <set> ")" "{" <stmts> "}"
i32 a = 0;
for (a = 0; a < 10; a++) {
print(a, 10);
}
<breakcont> ::= "break" ";"
| "continue" ";"
i32 a = 0;
for (a = 0; a < 10; a++) {
if (a == 5) {
break;
}
print(a, 10);
}
<switch> ::= "switch" "(" <expr> ")" "{" <cases> "}"
<cases> ::= <case> <cases>
| <default>
<case> ::= "case" <expr> ":" <stmts>
<default> ::= "default" ":" <stmts>
i32 a = 2;
switch (a) {
case 1:
print("a is 1", 10);
break;
case 2:
print("a is 2", 10);
break;
default:
print("a is not 1 or 2", 10);
break;
}
<input> ::= "input" "(" <id> "," <type> ")"
i32 a;
input(a, i32);
i8 choice;
input(choice, i8);
i8 creditCardDetails[120];
input(creditCardDetails, i8*);
NOTE: Input implicitly uses the array size.
<print> ::= "print" "(" <args> ")"
print("Hello", 10);
<bitwise> ::= <expr> "&" <expr>
| <expr> "|" <expr>
| <expr> "^" <expr>
| <expr> "<<" <expr>
| <expr> ">>" <expr>
i32 a = 2;
i32 b = 3;
print(a & b, 10);
print(a | b, 10);
print(a ^ b, 10);
print(a << b, 10);
print(a >> b, 10);
<logical> ::= <expr> "==" <expr>
| <expr> "!=" <expr>
| <expr> "<" <expr>
| <expr> ">" <expr>
| <expr> "<=" <expr>
| <expr> ">=" <expr>
i32 a = 2;
i32 b = 3;
print(a == b, 10);
print(a != b, 10);
print(a < b, 10);
print(a > b, 10);
print(a <= b, 10);
print(a >= b, 10);
<ternary> ::= <expr> "?" <expr> ":" <expr>
i32 a = 2;
i32 b = 3;
print(a == b ? 1 : 0, 10);
<andor> ::= <expr> "&&" <expr>
| <expr> "||" <expr>
i32 a = 2;
i32 b = 3;
print(a == 2 && b == 3, 10);
print(a == 2 || b == 3, 10);
<not> ::= "!" <expr>
<incdec> ::= "++" <id>
| "--" <id>
| <id> "++"
| <id> "--"
i32 a = 2;
print(a++, 10);
print(a, 10);
print(++a, 10);
print(a, 10);
print(a--, 10);
print(a, 10);
print(--a, 10);
print(a, 10);
NOTE: You can only have one increment/decrement per statement.
<pokepeek> ::= "poke" "(" <expr> "," <expr> ")"
| "peek" "(" <expr> ")"
i32 a = 2;
poke(0x10010000, a);
print(peek(0x10010000), 10);
<string> ::= <string> <string>
| <char>
i8 *sigma = "Skibidi toilet\n";
i8 *hello = "how, " "are, " "you?\n";
<arith> ::= <expr> "+" <expr>
| <expr> "-" <expr>
| <expr> "*" <expr>
| <expr> "/" <expr>
| <expr> "%" <expr>
i32 a = 2;
i32 b = 3;
print(a + b, 10);
print(a - b, 10);
print(a * b, 10);
print(a / b, 10);
print(a % b, 10);
<paren> ::= "(" <expr> ")"
i32 a = 2;
i32 b = 3;
print((a + b) * 2, 10);
<cast> ::= "(" <type> ")" <expr>
i32 a = 2;
i8 b = (i8)a;
print(b, 10);
<octal> ::= "0" <octal>
| "0"
i32 a = 010;
print(a, 10);
<hex> ::= "0x" <hex>
| "0x" <digit>
| "0x" <letter>
i32 a = 0x10;
print(a, 10);
<sizeof> ::= "sizeof" "(" <type> ")"
print(sizeof(i32), 10);
print(sizeof(i8), 10);
print(sizeof(i32*), 10);
print(sizeof(i8*), 10);
// Strings
print("Hello" [hello_string], 10);
// if statements
if [if_statement] (a == 2) {
print("a is 2", 10);
} else {
print("a is not 2", 10);
}
// while loops
while [while_loop] (a < 10) {
print(a, 10);
a = a + 1;
}
// for loops
for [for_loop] (a = 0; a < 10; a++) {
print(a, 10);
}
// switch
switch [switch_statement] (a) {
case [case_1] 1:
print("a is 1", 10);
break;
case [case_2] 2:
print("a is 2", 10);
break;
default [default_case]:
print("a is not 1 or 2", 10);
break;
}
<exit> ::= "exit" "(" <expr> ")"
exit(0);