Ejemplo n.º 1
0
        private NodeExpression ParseExpressionE(NodeTask t)
        {
            // this is the hard one
            NodeExpression o0 = this.ParseExpressionT(t);

            Token next = this.tn.Peek();

            while (next.type == Token.Type.Keyword &&
                   (next.val == "+" || next.val == "-" || next.val == "%"))
            {
                Token          op = this.tn.Next();
                NodeExpression o1 = this.ParseExpressionT(t);

                if (op.val == "+")
                {
                    o0 = new ExprAdd(t, o0, o1);
                }
                else if (op.val == "-")
                {
                    o0 = new ExprSub(t, o0, o1);
                }
                else if (op.val == "%")
                {
                    o0 = new ExprMod(t, o0, o1);
                }

                next = this.tn.Peek();
            }

            return(o0);
        }
Ejemplo n.º 2
0
 public void AddTask(NodeTask task)
 {
     if (task != null)
     {
         this.SubTasks.Add(task);
         task.Parent = this;
     }
 }
Ejemplo n.º 3
0
        private NodeExpression ParseExpression(NodeTask t)
        {
            // this is the hard one
            NodeExpression e = this.ParseExpressionBOr(t);

            Token next = this.tn.Peek();

            if (next.type == Token.Type.Keyword && next.val == ";")
            {
                // all fine
            }
            else
            {
            }

            return(e);
        }
Ejemplo n.º 4
0
        private NodeExpression ParseExpressionC(NodeTask t)
        {
            NodeExpression o0 = this.ParseExpressionE(t);

            Token next = this.tn.Peek();

            while (next.type == Token.Type.Keyword &&
                   (next.val == "<" || next.val == "<=" || next.val == "==" ||
                    next.val == ">=" || next.val == ">" || next.val == "!="))
            {
                Token          op = this.tn.Next();
                NodeExpression o1 = this.ParseExpressionE(t);

                if (op.val == "<")
                {
                    o0 = new ExprCmpLt(t, o0, o1);
                }
                else if (op.val == "<=")
                {
                    o0 = new ExprCmpLe(t, o0, o1);
                }
                else if (op.val == "==")
                {
                    o0 = new ExprCmpEq(t, o0, o1);
                }
                else if (op.val == ">=")
                {
                    o0 = new ExprCmpGe(t, o0, o1);
                }
                else if (op.val == ">")
                {
                    o0 = new ExprCmpGt(t, o0, o1);
                }
                else if (op.val == "!=")
                {
                    o0 = new ExprCmpNe(t, o0, o1);
                }

                next = this.tn.Peek();
            }

            return(o0);
        }
Ejemplo n.º 5
0
        private NodeExpression ParseExpressionBOr(NodeTask t)
        {
            NodeExpression o0 = this.ParseExpressionBAnd(t);

            Token next = this.tn.Peek();

            while (next.type == Token.Type.Keyword &&
                   (next.val == "||"))
            {
                Token          op = this.tn.Next();
                NodeExpression o1 = this.ParseExpressionBAnd(t);

                if (op.val == "||")
                {
                    o0 = new ExprOr(t, o0, o1);
                }

                next = this.tn.Peek();
            }

            return(o0);
        }
Ejemplo n.º 6
0
 public LiteralExpression(NodeTask task, Value val)
     : base(task)
 {
     this.val = val;
 }
Ejemplo n.º 7
0
 public LiteralExpression(NodeTask task, string val)
     : base(task)
 {
     this.val = new Value(val);
 }
Ejemplo n.º 8
0
 public NodeTask(NodeTask parent)
 {
     this.Parent = parent;
 }
Ejemplo n.º 9
0
 public IDExpression(NodeTask task, string id)
     : base(task)
 {
     this.id = id;
 }
Ejemplo n.º 10
0
 protected BinExpresssion(NodeTask task, NodeExpression left, NodeExpression right)
     : base(task)
 {
     this.Left  = left;
     this.Right = right;
 }
Ejemplo n.º 11
0
 public FcallExpression(NodeTask task, string id, List <NodeExpression> parms)
     : base(task)
 {
     this.id    = id;
     this.parms = parms;
 }
Ejemplo n.º 12
0
 public NodeDefinition(NodeTask task, string name, NodeExpression expression)
 {
     this.task       = task;
     this.name       = name;
     this.expression = expression;
 }
Ejemplo n.º 13
0
 protected ArithBinExpression(NodeTask task, NodeExpression a0, NodeExpression a1)
     : base(task, a0, a1)
 {
 }
Ejemplo n.º 14
0
 public CollectionExpression(NodeTask task, List <NodeExpression> expressions)
     : base(task)
 {
     this.expressions = expressions;
 }
Ejemplo n.º 15
0
        public NodeTask ParseTask(NodeTask parent)
        {
            NodeTask t = new NodeTask(parent);
            Token    r = this.tn.Peek();

            if (r.type == Token.Type.EOF)
            {
                return(null);
            }

            String s_name = null;
            String s_type = null;

            // Type (or name)
            Token t1 = this.tn.Next();

            if (t1.type != Token.Type.Literal) // !!!
            {
                this.Error("Task must have a type or name");
                return(null);
            }

            Token colon = this.tn.Peek();

            if (colon.type == Token.Type.Keyword && colon.val == ":")
            {
                this.tn.Next();                    // eat colon
                Token t2 = this.tn.Next();         // type

                if (t2.type != Token.Type.Literal) // !!!
                {
                    this.Error("Expected task type after : in task definition");
                    return(null);
                }

                s_name = t1.val;
                s_type = t2.val;
            }
            else
            {
                s_name = null;
                s_type = t1.val;
            }

            t.Type = s_type;
            t.Name = s_name;

            // {

            if (!this.Expect(Token.Type.Keyword, "{"))
            {
                return(null);
            }

            // definitions
            Token next = this.tn.Peek();

            while (next.type == Token.Type.ID)
            {
                Token ID = this.tn.Next(); // chomp ID

                if (!this.Expect(Token.Type.Keyword, "="))
                {
                    return(null);
                }

                NodeExpression expr = this.ParseExpression(t);

                if (!this.Expect(Token.Type.Keyword, ";"))
                {
                    return(null);
                }

                t.AddDefinition(new NodeDefinition(t, ID.val, expr));
                next = this.tn.Peek();
            }

            // child tasks
            next = this.tn.Peek();
            while (next.type == Token.Type.Literal)
            {
                NodeTask child = this.ParseTask(t);
                t.AddTask(child);
                next = this.tn.Peek();
            }

            // }

            if (!this.Expect(Token.Type.Keyword, "}"))
            {
                return(null);
            }

            return(t);
        }
Ejemplo n.º 16
0
 public AssocReadExpression(NodeTask task, NodeExpression a0, NodeExpression a1)
     : base(task, a0, a1)
 {
 }
Ejemplo n.º 17
0
        private NodeExpression ParseExpressionP(NodeTask t)
        {
            Token next = this.tn.Peek();

            if (next.type == Token.Type.Literal)
            {
                // literal expression
                this.tn.Next();
                Token lpar = this.tn.Peek();

                if (lpar.type == Token.Type.Keyword && lpar.val == "(")
                {
                    //fcall

                    List <NodeExpression> exprs = new List <NodeExpression>();
                    Token comma = null;

                    do
                    {
                        this.tn.Next();                         // eat ( or ,
                        NodeExpression n = this.ParseExpression(t);
                        exprs.Add(n);
                        comma = this.tn.Peek();
                    } while (comma.type == Token.Type.Keyword && comma.val == ",");

                    this.Expect(Token.Type.Keyword, ")");

                    NodeExpression e = new FcallExpression(t, next.val, exprs);
                    return(e);
                }
                else
                {
                    NodeExpression e = new LiteralExpression(t, next.val);
                    return(e);
                }
            }
            else if (next.type == Token.Type.ID)
            {
                // ID expression
                this.tn.Next();

                Token lpar = this.tn.Peek();

                // assoc lookup
                if (lpar.type == Token.Type.Keyword && lpar.val == "{")
                {
                    this.tn.Next();                     // eat {
                    NodeExpression id  = new IDExpression(t, next.val);
                    NodeExpression key = this.ParseExpression(t);
                    this.Expect(Token.Type.Keyword, "}");
                    NodeExpression e = new AssocReadExpression(t, id, key);
                    return(e);
                }
                else
                {
                    NodeExpression e = new IDExpression(t, next.val);
                    return(e);
                }
            }
            else if (next.type == Token.Type.Keyword && next.val == "(")
            {
                // par expressions
                this.tn.Next();
                NodeExpression n = this.ParseExpression(t);
                this.Expect(Token.Type.Keyword, ")");
                return(n);
            }
            else if (next.type == Token.Type.Keyword && next.val == "[")
            {
                // collection expressions

                List <NodeExpression> exprs = new List <NodeExpression>();
                Token comma = null;

                do
                {
                    this.tn.Next();
                    Token p = this.tn.Peek();
                    if (p.type == Token.Type.Keyword && p.val == "]")
                    {
                        break;                         // empty collection
                    }
                    NodeExpression n = this.ParseExpression(t);
                    exprs.Add(n);
                    comma = this.tn.Peek();
                } while (comma.type == Token.Type.Keyword && comma.val == ",");

                this.Expect(Token.Type.Keyword, "]");
                CollectionExpression ce = new CollectionExpression(t, exprs);
                return(ce);
            }
            else if (next.type == Token.Type.Keyword && next.val == "-")
            {
                // unary neg
                Token          neg = this.tn.Next();
                NodeExpression P   = this.ParseExpressionP(t);
                NodeExpression e   = new NegExpression(t, P);
                return(e);
            }
            else
            {
                this.Error("Currupt expression");
            }

            return(null);
        }
Ejemplo n.º 18
0
 public ExprCmpNe(NodeTask task, NodeExpression a0, NodeExpression a1)
     : base(task, a0, a1)
 {
 }
Ejemplo n.º 19
0
 public NegExpression(NodeTask task, NodeExpression e)
     : base(task)
 {
     this.e = e;
 }