Esempio n. 1
0
        public void visit(AST node)
        {
            // Flatten this level of the tree if it has no children
            bool flatten = /*true*/ false;
            AST  node2;

            for (node2 = node; node2 != null; node2 = node2.getNextSibling())
            {
                if (node2.getFirstChild() != null)
                {
                    flatten = false;
                    break;
                }
            }

            for (node2 = node; node2 != null; node2 = node2.getNextSibling())
            {
                if (!flatten || node2 == node)
                {
                    tabs();
                }
                if (node2.getText() == null)
                {
                    Console.Out.Write("nil");
                }
                else
                {
                    Console.Out.Write(node2.getText());
                }

                Console.Out.Write(" [" + node2.Type + "] ");

                if (flatten)
                {
                    Console.Out.Write(" ");
                }
                else
                {
                    Console.Out.WriteLine("");
                }

                if (node2.getFirstChild() != null)
                {
                    level++;
                    visit(node2.getFirstChild());
                    level--;
                }
            }

            if (flatten)
            {
                Console.Out.WriteLine("");
            }
        }
        public void visit(AST node)
        {
            // Flatten this level of the tree if it has no children
            bool flatten = /*true*/ false;
            AST node2;
            for (node2 = node; node2 != null; node2 = node2.getNextSibling())
            {
                if (node2.getFirstChild() != null)
                {
                    flatten = false;
                    break;
                }
            }

            for (node2 = node; node2 != null; node2 = node2.getNextSibling())
            {
                if (!flatten || node2 == node)
                {
                    tabs();
                }
                if (node2.getText() == null)
                {
                    Console.Out.Write("nil");
                }
                else
                {
                    Console.Out.Write(node2.getText());
                }

                Console.Out.Write(" [" + node2.Type + "] ");

                if (flatten)
                {
                    Console.Out.Write(" ");
                }
                else
                {
                    Console.Out.WriteLine("");
                }

                if (node2.getFirstChild() != null)
                {
                    level++;
                    visit(node2.getFirstChild());
                    level--;
                }
            }

            if (flatten)
            {
                Console.Out.WriteLine("");
            }
        }
Esempio n. 3
0
        override public string ToString()
        {
            string r = (root == null) ? "null" : root.getText();
            string c = (child == null) ? "null" : child.getText();

            return("[" + r + "," + c + "]");
        }
Esempio n. 4
0
        /*Is node t equal to this in terms of token type and text? */
        public virtual bool Equals(AST t)
        {
            if (t == null)
            {
                return(false);
            }

            return((Object.Equals(this.getText(), t.getText())) &&
                   (this.Type == t.Type));
        }
Esempio n. 5
0
        //throws RecognitionException
        public String value(AST _t)
        {
            String s ;

            AST value_AST_in = (AST)_t;
            AST l = null;
            AST ql = null;
            AST v = null;

            String variable = null;
            s = null;

            try {      // for error handling
            if (null == _t)
                _t = ASTNULL;
            switch ( _t.Type )
            {
            case LITERAL:
            {
                l = _t;
                match(_t,LITERAL);
                _t = _t.getNextSibling();

                s = l.getText();

                break;
            }
            case QLITERAL:
            {
                ql = _t;
                match(_t,QLITERAL);
                _t = _t.getNextSibling();

                s = ql.getText();

                break;
            }
            case VAR:
            {
                AST tmp18_AST_in = _t;
                match(_t,VAR);
                _t = _t.getNextSibling();
                AST tmp19_AST_in = _t;
                match(_t,LPAREN);
                _t = _t.getNextSibling();
                v = _t;
                match(_t,LITERAL);
                _t = _t.getNextSibling();
                AST tmp20_AST_in = _t;
                match(_t,RPAREN);
                _t = _t.getNextSibling();

                variable = v.getText();

                s = (String) environment.get(variable);

                if (s == null) {
                throw new RecognitionException("unrecognized variable " + variable);
                }

                break;
            }
            default:
            {
                throw new NoViableAltException(_t);
            }
             }
            }
            catch (RecognitionException ex)
            {
            reportError(ex);
            if (null != _t)
            {
                _t = _t.getNextSibling();
            }
            }
            retTree_ = _t;
            return s ;
        }
Esempio n. 6
0
        //throws RecognitionException
        public String literal(AST _t)
        {
            String s ;

            AST literal_AST_in = (AST)_t;
            AST l = null;
            AST ql = null;

            s = null;

            try {      // for error handling
            if (null == _t)
                _t = ASTNULL;
            switch ( _t.Type )
            {
            case LITERAL:
            {
                l = _t;
                match(_t,LITERAL);
                _t = _t.getNextSibling();

                s = l.getText();

                break;
            }
            case QLITERAL:
            {
                ql = _t;
                match(_t,QLITERAL);
                _t = _t.getNextSibling();

                s = ql.getText();

                break;
            }
            default:
            {
                throw new NoViableAltException(_t);
            }
             }
            }
            catch (RecognitionException ex)
            {
            reportError(ex);
            if (null != _t)
            {
                _t = _t.getNextSibling();
            }
            }
            retTree_ = _t;
            return s ;
        }
Esempio n. 7
0
 override public void  initialize(AST t)
 {
     setText(t.getText());
     Type = t.Type;
 }
Esempio n. 8
0
		/*Is node t equal to this in terms of token type and text? */
		public virtual bool Equals(AST t)
		{
			if (t == null)
				return false;

			return	(Object.Equals(this.getText(), t.getText())) && 
					(this.Type == t.Type);
		}
Esempio n. 9
0
        //throws RecognitionException
        public object value(AST _t)
        {
            object obj;

            AST value_AST_in = (AST)_t;
            AST l = null;
            AST ql = null;
            AST v = null;

            obj = null;

            try {      // for error handling
            if (null == _t)
                _t = ASTNULL;
            switch ( _t.Type )
            {
            case LITERAL:
            {
                l = _t;
                match(_t,LITERAL);
                _t = _t.getNextSibling();

                obj = Convert.ToInt32(l.getText());

                break;
            }
            case QLITERAL:
            {
                ql = _t;
                match(_t,QLITERAL);
                _t = _t.getNextSibling();

                obj = ql.getText();

                break;
            }
            case VAR:
            {
                AST tmp18_AST_in = _t;
                match(_t,VAR);
                _t = _t.getNextSibling();
                AST tmp19_AST_in = _t;
                match(_t,LPAREN);
                _t = _t.getNextSibling();
                v = _t;
                match(_t,LITERAL);
                _t = _t.getNextSibling();
                AST tmp20_AST_in = _t;
                match(_t,RPAREN);
                _t = _t.getNextSibling();

                string var = v.getText();

                obj = _inst.Eval(var);

                if (obj == null) {
                throw new RecognitionException("unrecognized variable " + var);
                }

                break;
            }
            default:
            {
                throw new NoViableAltException(_t);
            }
             }
            }
            catch (RecognitionException ex)
            {
            reportError(ex);
            if (null != _t)
            {
                _t = _t.getNextSibling();
            }
            }
            retTree_ = _t;
            return obj;
        }
Esempio n. 10
0
 override public void  initialize(AST t)
 {
     setText(t.getText());
     setType(t.Type);
 }
Esempio n. 11
0
 public override void initialize(AST t)
 {
     setText(t.getText());
     setType(t.Type);
 }
Esempio n. 12
0
		override public void  initialize(AST t)
		{
			setText(t.getText());
			Type = t.Type;
		}