Minimal typechecking for Binding
This commit is contained in:
parent
59894a1b64
commit
c8d16fc77f
@ -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
2
Cargo.lock
generated
@ -20,7 +20,7 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||
|
||||
[[package]]
|
||||
name = "thp"
|
||||
version = "0.0.10"
|
||||
version = "0.0.11"
|
||||
dependencies = [
|
||||
"colored",
|
||||
]
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "thp"
|
||||
version = "0.0.10"
|
||||
version = "0.0.11"
|
||||
edition = "2021"
|
||||
|
||||
|
||||
|
@ -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!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user