private static bool ClassMemberDeclaration() { if (Tokens.GetToken().lexeme != "public" && Tokens.GetToken().lexeme != "private") { parameters = ""; methodSize = 0; return(ConstructorDeclaration()); } accessMod = Tokens.GetToken().lexeme; Tokens.NextToken(); if (!type()) { SyntaxError(Tokens.GetToken(), "a type"); return(false); } if (semanticPass) { SemanticActions.tExist(); } Tokens.NextToken(); if (Tokens.GetToken().type != Token.Type.Identifier) { SyntaxError(Tokens.GetToken(), "identifer"); } currentIdentifier = Tokens.GetToken().lexeme; identifierToken = Tokens.GetToken(); if (semanticPass) { SemanticActions.dup(identifierToken, scope); } Tokens.NextToken(); Symbol symbol = null; if (Tokens.GetToken().lexeme == "[") { currentType = "@" + currentType; } if (Tokens.GetToken().lexeme == "[" || Tokens.GetToken().lexeme == "=" || Tokens.GetToken().lexeme == ";") { string[] data = new string[2]; data[0] = "returnType:" + currentType; data[1] = "accessMod:" + accessMod; symbol = new Symbol(scope, ("V" + uniqueCounter++), currentIdentifier, "ivar", data); SymbolTable.Add(symbol); if (!semanticPass) { memberVariables.Add(symbol.symid); } classSize += symbol.size; } identifierSymbol = symbol; if (!FieldDeclaration()) { SyntaxError(Tokens.GetToken(), "field declaration"); } accessMod = "public"; return(true); }
private static bool Parameter() { if (!type()) { return(false); } if (semanticPass) { SemanticActions.tExist(); } Tokens.NextToken(); if (Tokens.GetToken().type != Token.Type.Identifier) { SyntaxError(Tokens.GetToken(), "identifer"); } identifierToken = Tokens.GetToken(); if (semanticPass) { SemanticActions.dup(identifierToken, (scope + "." + currentIdentifier)); } if (Tokens.PeekToken().lexeme == "[") { currentType = "@" + currentType; } parameters += "P" + uniqueCounter; string[] data = new string[2]; data[0] = "returnType:" + currentType; data[1] = "accessMod:" + accessMod; Symbol symbol = new Symbol((scope + "." + currentIdentifier), ("P" + uniqueCounter++), Tokens.GetToken().lexeme, "Param", data); Tokens.NextToken(); if (Tokens.GetToken().lexeme == "[") { Tokens.NextToken(); if (Tokens.GetToken().lexeme != "]") { SyntaxError(Tokens.GetToken(), "]"); } Tokens.NextToken(); } SymbolTable.Add(symbol); return(true); }
private static bool VariableDeclaration() { if (Tokens.PeekToken().type != Token.Type.Identifier) { return(false); } if (!type()) { return(false); } if (semanticPass) { SemanticActions.tExist(); } Tokens.NextToken(); currentIdentifier = Tokens.GetToken().lexeme; identifierToken = Tokens.GetToken(); Tokens.NextToken(); if (Tokens.GetToken().lexeme == "[") { Tokens.NextToken(); currentType = "@" + currentType; if (Tokens.GetToken().lexeme != "]") { SyntaxError(Tokens.GetToken(), "]"); } Tokens.NextToken(); } string[] data = new string[2]; data[0] = "returnType:" + currentType; data[1] = "accessMod:" + accessMod; Symbol symbol = new Symbol(scope, ("L" + uniqueCounter++), currentIdentifier, "lvar", data); identifierSymbol = symbol; if (semanticPass) { SemanticActions.dup(identifierToken, scope); SemanticActions.vPush(symbol, identifierToken, scope); } SymbolTable.Add(symbol); if (Tokens.GetToken().lexeme == "=") { if (semanticPass) { SemanticActions.oPush(Tokens.GetToken()); } Tokens.NextToken(); if (!AssignmentExpression()) { SyntaxError(Tokens.GetToken(), "assignment expression"); } } if (Tokens.GetToken().lexeme != ";") { SyntaxError(Tokens.GetToken(), ";"); } if (semanticPass) { SemanticActions.EOE(); } Tokens.NextToken(); return(true); }