//----------------------------------------------------------- public void Visit(Programme node) { //Primera Pasada foreach (var n in node) { if (n is FunctionDef) { var funName = n.AnchorToken.Lexeme; if (Table.Contains(funName)) { throw new SemanticError( "Duplicated function: " + funName, n.AnchorToken); } else { int num = n[0].CountChildren(); Table[funName] = new Values("u", num, new SymbolTableLocal()); } } else { var size = n.CountChildren(); for (int i = 0; i < size; i++) { var varName = n[i].AnchorToken.Lexeme; if (GlobalVars.Contains(varName)) { throw new SemanticError( "Duplicated variable: " + varName, n[i].AnchorToken); } else { GlobalVars.Add(varName); } } } } // Revisar si no existe el método main if (!Table.Contains("main")) { throw new SemanticError( "Te pasaste de lanza, no hay main. \n Atte: Junco"); } //Segunda Pasada foreach (var n in node) { if (n is FunctionDef) { Visit((dynamic)n); } } }
private void AddGlobalsInlineDef(Antlr4.Runtime.ParserRuleContext ruleContext) { // CONSTANTS var allConsts = ruleContext.GetRuleContexts <DaedalusParser.ConstDefContext>(); foreach (var c in allConsts) { foreach (var cv in c.constValueDef()) { GlobalConsts.Add(new Constant { Column = cv.Start.Column, Line = cv.Start.Line, Name = cv.nameNode().GetText(), Type = c.typeReference().GetText(), Value = cv.constValueAssignment().expressionBlock().GetText(), }); } } // VARIABLES var allVarDecls = ruleContext.GetRuleContexts <DaedalusParser.VarDeclContext>(); foreach (var v in allVarDecls) { foreach (var vals in v.varValueDecl()) { GlobalVars.Add(new Variable { Name = vals.nameNode().GetText(), Type = v.typeReference().GetText(), Line = vals.nameNode().Start.Line, Column = vals.nameNode().Start.Column }); } foreach (var innerVarDecl in v.varDecl()) { foreach (var vals in v.varValueDecl()) { GlobalVars.Add(new Variable { Name = vals.nameNode().GetText(), Type = v.typeReference().GetText(), Line = vals.nameNode().Start.Line, Column = vals.nameNode().Start.Column }); } } } }
public ConnectionSegment(int indentCount, Queue queue) : base(indentCount) { Name = $"{queue.StorageAccount}_queue"; Requires.Add("var azure = require('azure-storage');"); DependsOnModules.Add("\"azure-storage\": \"2.10.2\""); GlobalVars.Add($"var {queue.StorageAccount}_queue;"); Methods.Add(connect .Replace("#storage-account", queue.StorageAccount) .Replace("#connection-string", queue.ConnectionString) ); }
public ConnectionSegement(int indentCount, Sql sql) : base(indentCount) { Name = $"{sql.DbName}_connection"; GlobalVars.Add($"var {sql.DbName}_connection;"); GlobalVars.Add($"var {sql.DbName}_connected = false;"); Requires.Add("var TYPES = require('tedious').TYPES;"); DependsOnModules.Add("\"tedious\": \"5.0.3\""); Methods.Add(connect .Replace("#username", sql.Username) .Replace("#password", sql.Password) .Replace("#connectinString", sql.ConnectinString) .Replace("#database", sql.DbName)); }
public void AddVar(Lexeme nameToken, Node node, ErrorHandler errorHandler, bool global = false) { if (FindName(nameToken) != null) { if (!GlobalVars.Contains(nameToken.Value)) { errorHandler.AddMessage(Severity.Error, $"Duplicate declaration of variable '{nameToken.Value}'", nameToken); } return; } Vars.Add(nameToken.Value, node); if (global) { GlobalVars.Add(nameToken.Value); } }
public void GlobalVarDef(GlobalVarDef e) { e.Value.Visit(this); e.ExpType = e.Value.ExpType; GlobalVars.Add(e.Name, e.Value.ExpType); }