public object VisitTermAST([NotNull] TermASTContext context) { if (context.factor().Length == 1) { return(Visit(context.factor()[0])); } else if (context.factor().Length > 1) { bool allInts = context.factor().ToList().All(factor => { string type = (string)Visit(factor); if (type != "int") { InsertError(factor.Start, $"El factor '{factor.GetText()}' no es un número entero. Solo se permite el uso de '*', '/' o '%' con números enteros"); } return(type == "int"); }); return(allInts ? "int" : null); } return(null); }
public object VisitTermAST([NotNull] TermASTContext context) { Visit(context.factor(0)); for (int i = 1; i < context.factor().Length; i++) { Visit(context.factor(i)); string instruction = "BINARY_"; if (context.mulop(i - 1).GetText() == "*") { instruction += "MULTIPLY"; } else if (context.mulop(i - 1).GetText() == "/") { instruction += "DIVIDE"; } AddLine(instruction); } return(null); }