public void setWhilte(ExprNode expr, BodyNode body)
 {
     fields.Add("expr", expr);
     fields.Add("body", body);
     //children.Add(body);
     children.Add(expr);
 }
 public void setFor(string id, IterNode iterator, BodyNode body)
 {
     this.id = id;
     fields.Add("iter", iterator);
     fields.Add("body", body);
     children.Add(iterator);
     //children.Add(body);
 }
 public IfNode(ExprNode e, BodyNode b, BodyNode el) : base(NodeType.IfNode)
 {
     this.expr      = e;
     this.body      = b;
     this.else_body = el;
     children       = new List <BaseNode>();
     //children.Add(expr);
     //children.Add(body);
     if (else_body != null)
     {
         children.Add(else_body);
     }
 }
        // returns List of (type, object)
        private BodyNode parseBody(List <string> tokens)
        {
            if (tokens.Count == 0)
            {
                return(null);
            }
            int cur  = 0;
            var body = new BodyNode();

            while (true)
            {
                if (cur >= tokens.Count)
                {
                    return(body);
                }
                int ind = findToken(tokens, (string s) => (s == "semi_t"), cur);
                if (ind == -1)
                {
                    ////printList(tokens);
                    throw new SyntaxError("; is missing");
                }
                else
                {
                    var t    = tokens.GetRange(cur, ind - cur); // cur = 3 ind  5
                    var type = toBody(t);
                    switch (type)
                    {
                    case BodyType.Decl:
                        body.add(type, parseDeclaration(t));
                        break;

                    case BodyType.Expr:
                        body.add(type, parseExpression(t));
                        break;

                    default:
                        body.addAll(type, parseStatements(t));
                        break;
                    }
                    cur = ind + 1;
                }
            }
        }
 public void setProgram(BodyNode b)
 {
     this.program = b;
     children.Add(program);
 }
Beispiel #6
0
 public void setBody(BodyNode b)
 {
     this.body = b;
     children.Add(b);
 }
 public IfNode(ExprNode e, BodyNode b) : this(e, b, null)
 {
 }