示例#1
0
        public override bool CreateNonTerminal(Lexer lex, ProductionStorage ps)
        {
            Mex1 m1;
            if (ps.MatchProduction<Mex1>(out m1))
            {
                result = m1;

                //( operator mex-1 | operand * operator KUhE? ) *
                while (true)
                {
                    Operator op;
                    Mex1 m12;
                    List<NonTerminal> o = new List<NonTerminal>();

                    //( operator mex1 )
                    int save = lex.Position;
                    if (ps.MatchProduction<Operator>(out op) && ps.MatchProduction<Mex1>(out m12))
                    {
                        //if we're done this, then we have the whole bracket.
                        //turn it into an infix
                        result = new Infix(result, op, m12);
                    }
                        //(operand * operator KUhE?)
                    else
                    {
                        //undo any damage from the first bit
                        lex.Seek(save);
                        //put the leading mex1 into the operand list
                        o.Add(m1);

                        //operand *
                        while (true)
                        {
                            Operand oper;
                            if(ps.MatchProduction<Operand>(out oper))
                                o.Add(oper);
                            else
                                break;
                        }

                        //operator
                        if (ps.MatchProduction<Operator>(out op))
                        {
                            result = new RP(o, op);
                        }
                        else
                        {
                            lex.Seek(save);
                            break; // havent matched an infix or an rp
                        }

                        ps.MatchProduction(Selmaho.KUhE);
                    }
                }

                return true;
            }
            else
                return false; //you have to match a Mex1 first
        }
示例#2
0
 public Infix(NonTerminal left, Operator op, NonTerminal right)
 {
     _operator = op;
     _args.Add(left);
     _args.Add(right);
 }