Minimal typechecking for Binding

master
Araozu 2024-05-04 19:23:53 -05:00
parent 59894a1b64
commit c8d16fc77f
5 changed files with 15 additions and 10 deletions

View File

@ -35,9 +35,9 @@
- [x] Parse binding of form `val Type variable = value`
- [x] Parse binding of form `Type variable = value`
- [ ] Infer datatype of `value` in the above for a simple expression
- [ ] Ensure that the anotated datatype matches the datatype of `value` in the above
- [ ] Infer datatype of a `val variable = value` in the AST: Use the infered datatype
- [x] Infer datatype of `value` in the above for a simple expression (minimal)
- [x] Ensure that the anotated datatype matches the datatype of `value` in the above (binding)
- [x] Infer datatype of a `val variable = value` in the AST: Use the infered datatype (binding)
- [x] Formally define the top level constructs
- [x] Parse bindings and function declarations as top level constructs
- [x] Parse function declaration arguments (`Type id`)

2
Cargo.lock generated
View File

@ -20,7 +20,7 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "thp"
version = "0.0.10"
version = "0.0.11"
dependencies = [
"colored",
]

View File

@ -1,6 +1,6 @@
[package]
name = "thp"
version = "0.0.10"
version = "0.0.11"
edition = "2021"

View File

@ -2,9 +2,17 @@ use crate::syntax::ast::Expression;
use super::Typed;
impl Typed for Expression<'_> {
fn get_type(&self) -> String {
todo!()
match self {
// TODO: Distinguish between Int & Float
Expression::Number(_) => "Int".into(),
Expression::String(_) => "String".into(),
Expression::Boolean(_) => "Bool".into(),
Expression::Identifier(_) => todo!(),
Expression::FunctionCall(_) => todo!(),
Expression::UnaryOperator(_, _) => todo!(),
Expression::BinaryOperator(_, _, _) => todo!(),
}
}
}

View File

@ -1,11 +1,8 @@
// This crate provides an interface and implementations
// for determining the datatypes of the language constructs.
use crate::lexic::token::Token;
mod expression;
pub trait Typed {
fn get_type(&self) -> String;
}