//----------------------------------------------------------- public void Visit(NVarDef node) { Console.WriteLine($"+++++++++++++++ NVARDEF ++++++++++++++++"); var variableName = node.AnchorToken.Lexeme; //Console.WriteLine($"variable: {variableName}"); if (pasones == 0) { if (globVars.Contains(variableName)) { throw new SemanticError( "Duplicated variable: " + variableName, node.AnchorToken); } else { //Console.WriteLine($"Agregando Variable: {variableName} "); globVars.Add(variableName); } } else if (pasones == 1) { if (Table[nombreFuncion].locTable.ContainsKey(node.AnchorToken.Lexeme)) { throw new SemanticError("parameter and local variable names have to be unique on function: " + nombreFuncion, node.AnchorToken); } Sharmuta sha = new Sharmuta(node.AnchorToken.Lexeme, false, null); Table[nombreFuncion].locTable[node.AnchorToken.Lexeme] = sha; } }
public string Visit(NVarDef nVarDef) { string lexeme = nVarDef.AnchorToken.Lexeme; if (currentFunction == null) // Global variable { return("\t.field public static int64 '" + lexeme + "'\n"); } else // Local variable { return("\t\t.locals init (int64 '" + lexeme + "')\n"); } }
// Appends NVarDef to nVarDefList public void VarDef(NVarDefList nVarDefList) { NVarDef nVarDef = new NVarDef(); Expect(TokenCategory.VAR); nVarDef.AnchorToken = Expect(TokenCategory.IDENTIFIER); nVarDefList.Add(nVarDef); while (CurrentToken == TokenCategory.COMMA) { Expect(TokenCategory.COMMA); NVarDef otherNVarDef = new NVarDef(); otherNVarDef.AnchorToken = Expect(TokenCategory.IDENTIFIER); nVarDefList.Add(otherNVarDef); } Expect(TokenCategory.SEMICOLON); }