From 03fb361e0b55e93e131e42c1406fde3c4f69ae37 Mon Sep 17 00:00:00 2001 From: Andrew Segavac Date: Sat, 29 May 2021 11:01:34 -0600 Subject: [PATCH] added block expression --- boring/parse.py | 3 ++- boring/type_checking.py | 4 ++++ examples/math/main.bl | 4 +++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/boring/parse.py b/boring/parse.py index aba9492..0289885 100644 --- a/boring/parse.py +++ b/boring/parse.py @@ -91,7 +91,7 @@ class VariableUsage: @dataclass class Expression: - expression: Union[LiteralInt, LiteralFloat, FunctionCall, VariableUsage, Operation] + expression: Union[LiteralInt, LiteralFloat, FunctionCall, "Block", VariableUsage, Operation] type: TypeUsage @@ -163,6 +163,7 @@ boring_grammar = r""" | variable_usage | function_call | "(" expression ")" + | block let_statement : "let" identifier "=" expression ";" | "let" identifier ":" type_usage "=" expression ";" diff --git a/boring/type_checking.py b/boring/type_checking.py index 61739ea..98c319f 100644 --- a/boring/type_checking.py +++ b/boring/type_checking.py @@ -139,6 +139,10 @@ class TypeChecker: if self.with_function_call(env, type_env, subexpression): changed = True return changed + if isinstance(subexpression, parse.Block): + if self.with_block(env, type_env, subexpression): + changed = True + return changed if isinstance(subexpression, parse.VariableUsage): if self.with_variable_usage(env, type_env, subexpression): changed = True diff --git a/examples/math/main.bl b/examples/math/main.bl index 4c492b1..8f75c7d 100644 --- a/examples/math/main.bl +++ b/examples/math/main.bl @@ -1,6 +1,8 @@ fn add(a: I32, b: I32): I32 { let foo = 4; - let test_float: F32 = 10.2; + let test_float: F32 = { + 10.2 + }; a + b + foo }