Get dataypes from sybols

master
Araozu 2023-02-11 09:52:30 -05:00
parent cfbb86ab68
commit 3a11000fe0
4 changed files with 15 additions and 15 deletions

View File

@ -11,6 +11,11 @@
- [ ] Stdlib
- [ ] Document code
## v0.0.2
- Compilation of `val` and `var` bindings with a number, string or boolean as value.
- Register symbols and datatypes in the Symbol table.
## v0.0.1
- Compilation of a `val` binding with a number.

2
Cargo.lock generated
View File

@ -169,7 +169,7 @@ dependencies = [
[[package]]
name = "misti"
version = "0.0.1"
version = "0.0.2"
dependencies = [
"chrono",
]

View File

@ -1,6 +1,6 @@
[package]
name = "misti"
version = "0.0.1"
version = "0.0.2"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@ -1,25 +1,20 @@
use crate::ast_types::Expression;
use crate::symbol_table::{_STRING, _BOOLEAN};
use super::symbol_table::{SymbolTable, _NUMBER};
use super::ast_types::{ModuleAST, Binding};
use super::symbol_table::{SymbolTable, _NUMBER, _STRING, _BOOLEAN};
use super::ast_types::{ModuleAST, Binding, Expression};
/// Checks the AST. In the future should return a list of errors.
pub fn check_ast<'a>(ast: &'a mut ModuleAST, symbol_table: &'a mut SymbolTable) {
for binding in &ast.bindings {
match binding {
Binding::Val(val_binding) => {
// TODO: create a function to get the datatype, instead of a hardcoded value
Binding::Val(binding) => {
symbol_table.add(
val_binding.identifier,
get_expression_type(&val_binding.expression).as_str()
binding.identifier,
get_expression_type(&binding.expression).as_str()
);
}
Binding::Var(var_binding) => {
// TODO: create a function to get the datatype, instead of a hardcoded value
Binding::Var(binding) => {
symbol_table.add(
var_binding.identifier,
get_expression_type(&var_binding.expression).as_str(),
binding.identifier,
get_expression_type(&binding.expression).as_str(),
);
}
}