public GlobalDeclarationType(string key, TypeG type, dynamic value, TypeG kind) { this.key = key; this.type = type; this.value = value; this.kind = kind; }
public LocalDeclarationType(string key, TypeG type, dynamic value, int pos, TypeG kind) { this.key = key; this.type = type; this.value = value; this.pos = pos; this.kind = kind; }
T2K() { Type_g = new TypeG[12]; Type_t = new TypeT[12]; Diam = new int[4]; G_max = new float[4]; G_pcnt_max = new byte[4]; G_pcnt_min = new byte[4]; F_max = new float[2]; Weight = new float[2]; SysConN = new SysCon[4]; }
public TypeG Visit(ParameterDeclarationList node) { CurrentContext.paramDetect = true; Console.WriteLine("PD"); TypeG tipo = Visit((dynamic)node[0]); foreach (var i in node) { var variableName = i[0].AnchorToken.Lexeme; dynamic variableValue = false; Console.WriteLine("ROOT"); if (CurrentContext.context == "GLOBAL") { if (GloabalDeclaratonT.Contains(variableName)) { throw new SemanticError( "Duplicated variable (" + CurrentContext.context + "): " + variableName, node[0].AnchorToken); } else { GloabalDeclaratonT[variableName] = new GlobalDeclarationType(variableName, tipo, variableValue, TypeG.PARAM); } } else if (CurrentContext.context == "LOCAL") { if (ListLocalDeclarationTable[CurrentContext.index].Contains(variableName)) { throw new SemanticError( "Duplicated variable: " + variableName, node[0].AnchorToken); } else { Console.WriteLine("GUARDANDO!!!"); ListLocalDeclarationTable[CurrentContext.index][variableName] = new LocalDeclarationType(variableName, tipo, variableValue, -1, TypeG.PARAM); Console.WriteLine("TABLA" + ListLocalDeclarationTable[CurrentContext.index]); } } } //VisitChildren(node); return(TypeG.VOID); //return TypeG.VOID; }
void VisitBinaryOperator(String op, Node node, TypeG type) { Console.WriteLine("CA " + node.ToStringTree()); Console.WriteLine("F" + node[0]); Console.WriteLine("U" + node[1]); if (Visit((dynamic)node[0]) != type || Visit((dynamic)node[1]) != type) { throw new SemanticError( String.Format( "Operator {0} requires two operands of type {1}", op, type), node.AnchorToken); } }
public TypeG Visit(For node) { Console.WriteLine("FOR: " + node.ToStringTree()); TypeG varType = Visit((dynamic)node[0]); TypeG listType = Visit((dynamic)node[1]); dynamic varListType; switch (varType) { case TypeG.INTEGER: varListType = TypeG.INTEGER_LIST; break; case TypeG.STRING: varListType = TypeG.STRING_LIST; break; case TypeG.BOOLEAN: varListType = TypeG.BOOLEAN_LIST; break; default: throw new Exception($"Type {varType} has no equivalent list type"); } if (varListType != listType) { throw new SemanticError($"Incompatible types {varType} and {listType}", node[0].AnchorToken); } string key = node.AnchorToken.Lexeme; ProcedureDeclarationT[CurrentContext.procedure] = new ProcedureDeclarationType(key, TypeG.VOID, false); var lastInLoopOrFor = CurrentContext.paramDetect; //insideLoop = true; Visit((dynamic)node[2]); //insideLoop = lastInLoopOrFor; return(TypeG.VOID); }
public ProcedureDeclarationType(string key, TypeG return_type, bool is_predef) { this.key = key; this.return_type = return_type; this.is_predef = is_predef; }
public TypeG Visit(CallNode node) { Console.WriteLine("INICIO" + node.ToStringTree()); VisitChildren(node); Console.WriteLine("FIN"); var name = node.AnchorToken.Lexeme; var parametersRequired = 0; TypeG typeRequired = TypeG.VOID; TypeG typeRequired2 = TypeG.VOID; TypeG returnType = TypeG.VOID; switch (name) { case "WrInt": parametersRequired = 1; typeRequired = TypeG.INTEGER; break; case "WrStr": parametersRequired = 1; typeRequired = TypeG.STRING; break; case "WrLn": break; case "RdInt": returnType = TypeG.INTEGER; break; case "RdStr": returnType = TypeG.STRING; break; case "AtStr": parametersRequired = 2; typeRequired = TypeG.STRING; typeRequired2 = TypeG.INTEGER; returnType = TypeG.STRING; break; case "LenStr": parametersRequired = 1; typeRequired = TypeG.STRING; returnType = TypeG.INTEGER; break; case "CmpStr": parametersRequired = 2; typeRequired = TypeG.STRING; typeRequired2 = TypeG.STRING; returnType = TypeG.INTEGER; break; case "CatStr": parametersRequired = 2; typeRequired = TypeG.STRING; typeRequired2 = TypeG.STRING; returnType = TypeG.STRING; break; case "LenLstInt": parametersRequired = 1; typeRequired = TypeG.INTEGER_LIST; returnType = TypeG.INTEGER; break; case "LenLstStr": parametersRequired = 1; typeRequired = TypeG.STRING_LIST; returnType = TypeG.INTEGER; break; case "LenLstBool": parametersRequired = 1; typeRequired = TypeG.BOOLEAN_LIST; returnType = TypeG.INTEGER; break; case "NewLstInt": parametersRequired = 1; typeRequired = TypeG.INTEGER; returnType = TypeG.INTEGER_LIST; break; case "NewLstStr": parametersRequired = 1; typeRequired = TypeG.INTEGER; returnType = TypeG.STRING_LIST; break; case "NewLstBool": parametersRequired = 1; typeRequired = TypeG.INTEGER; returnType = TypeG.BOOLEAN_LIST; break; case "IntToStr": parametersRequired = 1; typeRequired = TypeG.INTEGER; returnType = TypeG.STRING; break; case "StrToInt": parametersRequired = 1; typeRequired = TypeG.STRING; returnType = TypeG.INTEGER; break; default: throw new Exception($"Function {name} has no declared call"); } if (parametersRequired > 0) { dynamic tipo = Visit((dynamic)node[0]); if (node.getLength() == parametersRequired) { if (typeRequired == tipo) { return(returnType); } else { throw new SemanticError($"No type match for Call: " + $"expected {typeRequired} but got {tipo}", node.AnchorToken); } } else { throw new SemanticError($"Wrong number of params to procedure call: " + $"expected {parametersRequired} but got {node.getLength()}", node.AnchorToken); } } return(TypeG.VOID); }
public TypeG Visit(ParameterDeclaration node) { Console.WriteLine("PD"); TypeG tipo = Visit((dynamic)node); foreach (var i in node) { var variableName = i.AnchorToken.Lexeme; dynamic variableValue = false; Console.WriteLine("ROOT"); if (CurrentContext.context == "GLOBAL") { if (GloabalDeclaratonT.Contains(variableName)) { throw new SemanticError( "Duplicated variable (" + CurrentContext.context + "): " + variableName, node[0].AnchorToken); } else { GloabalDeclaratonT[variableName] = new GlobalDeclarationType(variableName, TypeG.INTEGER, variableValue, TypeG.PARAM); } } else if (CurrentContext.context == "LOCAL") { if (ListLocalDeclarationTable[CurrentContext.index].Contains(variableName)) { throw new SemanticError( "Duplicated variable: " + variableName, node[0].AnchorToken); } else { Console.WriteLine("GUARDANDO!!!"); ListLocalDeclarationTable[CurrentContext.index][variableName] = new LocalDeclarationType(variableName, TypeG.INTEGER, variableValue, -1, TypeG.PARAM); } } } //VisitChildren(node); return(TypeG.VOID); /*var variableName = i.AnchorToken.Lexeme; * dynamic variableValue = false; * * if (CurrentContext.context == "GLOBAL") * { * if (GloabalDeclaratonT.Contains(variableName)) * { * throw new SemanticError( * "Duplicated variable (" + CurrentContext.context + "): " + variableName, * node[0].AnchorToken); * } * else * { * GloabalDeclaratonT[variableName] = * new GlobalDeclarationType(variableName, TypeG.INTEGER, variableValue, TypeG.VAR); * } * } * else if (CurrentContext.context == "LOCAL") * { * if (ListLocalDeclarationTable[CurrentContext.index].Contains(variableName)) * { * throw new SemanticError( * "Duplicated variable: " + variableName, * node[0].AnchorToken); * } * else * { * * ListLocalDeclarationTable[CurrentContext.index][variableName] = new LocalDeclarationType(variableName, TypeG.INTEGER, variableValue, -1, TypeG.VAR); * } * } * //Console.WriteLine("FIN");*/ VisitChildren(node); return(TypeG.VOID); }
public TypeG Visit(VariableDeclarationList node) { foreach (var n in node) { TypeG tipo = Visit((dynamic)n); foreach (var i in n) { var variableName = i.AnchorToken.Lexeme; dynamic variableValue = false; switch (tipo) { case TypeG.BOOLEAN: variableValue = false; break; case TypeG.INTEGER: variableValue = 0; break; case TypeG.STRING: variableValue = ""; break; case TypeG.INTEGER_LIST: variableValue = new int[] { 0 }; break; case TypeG.BOOLEAN_LIST: variableValue = new bool[] { false }; break; case TypeG.STRING_LIST: variableValue = new string[] { "" }; break; default: throw new Exception($"Type {tipo} wasn't found"); } if (CurrentContext.context == "GLOBAL") { if (GloabalDeclaratonT.Contains(variableName)) { throw new SemanticError( "Duplicated variable (" + CurrentContext.context + "): " + variableName, n[0].AnchorToken); } else { GloabalDeclaratonT[variableName] = new GlobalDeclarationType(variableName, TypeG.INTEGER, variableValue, TypeG.VAR); } } else if (CurrentContext.context == "LOCAL") { if (ListLocalDeclarationTable[CurrentContext.index].Contains(variableName)) { throw new SemanticError( "Duplicated variable: " + variableName, n[0].AnchorToken); } else { ListLocalDeclarationTable[CurrentContext.index][variableName] = new LocalDeclarationType(variableName, TypeG.INTEGER, variableValue, -1, TypeG.VAR); } } } } //VisitChildren(node); return(TypeG.VOID); }