Cog has support for the following:
- numeric literals
- arithmetic operations
- variable declaration
- native function calls
- objects and object member calls
- string literals
- user defined functions
- conditionals
- loops
Since this is a college project i dont think i will add anything outside the list mentioned above, this is a side project, feel free to use the contents in this repo as you wish.
1 - Clone the repo:
git clone https://github.com/JoaoCardoso00/Cog.git
2 - Run the program:
cargo run -- example.cog
you can write in the example.cog or create a new one and pass the path to the file as the argument for the program
the program also supports an optional -ast flag that prints the generated AST to the standard output
cargo run -- example.cog -ast
Example:
let x = 5;
Output:
AST {
kind: "Program",
statements: [
ASTStatement {
kind: VariableDeclaration(
VariableDeclaration {
constant: false,
identifier: String(
"x",
),
value: Some(
ASTExpression {
kind: NumericLiteral,
body: Value(
Number(
5.0,
),
),
},
),
},
),
},
],
}
prints to the standard output all the arguments it was provided
let x = 10;
print(5 + 5)
print(x / 2)
it also supports object fields as arguments
let obj = {
field: {
value: 20
}
}
print(obj.field.value)