Ejemplo n.º 1
0
        protected override ExpressionSyntaxElement ReturnMul(ExpressionSyntaxElement anary, FixedList <LexicalElement, ExpressionSyntaxElement>[] repeatOf_Cross_AndAnary)
        {
            ExpressionSyntaxElement left = anary;

            foreach (var right in repeatOf_Cross_AndAnary)
            {
                BinarySyntaxElement.OperatorType op = BinarySyntaxElement.OperatorType.Cross;
                switch (right.Element1.Type)
                {
                case LexType.Cross:
                    op = BinarySyntaxElement.OperatorType.Cross;
                    break;

                case LexType.Slash:
                    op = BinarySyntaxElement.OperatorType.Slash;
                    break;

                case LexType.Percent:
                    op = BinarySyntaxElement.OperatorType.Percent;
                    break;

                default:
                    throw new NotSupportedException();
                }
                left = new BinarySyntaxElement(left.LexAtStart, op, left, right.Element2);
            }
            return(left);
        }
Ejemplo n.º 2
0
        protected override ExpressionSyntaxElement ReturnModProperty(ExpressionSyntaxElement property, Selection <ArgumentsSyntaxElement, ExpressionSyntaxElement, DotInvocationSyntaxElement>[] repeatOfArgumentsOrIndexingOrDotInvocation)
        {
            ExpressionSyntaxElement left = property;

            foreach (var selection in repeatOfArgumentsOrIndexingOrDotInvocation)
            {
                if (selection.Element1.HasValue)
                {
                    ArgumentsSyntaxElement args = selection.Element1.Value;
                    left = new InvokeSyntaxElement(left.LexAtStart, left, args);
                }
                else if (selection.Element2.HasValue)
                {
                    ExpressionSyntaxElement index = selection.Element2.Value;
                    left = new IndexerSyntaxElement(left.LexAtStart, left, index);
                }
                else if (selection.Element3.HasValue)
                {
                    DotInvocationSyntaxElement     right       = selection.Element3.Value;
                    List <ExpressionSyntaxElement> expressions = new List <ExpressionSyntaxElement>();
                    expressions.Add(left);
                    expressions.AddRange(right.Arguments);
                    left = new InvokeSyntaxElement(left.LexAtStart, new IdentifierSyntaxElement(right.Identifier), expressions);
                }
                else
                {
                    throw new NotSupportedException();
                }
            }
            return(left);
        }
Ejemplo n.º 3
0
        protected override ExpressionSyntaxElement ReturnUnary(LexicalElement[] repeatOfNot, ExpressionSyntaxElement inc)
        {
            ExpressionSyntaxElement right = inc;

            foreach (LexicalElement left in repeatOfNot.Reverse())
            {
                AnarySyntaxElement.OperatorType op = AnarySyntaxElement.OperatorType.Plus;
                switch (left.Type)
                {
                case LexType.Plus:
                    op = AnarySyntaxElement.OperatorType.Plus;
                    break;

                case LexType.Minus:
                    op = AnarySyntaxElement.OperatorType.Minus;
                    break;

                case LexType.Not:
                    op = AnarySyntaxElement.OperatorType.Not;
                    break;

                default:
                    throw new NotSupportedException();
                }
                right = new AnarySyntaxElement(left, op, right);
            }
            return(right);
        }
Ejemplo n.º 4
0
 public InvokeSyntaxElement(LexicalElement lexAtStart, ExpressionSyntaxElement function, ExpressionSyntaxElement firstParameter, IList <ExpressionSyntaxElement> parameters)
     : base(lexAtStart)
 {
     this.Function    = function;
     this.Parameters  = new[] { firstParameter }.Union(parameters).ToArray();
     this.IsDotAccess = true;
 }
Ejemplo n.º 5
0
        /// <summary>
        /// for = 'for', '(', [expression|declare], ';', [expression], ';', [expression], ')', statement ;
        /// </summary>
        /// <param name="@for">'for'</param>
        /// <param name="openPar">'('</param>
        /// <param name="selection_opt">[expression|declare]</param>
        /// <param name="semicolon_1">';'</param>
        /// <param name="expression_opt_1">[expression]</param>
        /// <param name="semicolon_2">';'</param>
        /// <param name="expression_opt_2">[expression]</param>
        /// <param name="closePar">')'</param>
        /// <param name="statement">statement</param>
        protected override ForSyntaxElement ReturnFor(LexicalElement @for, LexicalElement openPar, Optional <Selection <ExpressionSyntaxElement, MultiDeclareSyntaxElement> > selection_opt, LexicalElement semicolon_1, Optional <ExpressionSyntaxElement> expression_opt_1, LexicalElement semicolon_2, Optional <ExpressionSyntaxElement> expression_opt_2, LexicalElement closePar, SyntaxElement statement)
        {
            ExpressionSyntaxElement init = null;

            if (selection_opt.HasValue)
            {
                if (selection_opt.Value.Element1.HasValue)
                {
                    init = selection_opt.Value.Element1.Value;
                }
                if (selection_opt.Value.Element2.HasValue)
                {
                    init = selection_opt.Value.Element2.Value;
                }
            }
            ExpressionSyntaxElement cond = null;

            if (expression_opt_1.HasValue)
            {
                cond = expression_opt_1.Value;
            }
            ExpressionSyntaxElement cont = null;

            if (expression_opt_2.HasValue)
            {
                cont = expression_opt_2.Value;
            }
            return(new ForSyntaxElement(@for, init, cond, cont, statement));
        }
Ejemplo n.º 6
0
 public SubstituteSyntaxElement(LexicalElement lexAtStart, AccessorSyntaxElement accessor, OperatorType @operator, ExpressionSyntaxElement rightValue)
     : base(lexAtStart)
 {
     this.Accessor   = accessor;
     this.Operator   = @operator;
     this.RightValue = rightValue;
 }
Ejemplo n.º 7
0
 public InvokeSyntaxElement(LexicalElement lexAtStart, ExpressionSyntaxElement function, IList <ExpressionSyntaxElement> parameters)
     : base(lexAtStart)
 {
     this.Function    = function;
     this.Parameters  = parameters.ToArray();
     this.IsDotAccess = false;
 }
Ejemplo n.º 8
0
 public BinarySyntaxElement(LexicalElement lexAtStart, OperatorType @operator, ExpressionSyntaxElement left, ExpressionSyntaxElement right)
     : base(lexAtStart)
 {
     this.Operator = @operator;
     this.Left     = left;
     this.Right    = right;
 }
Ejemplo n.º 9
0
 public DeclareSyntaxElement(LexicalElement lexAtStart, string identifier, VariableStorage.FieldProperty property, ExpressionSyntaxElement initialValue)
     : base(lexAtStart)
 {
     this.Identifier   = identifier;
     this.InitialValue = initialValue;
     this.Property     = property;
 }
Ejemplo n.º 10
0
 public DoWhileSyntaxElement(LexicalElement lexAtStart, ExpressionSyntaxElement condition, SyntaxElement statement, bool @do)
     : base(lexAtStart)
 {
     this.Condition = condition;
     this.Statement = statement;
     this.Do        = @do;
 }
Ejemplo n.º 11
0
 public IfSyntaxElement(LexicalElement lexAtStart, ExpressionSyntaxElement condition, SyntaxElement then, SyntaxElement @else)
     : base(lexAtStart)
 {
     this.Condition = condition;
     this.Then      = then;
     this.Else      = @else;
 }
Ejemplo n.º 12
0
 public ForeachSyntaxElement(LexicalElement lexAtStart, string identifier, bool declare, ExpressionSyntaxElement enumerator, SyntaxElement statement)
     : base(lexAtStart)
 {
     this.Identifier = identifier;
     this.Declare    = declare;
     this.Enumerator = enumerator;
     this.Statement  = statement;
 }
Ejemplo n.º 13
0
 public ForSyntaxElement(LexicalElement lexAtStart, ExpressionSyntaxElement initialize, ExpressionSyntaxElement condition, ExpressionSyntaxElement @continue, SyntaxElement statement)
     : base(lexAtStart)
 {
     this.Initialize = initialize;
     this.Condition  = condition;
     this.Continue   = @continue;
     this.Statement  = statement;
 }
Ejemplo n.º 14
0
 public TernarySyntaxElement(LexicalElement lexAtStart, OperatorType @operator, ExpressionSyntaxElement first, ExpressionSyntaxElement second, ExpressionSyntaxElement third)
     : base(lexAtStart)
 {
     this.Operator = @operator;
     this.First    = first;
     this.Second   = second;
     this.Third    = third;
 }
Ejemplo n.º 15
0
        protected override ExpressionSyntaxElement ReturnOr(ExpressionSyntaxElement and, FixedList <LexicalElement, ExpressionSyntaxElement>[] repeatOfOrAndAnd)
        {
            ExpressionSyntaxElement left = and;

            foreach (var right in repeatOfOrAndAnd)
            {
                left = new BinarySyntaxElement(left.LexAtStart, BinarySyntaxElement.OperatorType.Or, left, right.Element2);
            }
            return(left);
        }
Ejemplo n.º 16
0
        protected override ExpressionSyntaxElement ReturnAnd(ExpressionSyntaxElement cmp, FixedList <LexicalElement, ExpressionSyntaxElement>[] repeatOfAndAndCmp)
        {
            ExpressionSyntaxElement left = cmp;

            foreach (var right in repeatOfAndAndCmp)
            {
                left = new BinarySyntaxElement(left.LexAtStart, BinarySyntaxElement.OperatorType.And, left, right.Element2);
            }
            return(left);
        }
Ejemplo n.º 17
0
        protected override MultiExpressionSyntaxElement ReturnMultiExpression(ExpressionSyntaxElement expression, FixedList <LexicalElement, ExpressionSyntaxElement>[] repeatOfCommaAndExpression)
        {
            List <ExpressionSyntaxElement> expressions = new List <ExpressionSyntaxElement>();

            expressions.Add(expression);
            foreach (var pair in repeatOfCommaAndExpression)
            {
                expressions.Add(pair.Element2);
            }
            return(new MultiExpressionSyntaxElement(expression.LexAtStart, expressions));
        }
Ejemplo n.º 18
0
        protected override ExpressionSyntaxElement ReturnTernary(ExpressionSyntaxElement or, Optional <FixedList <LexicalElement, ExpressionSyntaxElement, LexicalElement, ExpressionSyntaxElement> > optOfQuestionAndTernaryAndColonAndTernary)
        {
            ExpressionSyntaxElement left = or;

            if (optOfQuestionAndTernaryAndColonAndTernary.HasValue)
            {
                ExpressionSyntaxElement atTrue  = optOfQuestionAndTernaryAndColonAndTernary.Value.Element2;
                ExpressionSyntaxElement atFalse = optOfQuestionAndTernaryAndColonAndTernary.Value.Element4;
                left = new TernarySyntaxElement(left.LexAtStart, TernarySyntaxElement.OperatorType.Condition, left, atTrue, atFalse);
            }
            return(left);
        }
Ejemplo n.º 19
0
        protected override MultiDeclareSyntaxElement ReturnDeclare(Selection <FixedList <LexicalElement, Optional <LexicalElement> >, LexicalElement> readonlyAnd_OptOfVar_OrVar, IdentifierSyntaxElement identifier, Optional <FixedList <LexicalElement, ExpressionSyntaxElement> > optOfEqualAndExpression, FixedList <LexicalElement, IdentifierSyntaxElement, Optional <FixedList <LexicalElement, ExpressionSyntaxElement> > >[] repeatOfCommaAndIdentifierAnd_OptOfEqualAndExpression)
        {
            LexicalElement head = new LexicalElement();

            VariableStorage.FieldProperty property = new VariableStorage.FieldProperty();
            if (readonlyAnd_OptOfVar_OrVar.Element1.HasValue)
            {
                head = readonlyAnd_OptOfVar_OrVar.Element1.Value.Element1;
                property.Readonly = true;
            }
            else
            {
                head = readonlyAnd_OptOfVar_OrVar.Element2.Value;
            }
            List <DeclareSyntaxElement> varList = new List <DeclareSyntaxElement>();

            if (optOfEqualAndExpression.HasValue)
            {
                DeclareSyntaxElement var1 = new DeclareSyntaxElement(identifier.LexAtStart, identifier.Identifier, property, optOfEqualAndExpression.Value.Element2);
                varList.Add(var1);
            }
            else
            {
                DeclareSyntaxElement var1 = new DeclareSyntaxElement(identifier.LexAtStart, identifier.Identifier, property);
                varList.Add(var1);
            }
            foreach (var declare in repeatOfCommaAndIdentifierAnd_OptOfEqualAndExpression)
            {
                DeclareSyntaxElement    var2;
                IdentifierSyntaxElement identifier2 = declare.Element2;
                if (declare.Element3.HasValue)
                {
                    ExpressionSyntaxElement expression2 = declare.Element3.Value.Element2;
                    var2 = new DeclareSyntaxElement(identifier2.LexAtStart, identifier2.Identifier, property, expression2);
                }
                else
                {
                    var2 = new DeclareSyntaxElement(identifier2.LexAtStart, identifier2.Identifier, property);
                }
                varList.Add(var2);
            }
            return(new MultiDeclareSyntaxElement(head, property, varList));
        }
Ejemplo n.º 20
0
        protected override ExpressionSyntaxElement ReturnSubstitute(ExpressionSyntaxElement leftValue, Optional <FixedList <LexicalElement, ExpressionSyntaxElement> > optOf_PlusEqual_AndSubstitute)
        {
            if (optOf_PlusEqual_AndSubstitute.HasValue)
            {
                SubstituteSyntaxElement.OperatorType op = SubstituteSyntaxElement.OperatorType.Substitute;
                switch (optOf_PlusEqual_AndSubstitute.Value.Element1.Type)
                {
                case LexType.Equal:
                    op = SubstituteSyntaxElement.OperatorType.Substitute;
                    break;

                case LexType.PlusEqual:
                    op = SubstituteSyntaxElement.OperatorType.Add;
                    break;

                case LexType.MinusEqual:
                    op = SubstituteSyntaxElement.OperatorType.Subtract;
                    break;

                case LexType.CrossEqual:
                    op = SubstituteSyntaxElement.OperatorType.Multiply;
                    break;

                case LexType.SlashEqual:
                    op = SubstituteSyntaxElement.OperatorType.Divide;
                    break;

                case LexType.PercentEqual:
                    op = SubstituteSyntaxElement.OperatorType.Remainder;
                    break;
                }
                AccessorSyntaxElement accessor = leftValue as AccessorSyntaxElement;
                if (accessor == null)
                {
                    throw new ParseException("Only identifier or indexer can be left value", leftValue.LexAtStart);
                }
                leftValue = new SubstituteSyntaxElement(leftValue.LexAtStart, accessor, op, optOf_PlusEqual_AndSubstitute.Value.Element2);
            }
            return(leftValue);
        }
Ejemplo n.º 21
0
        protected override ExpressionSyntaxElement ReturnCmp(ExpressionSyntaxElement add, Optional <FixedList <LexicalElement, ExpressionSyntaxElement> > optOf_Le_AndAdd)
        {
            ExpressionSyntaxElement left = add;

            if (optOf_Le_AndAdd.HasValue)
            {
                BinarySyntaxElement.OperatorType op = BinarySyntaxElement.OperatorType.Eq;
                switch (optOf_Le_AndAdd.Value.Element1.Type)
                {
                case LexType.Eq:
                    op = BinarySyntaxElement.OperatorType.Eq;
                    break;

                case LexType.Ne:
                    op = BinarySyntaxElement.OperatorType.Ne;
                    break;

                case LexType.Gt:
                    op = BinarySyntaxElement.OperatorType.Gt;
                    break;

                case LexType.Ge:
                    op = BinarySyntaxElement.OperatorType.Ge;
                    break;

                case LexType.Lt:
                    op = BinarySyntaxElement.OperatorType.Lt;
                    break;

                case LexType.Le:
                    op = BinarySyntaxElement.OperatorType.Le;
                    break;

                default:
                    throw new NotSupportedException();
                }
                left = new BinarySyntaxElement(left.LexAtStart, op, left, optOf_Le_AndAdd.Value.Element2);
            }
            return(left);
        }
Ejemplo n.º 22
0
        protected override ExpressionSyntaxElement ReturnInc(ExpressionSyntaxElement modProperty, LexicalElement plusPlus)
        {
            IncrementSyntaxElement.OperatorType op = IncrementSyntaxElement.OperatorType.PostDec;
            switch (plusPlus.Type)
            {
            case LexType.PlusPlus:
                op = IncrementSyntaxElement.OperatorType.PostInc;
                break;

            case LexType.MinusMinus:
                op = IncrementSyntaxElement.OperatorType.PostDec;
                break;

            default:
                throw new NotSupportedException();
            }
            AccessorSyntaxElement accessor = modProperty as AccessorSyntaxElement;

            if (accessor == null)
            {
                throw new ParseException("Only identifier or indexer can be left value", modProperty.LexAtStart);
            }
            return(new IncrementSyntaxElement(plusPlus, accessor, op));
        }
Ejemplo n.º 23
0
        protected override ExpressionSyntaxElement ReturnAdd(ExpressionSyntaxElement mul, FixedList <LexicalElement, ExpressionSyntaxElement>[] repeatOf_Plus_AndMul)
        {
            ExpressionSyntaxElement left = mul;

            foreach (var right in repeatOf_Plus_AndMul)
            {
                BinarySyntaxElement.OperatorType op = BinarySyntaxElement.OperatorType.Plus;
                switch (right.Element1.Type)
                {
                case LexType.Plus:
                    op = BinarySyntaxElement.OperatorType.Plus;
                    break;

                case LexType.Minus:
                    op = BinarySyntaxElement.OperatorType.Minus;
                    break;

                default:
                    throw new NotSupportedException();
                }
                left = new BinarySyntaxElement(left.LexAtStart, op, left, right.Element2);
            }
            return(left);
        }
Ejemplo n.º 24
0
 protected override ExpressionSyntaxElement ReturnIndexing(LexicalElement openBracket, ExpressionSyntaxElement expression, LexicalElement closeBracket)
 {
     return(expression);
 }
Ejemplo n.º 25
0
 protected override ExpressionSyntaxElement ReturnLeftValue(ExpressionSyntaxElement ternary)
 {
     return(ternary);
 }
Ejemplo n.º 26
0
 protected override ExpressionSyntaxElement ReturnExpression(ExpressionSyntaxElement substitute)
 {
     return(substitute);
 }
Ejemplo n.º 27
0
 protected override ForeachSyntaxElement ReturnForeach(LexicalElement @foreach, LexicalElement openPar, Optional <LexicalElement> optOfVar, IdentifierSyntaxElement identifier, LexicalElement @in, ExpressionSyntaxElement expression, LexicalElement closePar, SyntaxElement statement)
 {
     return(new ForeachSyntaxElement(@foreach, identifier.Identifier, optOfVar.HasValue, expression, statement));
 }
Ejemplo n.º 28
0
 protected override ExpressionSyntaxElement ReturnProperty(ExpressionSyntaxElement func)
 {
     return(func);
 }
Ejemplo n.º 29
0
 /// <summary>
 /// if = 'if', '(', expression, ')', statement, ['else', statement] ;
 /// </summary>
 /// <param name="@if">'if'</param>
 /// <param name="openPar">'('</param>
 /// <param name="expression">expression</param>
 /// <param name="closePar">')'</param>
 /// <param name="statement">statement</param>
 /// <param name="else_Statement_opt">['else', statement]</param>
 protected override IfSyntaxElement ReturnIf(LexicalElement @if, LexicalElement openPar, ExpressionSyntaxElement expression, LexicalElement closePar, SyntaxElement statement, Optional <FixedList <LexicalElement, SyntaxElement> > else_Statement_opt)
 {
     if (else_Statement_opt.HasValue)
     {
         return(new IfSyntaxElement(@if, expression, statement, else_Statement_opt.Value.Element2));
     }
     return(new IfSyntaxElement(@if, expression, statement));
 }
Ejemplo n.º 30
0
 protected override ExpressionSyntaxElement ReturnInc(ExpressionSyntaxElement modProperty)
 {
     return(modProperty);
 }