Exemplo n.º 1
0
        public new static TCall LeftClaim(StringClaimer claimer, TExpression left)
        {
            Claim lb = claimer.Claim(LeftBracket);

            if (!lb.Success) // Left Bracket is a requirement.
            {
                return(null);
            }
            lb.Pass(); // At this point, we cannot fail.

            TCall newCall = new TCall {
                _caller = left
            };

            while (true)
            {
                Claim rb = claimer.Claim(RightBracket);
                if (rb.Success)
                {
                    rb.Pass();
                    break;
                }
                TArgument newArg = TArgument.Claim(claimer);
                if (newArg == null)
                {
                    break;
                }
                newCall._arguments.Add(newArg);
                claimer.Claim(Comma);
            }

            return(newCall);
        }
Exemplo n.º 2
0
        public new static TParenExpression Claim(StringClaimer claimer)
        {
            Claim lb = claimer.Claim(LeftBracket);

            if (!lb.Success)
            {
                return(null);
            }
            TParenExpression ptoken = new TParenExpression {
                _realExpression = TExpression.Claim(claimer)
            };

            if (ptoken._realExpression == null)
            {
                lb.Fail();
                return(null);
            }
            lb.Pass();
            Claim rb = claimer.Claim(RightBracket);

            if (rb.Success)
            {
                rb.Pass();            // right bracket is optional. So just pass it if we get it.
            }
            return(ptoken);
        }
Exemplo n.º 3
0
        public new static TBlock Claim(StringClaimer claimer)
        {
            Claim c = claimer.Claim(LeftBracket);

            if (!c.Success)
            {
                return(null);
            }
            c.Pass();
            TBlock      newBlock = new TBlock();
            TExpression nExp;

            while ((nExp = TExpression.Claim(claimer)) != null)
            {
                newBlock._expressions.Add(nExp);
                claimer.Claim(SemiColon);
                if (!(c = claimer.Claim(RightBracket)).Success)
                {
                    continue;
                }
                c.Pass();
                return(newBlock);
            }
            return(newBlock);
        }
Exemplo n.º 4
0
        public new static TWhile Claim(StringClaimer claimer)
        {
            Claim failpoint = claimer.FailPoint();
            Claim c         = claimer.Claim(While);

            if (!c.Success)
            {
                failpoint.Fail();
                return(null);
            }
            TExpression condition = TExpression.Claim(claimer);

            if (condition == null)
            {
                failpoint.Fail();
                return(null);
            }
            TExpression action     = TExpression.Claim(claimer);
            TWhile      whileBlock = new TWhile
            {
                _condition = condition,
                _action    = action
            };

            return(whileBlock);
        }
Exemplo n.º 5
0
        public new static TIf Claim(StringClaimer claimer)
        {
            Claim failpoint = claimer.FailPoint();
            Claim c         = claimer.Claim(If);

            if (!c.Success)
            {
                failpoint.Fail();
                return(null);
            }
            TExpression condition = TExpression.Claim(claimer);

            if (condition == null)
            {
                failpoint.Fail();
                return(null);
            }
            TExpression action  = TExpression.Claim(claimer);
            TIf         ifblock = new TIf
            {
                _condition = condition,
                _action    = action
            };


            c = claimer.Claim(Else);
            if (!c.Success)
            {
                return(ifblock);
            }
            TExpression otherwise = TExpression.Claim(claimer);

            if (otherwise == null)
            {
                c.Fail();
            }
            else
            {
                ifblock._otherwise = otherwise;
                c.Pass();
            }


            return(ifblock);
        }
Exemplo n.º 6
0
        public new static TIdentifier Claim(StringClaimer claimer)
        {
            TIdentifier ident = new TIdentifier();
            Claim       c     = claimer.Claim(Local);

            if (c.Success)
            {
                c.Pass();
                ident._isLocal = true;
            }

            c = claimer.Claim(Identifier);
            if (!c.Success)
            {
                return(null);
            }
            ident.Name = c.GetText();
            return(ident);
        }
Exemplo n.º 7
0
        new public static TFor Claim(StringClaimer claimer)
        {
            Claim c = claimer.Claim(FOR);

            if (!c.Success)
            {
                return(null);
            }

            TExpression[] exprs = new TExpression[4];
            claimer.Claim(LEFT_BRACKET);
            int claimed = 0;

            for (; claimed < 3; claimed++)
            {
                if ((exprs[claimed] = TExpression.Claim(claimer)) == null) // Out of Expressions. :(
                {
                    break;
                }
            }
            claimed--;
            c = claimer.Claim(RIGHT_BRACKET);
            if ((exprs[3] = TExpression.Claim(claimer)) == null && !c.Success)
            {
                if (claimed >= 0 && exprs[claimed] != null)
                {
                    exprs[3]       = exprs[claimed];
                    exprs[claimed] = null;
                }
            }
            TFor newFor = new TFor();

            newFor.initial   = exprs[0];
            newFor.condition = exprs[1];
            newFor.after     = exprs[2];
            newFor.body      = exprs[3];

            return(newFor);
        }
Exemplo n.º 8
0
        public new static TLiteralStringSimple Claim(StringClaimer claimer)
        {
            Claim c = claimer.Claim(String);

            if (!c.Success)
            {
                return(null);
            }
            c.Pass();
            TLiteralStringSimple str = new TLiteralStringSimple
            {
                _value = new VarString(Regex.Unescape(c.GetMatch().Groups["text"].Value))
            };

            return(str);
        }
Exemplo n.º 9
0
        public new static TOperator Claim(StringClaimer claimer)
        {
            foreach (var thisOp in Operators)
            {
                Claim c = claimer.Claim(thisOp.Regex);
                if (!c.Success)
                {
                    continue;
                }
                c.Pass();
                TOperator newOp = new TOperator {
                    _op = thisOp
                };
                return(newOp);
            }

            return(null);
        }
Exemplo n.º 10
0
        public new static TLiteralNumber Claim(StringClaimer claimer)
        {
            TLiteralNumber numb = new TLiteralNumber();

            Claim claim = claimer.Claim(Number);

            if (!claim.Success)
            {
                return(null);
            }
            claim.Pass();

            double v;
            Match  m = claim.GetMatch();


            if (m.Groups["integer"].Length > 0)
            {
                // x or b integer format.
                v = m.Groups["hex_val"].Length > 0 ? int.Parse(m.Groups["hex_val"].Value, NumberStyles.HexNumber) : Convert.ToInt32(m.Groups["bin_val"].Value, 2);
            }
            else
            {
                var num = m.Groups["int"].Length > 0 ? m.Groups["int"].Value : m.Groups["float"].Value;
                v = Convert.ToDouble(num);
                if (m.Groups["expon"].Length > 0)
                {
                    for (int i = Convert.ToInt32(m.Groups["expon"].Value); i > 0; i--)
                    {
                        v *= 10;
                    }
                }
            }

            if (m.Groups["negative"].Length > 0) // Has a -
            {
                v *= -1;
            }
            numb._value = new VarNumber(v);
            return(numb);
        }
Exemplo n.º 11
0
        public new static TAssignment Claim(StringClaimer claimer)
        {
            Claim failTo = claimer.FailPoint();

            TVariable toAssign = TVariable.Claim(claimer);

            if (toAssign == null)
            {
                failTo.Fail();
                return(null);
            }

            TOperator newOp = TOperator.Claim(claimer);

            Claim c = claimer.Claim(Set);

            if (!c.Success)
            {
                failTo.Fail();
                return(null);
            }
            TExpression assignValue = TExpression.Claim(claimer);

            if (assignValue == null)
            {
                failTo.Fail();
                return(null);
            }

            TAssignment newAssign = new TAssignment
            {
                _var   = toAssign,
                _op    = newOp,
                _value = assignValue
            };

            return(newAssign);
        }