private Node ParseClassDeclaration() { Token t = lexer.GetNext(); List <string> modifiers = new List <string>(); if (t.value == "public" || t.value == "private" || t.value == "protected") { modifiers.Add(t.value); t = lexer.GetNext(); } if (t.value == "abstract" || t.value == "static") { modifiers.Add(t.value); t = lexer.GetNext(); } if (t.value == "class") { var f = ParseFactor(); if (f is NodeIdentifier) { NodeIdentifier identifier = (NodeIdentifier)f; identifier.type = "class"; return(new NodeClassDeclaration() { modifiers = modifiers, identifier = identifier, body = ParseClassBody() }); } } if (modifiers.Count == 0) { lexer.PutBack(t); } return(new NodeError()); }
private Node ParseParameter() { Token t = lexer.GetNext(); if (t.type == TokenType.VARTYPE) { var f = ParseFactor(); if (f is NodeIdentifier) { NodeIdentifier identifier = (NodeIdentifier)f; identifier.type = t.value; try { varDictionary.Add(identifier.name, identifier); } catch { Console.WriteLine("ERROR: Identifier " + identifier.name + " is already declarated"); return(new NodeParameter() { identifier = identifier }); } return(new NodeParameter() { identifier = identifier }); } return(new NodeError()); } lexer.PutBack(t); return(null); }
private ResType DefineResType(Node operand) { if (operand is NodeBinaryOp) { NodeBinaryOp o = (NodeBinaryOp)operand; return(o.resType); } if (operand is NodeUnaryOp) { NodeUnaryOp o = (NodeUnaryOp)operand; return(o.resType); } if (operand is NodeBoolLiteral) { return(ResType.BOOL); } if (operand is NodeIntLiteral || operand is NodeFloatLiteral || operand is NodeDoubleLiteral) { return(ResType.NUM); } if (operand is NodeStringLiteral) { return(ResType.STRING); } if (operand is NodeCharLiteral) { return(ResType.CHAR); } if (operand is NodeIdentifier) { NodeIdentifier ni = (NodeIdentifier)operand; if (ni.type == "int" || ni.type == "float" || ni.type == "double") { return(ResType.NUM); } if (ni.type == "bool") { return(ResType.BOOL); } if (ni.type == "string") { return(ResType.STRING); } if (ni.type == "char") { return(ResType.CHAR); } return(ResType.IDENTIFIER); } return(ResType.ERROR); }