Exemplo n.º 1
0
        void BuildOperand(ExpressionBuilder builder)
        {
            //literal or identifier
            if (Accept (Category.Literal_Integer,
                        Category.Literal_String,
                        Category.Identifier)) {
                builder.Offer(accepted);

            //nested expression
            } else if (Accept (Category.Left_Bracket)) {
                builder.Offer(accepted);
                BuildExpression (builder);
                Expect (Category.Rigth_Bracket);
                builder.Offer (accepted);
            } else {
                errors.AddError(token, ErrorType.SyntaxError, "Expecting an operand");
            }
        }
Exemplo n.º 2
0
 Expression ParseExpression(ISet<Category> follow, ISet<Category> starters)
 {
     ExpressionBuilder builder = new ExpressionBuilder(errors);
     BuildExpression(builder);
     return builder.Build();
 }
Exemplo n.º 3
0
 void BuildExpression(ExpressionBuilder builder)
 {
     if (Accept (Category.Unary_Operator)) {
         builder.Offer(accepted);
         BuildOperand (builder);
     } else {
         BuildOperand (builder);
         if (Accept (Category.Binary_Operator)) {
             builder.Offer(accepted);
             BuildOperand (builder);
         }
     }
 }