public override void EnterVar_decl([NotNull] GrammarParser.Var_declContext context) { var variableName = context.GetChild(1).GetText(); var expression = context.GetChild(3).GetText(); Console.WriteLine(context.GetChild(3).GetText()); if (!LookUpScope(variableName)) { currentScope.SymbolTable.Add(variableName, expression); } else { throw new Exception("Variable already exists in local or parent scopes!"); } base.EnterVar_decl(context); }
public override bool VisitVar_decl([NotNull] GrammarParser.Var_declContext context) { Console.WriteLine("Variable Declaration "); DataTable dt = new DataTable(); string expression = context.GetChild(3).GetText(); expression = SearchAndReplace(expression); /* * if ((!MainScopeClass.MainScope.ContainsKey(context.GetChild(1).GetText()))) * { * if ((!MainScopeClass.MainScope.ContainsKey(context.GetChild(1).GetText()))) * { * MainScopeClass.MainScope.Add(context.GetChild(1).GetText(), dt.Compute(expression, "")); * Console.WriteLine($"HERE: {context.GetChild(1).GetText()} {dt.Compute(expression, "")}"); * } * else * { * //Something * * } * * } * else * { * throw new Exception("Variable already exists!"); * } */ if (scopeCount != 0) { scopeCount--; } if (scopeCount == 0) { //Something? } return(base.VisitVar_decl(context)); }
/// <summary> /// Exit a parse tree produced by <see cref="GrammarParser.var_decl"/>. /// <para>The default implementation does nothing.</para> /// </summary> /// <param name="context">The parse tree.</param> public virtual void ExitVar_decl([NotNull] GrammarParser.Var_declContext context) { }
/// <summary> /// Visit a parse tree produced by <see cref="GrammarParser.var_decl"/>. /// <para> /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/> /// on <paramref name="context"/>. /// </para> /// </summary> /// <param name="context">The parse tree.</param> /// <return>The visitor result.</return> public virtual Result VisitVar_decl([NotNull] GrammarParser.Var_declContext context) { return(VisitChildren(context)); }