@@ -0,0 +1,1738 @@
+package semantic;%0A%0Aimport parser.*;%0Aimport java.util.*;%0A%0A/**%0A * Created by Doris on 14-2-13.%0A */%0Apublic class SemanticChecker %7B%0A    public static void start(SimpleNode root)%7B%0A        SymbolTable st = new SymbolTable();%0A%0A        for(int i=0; i %3C root.jjtGetNumChildren(); i++)%7B%0A            SimpleNode child = root.jjtGetChild(i);%0A            switch (child.getId())%7B%0A                case UcParseTreeConstants.JJTFUNCTIONDEFINITION:%0A                    checkFuncDef(child,st);%0A                    break;%0A                case UcParseTreeConstants.JJTFUNCTIONDECLARATION:%0A                    break;%0A                case UcParseTreeConstants.JJTVARIABLEDECLARATION:%0A                    break;%0A            %7D%0A        %7D%0A%0A    %7D%0A%0A%0A    public static void checkFuncDef(SimpleNode funcDef, SymbolTable st)%7B%0A%0A        //get the second child, should be identifier%0A        SimpleNode id = funcDef.jjtGetChild(1);%0A%0A        //get the name of the function%0A        String name = (String)id.jjtGetValue();%0A%0A        //insert into symbol table%0A        st.addFunction(name,funcDef);%0A%0A        //check FunctionParameters, the third child%0A        checkFuncParams(funcDef.jjtGetChild(2),st);%0A%0A        //check CompoundStatement, the 4th child%0A        checkCompStmt(funcDef.jjtGetChild(3),st);%0A%0A    %7D%0A%0A    public static void checkFuncParams(SimpleNode funcParams, SymbolTable st)%7B%0A        //only contains VariableDeclaration-s%0A%0A        for(int i=0; i%3C funcParams.jjtGetNumChildren()-1; i++)%7B%0A%0A            SimpleNode varDec = funcParams.jjtGetChild(i);%0A            checkVarDec(varDec, st);%0A        %7D%0A    %7D%0A%0A    public static void checkCompStmt(SimpleNode compStmt, SymbolTable st)%7B%0A%0A    %7D%0A%0A    public static void checkVarDec(SimpleNode varDec, SymbolTable st)%7B%0A%0A    %7D%0A%0A%7D%0A

add SemanticChecker