public MethodSymbol AddMethod(IdentToken token, Type type, FormalParamSymbol[] formalParams, MethodInfo methodInfo) { MethodSymbol result = new MethodSymbol(token, type, formalParams, methodInfo); symbolTable.Peek().Add(token.value, result); return(result); }
public LocalVarSymbol AddLocalVar(IdentToken token, LocalBuilder localBuilder) { LocalVarSymbol result = new LocalVarSymbol(token, localBuilder); symbolTable.Peek().Add(token.value, result); return(result); }
public FormalParamSymbol AddFormalParam(IdentToken token, Type type, ParameterBuilder parameterInfo) { FormalParamSymbol result = new FormalParamSymbol(token, type, parameterInfo); symbolTable.Peek().Add(token.value, result); return(result); }
public FieldSymbol AddField(IdentToken token, FieldInfo field) { FieldSymbol result = new FieldSymbol(token, field); fieldScope.Add(token.value, result); return(result); }
// [1] Program = {UsingClause} 'class' Ident '{' {FieldDecl | MethodDecl} '}'. public bool IsProgram() { while (IsUsingClause()) { ; } if (!CheckKeyword("class")) { Error("Очаквам ключова дума 'class'"); } IdentToken id = token as IdentToken; if (!CheckIdent()) { Error("Очаквам идентификатор"); } symbolTable.AddToUniverse(new PrimitiveTypeSymbol(id, emit.InitProgramClass(id.value))); if (!CheckSpecialSymbol("{")) { Error("Очаквам специален символ '{'"); } while (IsFieldDeclOrMethodDecl()) { ; } if (!CheckSpecialSymbol("}")) { Error("Очаквам специален символ '}'"); } Debug.WriteLine(symbolTable.ToString()); return(diag.GetErrorCount() == 0); }
// [7] Type = 'int' | 'bool' | 'double' | 'char' | 'string' | 'void' | 'object' | Ident. public bool IsType(out Type type) { // if (CheckKeyword("int")) { // type = typeof(System.Int32); // return true; // } // if (CheckKeyword("bool")) { // type = typeof(System.Boolean); // return true; // } // if (CheckKeyword("double")) { // type = typeof(System.Double); // return true; // } // if (CheckKeyword("char")) { // type = typeof(System.Char); // return true; // } // if (CheckKeyword("string")) { // type = typeof(System.String); // return true; // } if (CheckKeyword("object")) { type = typeof(System.Object); return(true); } if (CheckKeyword("void")) { type = typeof(void); return(true); } IdentToken typeIdent = token as IdentToken; if (typeIdent != null) { TypeSymbol ts = symbolTable.GetSymbol(typeIdent.value) as TypeSymbol; if (ts != null) { type = ts.type; } else { type = symbolTable.ResolveExternalType(typeIdent.value); } if (type != null) { ReadNextToken(); return(true); } } type = null; return(false); }
// [9] Location = Ident | Ident '[' Expression ']'. public bool IsLocation(out LocationInfo location) { IdentToken id = token as IdentToken; Type type; if (!CheckIdent()) { location = null; return(false); } location = new LocationInfo(); location.id = symbolTable.GetSymbol(id.value); // Семантична грешка - деклариран ли е вече идентификатора? if (location.id == null) { Error("Недеклариран идентификатор {0}", id, id.value); } FieldSymbol fs = location.id as FieldSymbol; if (fs != null) { if (CheckSpecialSymbol("[")) { // Emit emit.AddLoadArray(fs.fieldInfo); if (!IsExpression(null, out type)) { Error("Очаквам израз"); } if (!CheckSpecialSymbol("]")) { Error("Очаквам специален символ ']'"); } if (!(type == typeof(System.Int32))) { Error("Типа на индекса трябва да е Integer"); } location.isArray = true; } } return(true); }
public PrimitiveTypeSymbol(IdentToken token, Type type) : base(token, type) { }
public FormalParamSymbol(IdentToken token, Type paramType, ParameterBuilder parameterInfo) : base(token.line, token.column, token.value) { this.paramType = paramType; this.parameterInfo = parameterInfo; }
public FieldSymbol(IdentToken token, FieldInfo fieldInfo) : base(token.line, token.column, token.value) { this.fieldInfo = fieldInfo; }
public MethodSymbol(IdentToken token, Type returnType, FormalParamSymbol[] formalParams, MethodInfo methodInfo) : base(token.line, token.column, token.value) { this.returnType = returnType; this.formalParams = formalParams; this.methodInfo = methodInfo; }
public TypeSymbol(IdentToken token, Type type) : base(token.line, token.column, token.value) { this.type = type; }
public ExternalMethodSymbol(IdentToken token, MethodInfo[] methodInfo) : base(token.line, token.column, token.value) { this.methodInfo = methodInfo; }
public LocalVarSymbol(IdentToken token, LocalVariableInfo localVariableInfo) : base(token.line, token.column, token.value) { this.localVariableInfo = localVariableInfo; }