Example #1
0
        private void SemanticCheck(IfStatement ast, CompilerContext context)
        {
            var val = expressionTyper.TypeExpression(ast.Condition, context);

            if (val != WhileType.BOOL)
            {
                throw new SignatureException($"invalid condition type {ast.Condition.Dump("")} at {ast.Position}");
            }
            ast.CompilerScope = context.CurrentScope;

            context.OpenNewScope();
            SemanticCheck(ast.ThenStmt);
            context.CloseScope();

            context.OpenNewScope();
            SemanticCheck(ast.ElseStmt);
            context.CloseScope();
        }
Example #2
0
 private void SemanticCheck(SequenceStatement ast, CompilerContext context)
 {
     context.OpenNewScope();
     ast.CompilerScope = context.CurrentScope;
     for (int i = 0; i < ast.Count; i++)
     {
         Statement stmt = ast.Get(i);
         SemanticCheck(stmt, context);
     }
     context.CloseScope();
 }
Example #3
0
        private void SemanticCheck(WhileStatement ast, CompilerContext context)
        {
            WhileType cond = expressionTyper.TypeExpression(ast.Condition, context);

            if (cond != WhileType.BOOL)
            {
                throw new SignatureException($"invalid condition type {ast.Condition.Dump("")} at {ast.Position.ToString()}");
            }
            ast.CompilerScope = context.CurrentScope;

            context.OpenNewScope();
            SemanticCheck(ast.BlockStmt, context);
            context.CloseScope();
        }