public Statement Parse(LoonyParser parser, LoonyToken token, out bool trailingSemicolon) { trailingSemicolon = true; var name = parser.Take(LoonyTokenType.Identifier).Contents; TypeBase type = null; Expression initializer = null; if (parser.MatchAndTake(LoonyTokenType.Colon)) { type = parser.ParseType(); } if (type == null) { parser.Take(LoonyTokenType.Assign); initializer = parser.ParseExpression(); } else if (parser.MatchAndTake(LoonyTokenType.Assign)) { initializer = parser.ParseExpression(); } return(new VariableStatement(token, parser.Previous, name, type, initializer)); }
public Statement Parse(LoonyParser parser, LoonyToken token, out bool trailingSemicolon) { trailingSemicolon = true; var value = parser.ParseExpression(); return new ReturnStatement(token, parser.Previous, value); }
public Expression Parse(LoonyParser parser, LoonyToken token) { var expression = parser.ParseExpression(); parser.Take(LoonyTokenType.RightParen); return(expression); }
public Statement Parse(LoonyParser parser, LoonyToken token, out bool trailingSemicolon) { trailingSemicolon = true; var value = parser.ParseExpression(); return(new ReturnStatement(token, parser.Previous, value)); }
public Statement Parse(LoonyParser parser, LoonyToken token, out bool trailingSemicolon) { trailingSemicolon = true; var name = parser.Take(LoonyTokenType.Identifier).Contents; TypeBase type = null; Expression initializer = null; if (parser.MatchAndTake(LoonyTokenType.Colon)) type = parser.ParseType(); if (type == null) { parser.Take(LoonyTokenType.Assign); initializer = parser.ParseExpression(); } else if (parser.MatchAndTake(LoonyTokenType.Assign)) { initializer = parser.ParseExpression(); } return new VariableStatement(token, parser.Previous, name, type, initializer); }
public Expression Parse(LoonyParser parser, Expression left, LoonyToken token) { var right = parser.ParseExpression(Precedence - (_isRight ? 1 : 0)); return new BinaryOperatorExpression(token, left, right); }
public Expression Parse(LoonyParser parser, LoonyToken token) { var expression = parser.ParseExpression(); parser.Take(LoonyTokenType.RightParen); return expression; }
public Expression Parse(LoonyParser parser, Expression left, LoonyToken token) { var right = parser.ParseExpression(Precedence - (_isRight ? 1 : 0)); return(new BinaryOperatorExpression(token, left, right)); }