public override EExpressionType VisitNum_expr([NotNull] GrammarParser.Num_exprContext context) { if (context.ChildCount == 1) { var element = context.GetChild(0).GetText(); int result = 0; if (int.TryParse(element, out result)) { return(EExpressionType.Int); } else { element = LookUp(element); if (int.TryParse(element, out result)) { return(EExpressionType.Int); } } float result2 = 0; if (float.TryParse(element, out result2)) { return(EExpressionType.Float); } else { element = LookUp(element); if (float.TryParse(element, out result2)) { return(EExpressionType.Float); } } return(EExpressionType.Unknown); } else if (context.ChildCount == 3) { var lhs = context.GetChild(0); var lhsType = Visit(lhs); var rhs = context.GetChild(2); var rhsType = Visit(rhs); if (lhsType != rhsType) { throw new Exception("Type missmatch"); } } else { throw new NotImplementedException("Grammar has changed!"); } return(base.VisitNum_expr(context)); }
public override void EnterNum_expr([NotNull] GrammarParser.Num_exprContext context) { if (context.ChildCount == 1) { if (!(int.TryParse(context.GetChild(0).GetText(), out var result))) { LookUpScope(context.GetChild(0).GetText()); } } base.EnterNum_expr(context); }
public override bool VisitNum_expr([NotNull] GrammarParser.Num_exprContext context) { Console.WriteLine($"Numeric Expression {context.GetText()}"); if (context.ChildCount == 1) { string expression = SearchAndReplace(context.GetChild(0).GetText()); try { var test = float.Parse(expression); Console.WriteLine("Succesfully accepted!"); } catch (Exception) { Console.WriteLine("Error man"); } } else { } return(base.VisitNum_expr(context)); }
/// <summary> /// Exit a parse tree produced by <see cref="GrammarParser.num_expr"/>. /// <para>The default implementation does nothing.</para> /// </summary> /// <param name="context">The parse tree.</param> public virtual void ExitNum_expr([NotNull] GrammarParser.Num_exprContext context) { }
/// <summary> /// Visit a parse tree produced by <see cref="GrammarParser.num_expr"/>. /// <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 VisitNum_expr([NotNull] GrammarParser.Num_exprContext context) { return(VisitChildren(context)); }