Imperative language done as compilers class final project
cargo run -- examples/filename.ra
-q
or--quads
. Shows the quadruples generated by the compiler-d
or--debug
. Shows debugging message for the developer of the language
- Assignments for global variables
- Function declarations
- Main
a = 3;
b = "hello";
c = false;
d = 1.2;
e = [1, 2, 3];
f = read_csv("data.csv");
In raoul variable type is infer based on the first value assigned to the variable. We support the following types:
- int
- float
- string
- boolean
- dataframes
- arrays (only for atomic types, ie. not dataframes)
Due to this freedom, we made the rule of not being able to re-define the type
of a variable. If the variable was initially assigned to a boolean
type, the
following assignments to this variable must be of type boolean
or any type
that can be cast into it.
If you wish to make use of global variables there are 2 ways to achieve this:
// Assign before functions
a = 3;
func test(): int {
return a * b;
}
func main(): void {
// Use the "global" prefix
global b = 3;
print(test());
}
It's important to note that using the "global prefix" method sometimes may cause compilation errors that the "assign before functions" does not. Thus, if you don't want to worry about a lot about the prior is the recommended method.
Must be declared before main function. This is a language of good families, thus there is no polymorphism, meaning that every function's name should be unique.
func fibonacci(param: int): int {
...
return result;
}
x = 2 * (12 + x) >= a;
Language supports:
- Arithmetic operations (+, -, *, /)
- Compare and equality (>, <, >=, <=, ==, !=)
- Logical operations (&&, ||, !)
- Parenthesis for nested expressions
The upper-limit is an inclusive limit. Meaning that if the limit is equals to
5
the variable of control must be higher than five to exit.
for i = start to limit {
...
}
i = 0
while(i < 10) {
...
i = i + 1;
}
if (cond) {
...
} else if (cond_2) {
...
} else {
...
}
Variable assigned the value of input will be of type string
, nevertheless,
we've made sure that string
can cast into most of atomic types (with the
exception of boolean). Thus, you can make use of it.
a = input();
Its possible to chain multiple string constants and expressions. At the end, this will always print a new line.
print(var, " ", func());
There can only be one dataframe per program
read_csv("data.csv");
To get the amount rows and columns of a dataframe you can do the following
rows = get_rows(dataframe);
columns = get_columns(dataframe);
Returns the operation value for a given key.
Possible operations:
- Mean:
average()
- Variance:
variance()
- Std:
std()
- Median:
median()
- Min:
min()
- Max:
max()
- Range:
range()
Arguments:
- 1st argument: must be a dataframe
- 2nd argument: must be a value of type
string
, that represents the column to analyze
avg(data, "key");
Returns correlation value for two columns
correl(data, "key1", "key2");
Scatter plot for two columns in the dataframe, pops up in new window
plot(data, "key1", "key2");
Note. Using this command will end the execution of the program, so is recommended to be the last one
Histogram for a variable in the dataframe, the third argument is the number of bins for the histogram.
Plot pops up in new window.
hist(data, "key1", 10);
Note. Using this command will end the execution of the program, so is recommended to be the last one
func main(): void {
...
}
There is a bunch a possible valid and invalid files in the examples folder in repo.
For more details, check Documentation
If you want a use in action of the compiler you can see the following video
Note The video is in Spanish