Exemple #1
0
        //only supports direct comparaison. No result of operation allowed
        //TODO combinator (&& ||)
        private ComparaisonNode ParseComparaisonNode(ref int at)
        {
            ComparaisonNode cn = new ComparaisonNode();

            var l_val = ParseValueNode(ref at);

            at++;

            Signature op = Ast[at].Signature;

            at++;

            var r_val = ParseValueNode(ref at);

            at++;

            if (l_val == null || r_val == null || !op.IsComparationOperator())
            {
                at = 0;
                return(null);
            }

            cn.ComparaisonType = op;
            cn.l_op            = l_val;
            cn.r_op            = r_val;

            return(cn);
        }
Exemple #2
0
        private bool ParseIfStatement(ref int at)
        {
            var ifNode = new IfNode();

            //parse operation
            at++;

            //Parse op
            if (Ast[at].Signature != Signature.LPAREN)
            {
                return(false);
            }

            at++;
            //returns at the position after the second value
            ComparaisonNode cn = ParseComparaisonNode(ref at);

            if (cn == null)
            {
                return(false);
            }

            ifNode.AddComparaisonNode(cn);

            if (Ast[at].Signature != Signature.RPAREN)
            {
                return(false);
            }

            at++;
            if (Ast[at].Signature != Signature.LBRACE)
            {
                return(false);
            }

            //get bounds of the {} block
            int startOfIfBlock = at;

            at++;
            var closingBraceFound = GoToClosingBrace(at);

            if (closingBraceFound.Item1 == false)
            {
                return(false);
            }

            int startOfElseBlock = closingBraceFound.Item2;

            startOfElseBlock++;
            if (startOfElseBlock < Ast.Count)
            {
                if (Ast[startOfElseBlock].Signature == Signature.KW_ELSE)
                {
                    ifNode.HasElse = true;
                    ifNode.AddChild(OperationType.BLOCK);

                    startOfElseBlock++;
                    if (Ast[startOfElseBlock].Signature != Signature.LBRACE)
                    {
                        return(false);
                    }

                    startOfElseBlock++;

                    if (!GoToClosingBrace(startOfElseBlock).Item1)
                    {
                        return(false);
                    }
                }
            }

            Tree.Current.AddChild(ifNode);
            at = startOfIfBlock;

            return(true);
        }
Exemple #3
0
 public void AddComparaisonNode(ComparaisonNode node)
 => Childrens[0] = node;