/// <summary> /// 左結合のために、Exp2を分割したもの /// </summary> /// <param name="lhs">パース済みの左辺項</param> Ast.Exp parseExp2Rest(Ast.Exp lhs) { var t = currentToken(); if (t.Type == TokenType.Star || t.Type == TokenType.Slash) { var binopType = BinOpMap[t.Type]; progress(); var rhs = parseValue(); if (rhs == null) { throw new Exception("No rhs parsed"); } var exp = new Ast.BinOp(binopType, lhs, rhs); return(parseExp2Rest(exp)); } else { return(lhs); } }
/// <summary> /// 左結合のために、Exp1を分割したもの /// </summary> /// <param name="lhs">パース済みの左辺項</param> Ast.Exp parseExp0Rest(Ast.Exp lhs) { var t = currentToken(); if (t.Type == TokenType.Less || t.Type == TokenType.LessEqual || t.Type == TokenType.Greater || t.Type == TokenType.GreaterEqual || t.Type == TokenType.EqualEqual) { var binopType = BinOpMap[t.Type]; progress(); var rhs = parseExp1(); if (rhs == null) { throw new Exception("No rhs parsed"); } var exp = new Ast.BinOp(binopType, lhs, rhs); return(parseExp0Rest(exp)); } else { return(lhs); } }