private ArrayList<SymTabEntry> parseParmSublist(Token token, SymTabEntry routineId) throws Exception { // name = main, definition == function Definition parmDefn = null; TokenType tokenType = token.getType(); parmDefn = VALUE_PARM; SymTabEntry sublist = null; if (tokenType == INT) { IntDeclarationsParser intDeclarationsParser = new IntDeclarationsParser(this); intDeclarationsParser.setDefinition(parmDefn); token = nextToken(); sublist = intDeclarationsParser.parseIdentifier(token); sublist.setTypeSpec(integerType); } else if (tokenType == CHAR) { IntDeclarationsParser intDeclarationsParser = new IntDeclarationsParser(this); intDeclarationsParser.setDefinition(parmDefn); token = nextToken(); sublist = intDeclarationsParser.parseIdentifier(token); sublist.setTypeSpec(charType); } token = nextToken(); token = currentToken(); if (token.getType() == COMMA) { token = nextToken(); } tokenType = token.getType(); token = synchronize(PARAMETER_SET); ArrayList<SymTabEntry> SC = new ArrayList<SymTabEntry>(); SC.add(sublist); return SC; }
public SymTabEntry parse(Token token, SymTabEntry parentId) throws Exception { Token FunctionReturnToken = token; Definition routineDefn = null; String dummyName = null; SymTabEntry routineId = null; TokenType routineType = token.getType(); // Initialize. switch ((WookieTokenType) routineType) { case INT: { // save the int data type for use later FunctionReturnToken = token; token = nextToken(); // consume Int routineDefn = DefinitionImpl.FUNCTION; dummyName = "DummyProgramName".toLowerCase() + String.format("%03d", ++dummyCounter); break; } case CHAR: { // save the char data type for use later FunctionReturnToken = token; token = nextToken(); // consume Char routineDefn = DefinitionImpl.FUNCTION; dummyName = "DummyProgramName".toLowerCase() + String.format("%03d", ++dummyCounter); break; } case VOID: { // save the void data type for use later FunctionReturnToken = token; token = nextToken(); // consume PROGRAM routineDefn = DefinitionImpl.PROCEDURE; dummyName = "DummyProgramName".toLowerCase() + String.format("%03d", ++dummyCounter); break; } default: { routineDefn = DefinitionImpl.PROGRAM; dummyName = "DummyProgramName".toLowerCase(); break; } } // Parse the routine name. routineId = parseRoutineName(token, dummyName); routineId.setDefinition(routineDefn); token = currentToken(); // Create new intermediate code for the routine. ICode iCode = ICodeFactory.createICode(); routineId.setAttribute(ROUTINE_ICODE, iCode); routineId.setAttribute(ROUTINE_ROUTINES, new ArrayList<SymTabEntry>()); SymTab symTab = symTabStack.push(); routineId.setAttribute(ROUTINE_SYMTAB, symTab); ((SymTabImpl) symTab).setfuncName(routineId.getName()); parseFormalParameters(token, routineId); token = currentToken(); if (FunctionReturnToken.getType() == INT) { routineId.setTypeSpec(integerType); } else if (FunctionReturnToken.getType() == CHAR) { routineId.setTypeSpec(charType); } // Parse the routine's block declaration. if (token.getType() == LEFT_BRACE) { routineId.setAttribute(ROUTINE_CODE, DECLARED); BlockParser blockParser = new BlockParser(this); ICodeNode rootNode = blockParser.parse(token, routineId); iCode.setRoot(rootNode); } ArrayList<SymTabEntry> subroutines = (ArrayList<SymTabEntry>) parentId.getAttribute(ROUTINE_ROUTINES); subroutines.add(routineId); // Pop the routine's symbol table off the stack. symTabStack.pop(); return routineId; }