Expression factor() { Expression e; Token temp = next; switch (t) { case TokenKind.Real: e = new Constant(((Real)next).value, next.line, next.col); move(); return(e); case TokenKind.StringLiteral: e = new Constant(((StringLiteral)next).value, next.line, next.col); move(); return(e); case TokenKind.Identifier: if (peek().t == TokenKind.OpeningParenthesis) { string str = next.lexeme; if (!Context.Resources.FunctionExists(str)) { error(Error.UnknownFunction, str); } move(); move(); List <Expression> exprs = new List <Expression>(); if (t != TokenKind.ClosingParenthesis && t != TokenKind.Eof) { exprs.Add(expr()); } while (t == TokenKind.Comma) { move(); exprs.Add(expr()); } match(Token.ClosingParenthesis); IFunction f = Context.Resources.GetFunction(str); if ((f.Argc != -1 && exprs.Count != f.Argc) || exprs.Count > 16) { error(Error.WrongArgumentNumber); } return(new Call(f, exprs.ToArray(), temp.line, temp.col)); } else { Expression x = new Id(next.lexeme, next.line, next.col); move(); return(x); } case TokenKind.OpeningParenthesis: move(); e = new Grouping(expr(), next.line, next.col); match(Token.ClosingParenthesis, Error.UnexpectedSymbolInExpression); return(e); default: throw new ProgramError(Error.UnexpectedSymbolInExpression, ErrorSeverity.CompilationError, next.line, next.col); } }
public abstract void VisitGrouping(Grouping expression);
public abstract void VisitGrouping(Grouping expression);
Expression factor() { Expression e; Token temp = next; switch (t) { case TokenKind.Real: e = new Constant(((Real)next).value, next.line, next.col); move(); return e; case TokenKind.StringLiteral: e = new Constant(((StringLiteral)next).value, next.line, next.col); move(); return e; case TokenKind.Identifier: if (peek().t == TokenKind.OpeningParenthesis) { string str = next.lexeme; if (!Context.Resources.FunctionExists(str)) { error(Error.UnknownFunction, str); } move(); move(); List<Expression> exprs = new List<Expression>(); if (t != TokenKind.ClosingParenthesis && t != TokenKind.Eof) { exprs.Add(expr()); } while (t == TokenKind.Comma) { move(); exprs.Add(expr()); } match(Token.ClosingParenthesis); IFunction f = Context.Resources.GetFunction(str); if ((f.Argc != -1 && exprs.Count != f.Argc) || exprs.Count > 16) error(Error.WrongArgumentNumber); return new Call(f, exprs.ToArray(), temp.line, temp.col); } else { Expression x = new Id(next.lexeme, next.line, next.col); move(); return x; } case TokenKind.OpeningParenthesis: move(); e = new Grouping(expr(), next.line, next.col); match(Token.ClosingParenthesis, Error.UnexpectedSymbolInExpression); return e; default: throw new ProgramError(Error.UnexpectedSymbolInExpression, ErrorSeverity.CompilationError, next.line, next.col); } }