Beispiel #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);
        }
Beispiel #2
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);
        }
Beispiel #3
0
        public bool BindSymbols()
        {
            bool ok = true;

            // Traverse the tree and connect ID expression to their expression
            foreach (NodeDefinition d in this.definitions)
            {
                NodeExpression e = d.GetExpression();
                ok &= e.BindSymbols();
            }

            foreach (NodeTask t in this.SubTasks)
            {
                ok &= t.BindSymbols();
            }

            return(ok);
        }
Beispiel #4
0
        public virtual Value GetValueOfId(string def)
        {
            int dotIndex = def.IndexOf('.');

            if (dotIndex != -1)
            {
                // dot in name, search in named chilren tasks for it
                String cname = def.Substring(0, dotIndex);
                String cdef  = def.Substring(dotIndex + 1);

                foreach (NodeTask t in this.SubTasks)
                {
                    if (t.Name != null && t.Name == cname)
                    {
                        Value v = t.GetValueOfId(cdef);
                        return(v);
                    }
                }
            }
            else
            {
                foreach (NodeDefinition d in this.definitions)
                {
                    if (d.IsNamed(def))
                    {
                        NodeExpression e   = d.GetExpression();
                        Value          val = e.GetValue();

                        //  PPather.WriteLine(" def: " + def + " got e " + e + " and val " + val);

                        return(val);
                    }
                }

                if (this.Parent != null)
                {
                    Value e = this.Parent.GetValueOfId(def);
                    return(e);
                }
            }

            this.Error("No definition of idenfifier " + def);
            return(null);
        }
Beispiel #5
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);
        }
Beispiel #6
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);
        }
Beispiel #7
0
        public virtual NodeExpression GetExpressionOfId(string def)
        {
            /*int dotIndex = def.IndexOf('.');
             *
             * if (dotIndex != -1)
             * {
             *      // dot in name, search in named chilren tasks for it
             *      String cname = def.Substring(0, dotIndex);
             *      String cdef  = def.Substring(dotIndex + 1);
             *      foreach (
             *              NodeTask t in subTasks)
             *      {
             *              if (t.name != null && t.name == cname)
             *                      return t.GetExpressionOfId(def);
             *      }
             * }
             * else*/
            {
                foreach (NodeDefinition d in this.definitions)
                {
                    if (d.IsNamed(def))
                    {
                        return(d.GetExpression());
                    }
                }
            }

            if (this.Parent != null)
            {
                NodeExpression e = this.Parent.GetExpressionOfId(def);
                return(e);
            }

            this.Error("No definition of idenfifier " + def);
            return(null);
        }
Beispiel #8
0
 public ExprCmpNe(NodeTask task, NodeExpression a0, NodeExpression a1)
     : base(task, a0, a1)
 {
 }
 public AssocReadExpression(NodeTask task, NodeExpression a0, NodeExpression a1)
     : base(task, a0, a1)
 {
 }
Beispiel #10
0
 public override bool BindSymbols()
 {
     this.expression = this.Task.GetExpressionOfId(this.id);
     return(this.expression != null);
 }
Beispiel #11
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);
        }
Beispiel #12
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);
        }
Beispiel #13
0
 public NodeDefinition(NodeTask task, string name, NodeExpression expression)
 {
     this.task       = task;
     this.name       = name;
     this.expression = expression;
 }
 protected ArithBinExpression(NodeTask task, NodeExpression a0, NodeExpression a1)
     : base(task, a0, a1)
 {
 }
Beispiel #15
0
 protected BinExpresssion(NodeTask task, NodeExpression left, NodeExpression right)
     : base(task)
 {
     this.Left  = left;
     this.Right = right;
 }
Beispiel #16
0
 public NegExpression(NodeTask task, NodeExpression e)
     : base(task)
 {
     this.e = e;
 }