Пример #1
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));
        }
Пример #2
0
 public InvokeSyntaxElement(LexicalElement lexAtStart, ExpressionSyntaxElement function, IList <ExpressionSyntaxElement> parameters)
     : base(lexAtStart)
 {
     this.Function    = function;
     this.Parameters  = parameters.ToArray();
     this.IsDotAccess = false;
 }
Пример #3
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;
 }
Пример #4
0
 public SubstituteSyntaxElement(LexicalElement lexAtStart, AccessorSyntaxElement accessor, OperatorType @operator, ExpressionSyntaxElement rightValue)
     : base(lexAtStart)
 {
     this.Accessor   = accessor;
     this.Operator   = @operator;
     this.RightValue = rightValue;
 }
Пример #5
0
 public FunctionSyntaxElement(LexicalElement lexAtStart, IList <IdentifierSyntaxElement> parameters, SyntaxElement body, bool isParams)
     : base(lexAtStart)
 {
     this.Parameters = parameters;
     this.Body       = body;
     this.IsParams   = isParams;
 }
Пример #6
0
 public BinarySyntaxElement(LexicalElement lexAtStart, OperatorType @operator, ExpressionSyntaxElement left, ExpressionSyntaxElement right)
     : base(lexAtStart)
 {
     this.Operator = @operator;
     this.Left     = left;
     this.Right    = right;
 }
Пример #7
0
 public DeclareSyntaxElement(LexicalElement lexAtStart, string identifier, VariableStorage.FieldProperty property, ExpressionSyntaxElement initialValue)
     : base(lexAtStart)
 {
     this.Identifier   = identifier;
     this.InitialValue = initialValue;
     this.Property     = property;
 }
Пример #8
0
 public DoWhileSyntaxElement(LexicalElement lexAtStart, ExpressionSyntaxElement condition, SyntaxElement statement, bool @do)
     : base(lexAtStart)
 {
     this.Condition = condition;
     this.Statement = statement;
     this.Do        = @do;
 }
Пример #9
0
 public IfSyntaxElement(LexicalElement lexAtStart, ExpressionSyntaxElement condition, SyntaxElement then, SyntaxElement @else)
     : base(lexAtStart)
 {
     this.Condition = condition;
     this.Then      = then;
     this.Else      = @else;
 }
Пример #10
0
        protected override ExpressionSyntaxElement ReturnFunc(LexicalElement func, LexicalElement openPar, Optional <FixedList <Optional <LexicalElement>, Optional <LexicalElement>, IdentifierSyntaxElement, FixedList <LexicalElement, Optional <LexicalElement>, Optional <LexicalElement>, IdentifierSyntaxElement>[]> > optOf_OptOfParams_And_OptOfVar_AndIdentifierAnd_RepeatOfCommaAnd_OptOfParams_And_OptOfVar_AndIdentifier, LexicalElement closePar, SyntaxElement block)
        {
            List <IdentifierSyntaxElement> @params = new List <IdentifierSyntaxElement>();
            bool isParam = false;

            if (optOf_OptOfParams_And_OptOfVar_AndIdentifierAnd_RepeatOfCommaAnd_OptOfParams_And_OptOfVar_AndIdentifier.HasValue)
            {
                var tmp        = optOf_OptOfParams_And_OptOfVar_AndIdentifierAnd_RepeatOfCommaAnd_OptOfParams_And_OptOfVar_AndIdentifier.Value;
                var param      = tmp.Element1;
                var var        = tmp.Element2;
                var identifier = tmp.Element3;
                var repeat     = tmp.Element4;
                if (optOf_OptOfParams_And_OptOfVar_AndIdentifierAnd_RepeatOfCommaAnd_OptOfParams_And_OptOfVar_AndIdentifier.Value.Element1.HasValue)
                {
                    isParam = true;
                }
                @params.Add(identifier);
                foreach (var successor in repeat)
                {
                    var comma       = successor.Element1;
                    var param2      = successor.Element2;
                    var var2        = successor.Element3;
                    var identifier2 = successor.Element4;
                    @params.Add(identifier2);
                }
            }
            return(new FunctionSyntaxElement(func, @params, block, isParam));
        }
Пример #11
0
 protected override ControlSyntaxElement ReturnControl(LexicalElement @return, Optional <ExpressionSyntaxElement> optOfExpression)
 {
     if (optOfExpression.HasValue)
     {
         return(new ControlSyntaxElement(@return, optOfExpression.Value));
     }
     return(new ControlSyntaxElement(@return, RunControlType.Return));
 }
Пример #12
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));
 }
Пример #13
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;
 }
Пример #14
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;
 }
Пример #15
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;
 }
Пример #16
0
        protected override ExpressionSyntaxElement ReturnProperty_Number(LexicalElement number)
        {
            decimal value;

            if (decimal.TryParse(number.Text, out value))
            {
                return(new NumberSyntaxElement(number, value));
            }
            return(new NumberSyntaxElement(number, 0M));
        }
Пример #17
0
        protected override ListSyntaxElement ReturnList(LexicalElement openBraces, Optional <FixedList <ExpressionSyntaxElement, FixedList <LexicalElement, ExpressionSyntaxElement>[]> > optOfExpressionAnd_RepeatOfCommaAndExpression, LexicalElement closeBraces)
        {
            List <ExpressionSyntaxElement> expressions = new List <ExpressionSyntaxElement>();

            if (optOfExpressionAnd_RepeatOfCommaAndExpression.HasValue)
            {
                expressions.Add(optOfExpressionAnd_RepeatOfCommaAndExpression.Value.Element1);
                foreach (var list in optOfExpressionAnd_RepeatOfCommaAndExpression.Value.Element2)
                {
                    expressions.Add(list.Element2);
                }
            }
            return(new ListSyntaxElement(openBraces, expressions));
        }
Пример #18
0
        protected override ArgumentsSyntaxElement ReturnArguments(LexicalElement openPar, Optional <FixedList <ExpressionSyntaxElement, FixedList <LexicalElement, ExpressionSyntaxElement>[]> > optOfExpressionAnd_RepeatOfCommaAndExpression, LexicalElement closePar)
        {
            List <ExpressionSyntaxElement> expressions = new List <ExpressionSyntaxElement>();

            if (optOfExpressionAnd_RepeatOfCommaAndExpression.HasValue)
            {
                expressions.Add(optOfExpressionAnd_RepeatOfCommaAndExpression.Value.Element1);
                foreach (var successor in optOfExpressionAnd_RepeatOfCommaAndExpression.Value.Element2)
                {
                    expressions.Add(successor.Element2);
                }
            }
            return(new ArgumentsSyntaxElement(expressions));
        }
Пример #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));
        }
Пример #20
0
        protected override ExpressionSyntaxElement ReturnInc(LexicalElement plusPlus, ExpressionSyntaxElement modProperty)
        {
            IncrementSyntaxElement.OperatorType op = IncrementSyntaxElement.OperatorType.PostDec;
            switch (plusPlus.Type)
            {
            case LexType.PlusPlus:
                op = IncrementSyntaxElement.OperatorType.PreInc;
                break;

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

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

            if (accessor == null)
            {
                throw new ParseException("Only identifier or indexer can be left value", plusPlus);
            }
            return(new IncrementSyntaxElement(plusPlus, accessor, op));
        }
Пример #21
0
 protected override ParenthesisSyntaxElement ReturnParenthesis(LexicalElement openPar, MultiExpressionSyntaxElement multiExpression, LexicalElement closePar)
 {
     return(new ParenthesisSyntaxElement(openPar, multiExpression));
 }
Пример #22
0
 protected override ExpressionSyntaxElement ReturnIndexing(LexicalElement openBracket, ExpressionSyntaxElement expression, LexicalElement closeBracket)
 {
     return(expression);
 }
Пример #23
0
 protected override ExpressionSyntaxElement ReturnProperty_Null(LexicalElement @null)
 {
     return(new NullSyntaxElement(@null));
 }
Пример #24
0
 protected override ExpressionSyntaxElement ReturnProperty_False(LexicalElement @false)
 {
     return(new BooleanSyntaxElement(@false, false));
 }
Пример #25
0
 protected override ExpressionSyntaxElement ReturnProperty_True(LexicalElement @true)
 {
     return(new BooleanSyntaxElement(@true, true));
 }
Пример #26
0
 protected override ExpressionSyntaxElement ReturnProperty_String(LexicalElement @string)
 {
     return(new StringSyntaxElement(@string, @string.Text));
 }
Пример #27
0
 protected override ControlSyntaxElement ReturnControl_Continue(LexicalElement @continue)
 {
     return(new ControlSyntaxElement(@continue, RunControlType.Continue));
 }
Пример #28
0
 protected override ControlSyntaxElement ReturnControl_Break(LexicalElement @break)
 {
     return(new ControlSyntaxElement(@break, RunControlType.Break));
 }
Пример #29
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));
 }
Пример #30
0
 protected override IdentifierSyntaxElement ReturnIdentifier(LexicalElement identifier)
 {
     return(new IdentifierSyntaxElement(identifier, identifier.Text));
 }