view ast/Stmt.d @ 11:642c6a998fd9

Support for while statements and fixed scope for if
author Anders Halager <halager@gmail.com>
date Fri, 18 Apr 2008 13:45:39 +0200
parents 2c5a8f4c254a
children ce17bea8e9bd
line wrap: on
line source

module ast.Stmt;

import ast.Exp,
       ast.Decl;

import sema.SymbolTable;

enum StmtType
{
    Stmt,
    Decl,
    Exp,
    Return,
    If,
    While,
}

class Stmt
{
    this(StmtType stmtType = StmtType.Stmt)
    {
        this.stmtType = stmtType;
    }

    StmtType stmtType;
    Scope env;
}

class ReturnStmt : Stmt
{
    this()
    {
        super(StmtType.Return);
    }

    public Exp exp;
}

class DeclStmt : Stmt
{
    this(Decl decl)
    {
        super(StmtType.Decl);
        this.decl = decl;
    }

    public Decl decl;
}

class ExpStmt : Stmt
{
    this(Exp exp)
    {
        super(StmtType.Exp);
        this.exp = exp;
    }

    public Exp exp;
}

class IfStmt : Stmt
{
    this(Exp cond, Stmt[] then, Stmt[] el = null)
    {
        super(StmtType.If);
        this.cond = cond;
        this.then_body = then;
        this.else_body = el;
    }

    Exp cond;
    Stmt[] then_body;
    Stmt[] else_body;
}

class WhileStmt : Stmt
{
    this(Exp cond, Stmt[] stmts)
    {
        super(StmtType.While);
        this.cond = cond;
        this.stmts = stmts;
    }

    Exp cond;
    Stmt[] stmts;
}