Пример #1
0
        public YuToken RBrace()
        {
            YuToken ret = this.CurrToken;

            this.Match(ETokenType.RBrace);
            return(ret);
        }
Пример #2
0
        public YuToken Def()
        {
            YuToken ret = this.CurrToken;

            this.Match(ETokenType.Def);
            return(ret);
        }
Пример #3
0
        public YuToken Call()
        {
            YuToken ret = this.CurrToken;

            this.Match(ETokenType.Call);
            return(ret);
        }
Пример #4
0
        public YuToken Symbol()
        {
            YuToken ret = this.CurrToken;

            this.Match(ETokenType.Symbol);
            return(ret);
        }
Пример #5
0
        public YuToken Equal()
        {
            YuToken ret = this.CurrToken;

            this.Match(ETokenType.Equal);
            return(ret);
        }
Пример #6
0
        public YuToken Var()
        {
            YuToken ret = this.CurrToken;

            this.Match(ETokenType.Var);
            return(ret);
        }
Пример #7
0
        public YuToken ExpAdd()
        {
            YuToken ret = this.CurrToken;

            this.Match(ETokenType.ExpAdd);
            return(ret);
        }
Пример #8
0
        public YuToken SemiColon()
        {
            YuToken ret = this.CurrToken;

            this.Match(ETokenType.SemiColon);
            return(ret);
        }
Пример #9
0
 public YuSymbolTableRow(ESymbolType stype, YuToken token)
 {
     this.SymbolType   = stype;
     this.SymbolToken  = token;
     this.ProcTree     = null;
     this.AbsoluteAddr = -1;
 }
Пример #10
0
        public YuToken Number()
        {
            YuToken ret = this.CurrToken;

            this.Match(ETokenType.Number);
            return(ret);
        }
Пример #11
0
 public YuSymbolTableRow(ESymbolType stype, YuToken token, YuTreeNode tree)
 {
     this.SymbolType   = stype;
     this.SymbolToken  = token;
     this.ProcTree     = tree;
     this.AbsoluteAddr = -1;
 }
Пример #12
0
        public YuTreeNode ExpStat()
        {
            YuToken    a   = this.Term();
            YuToken    exp = null;
            YuToken    b   = null;
            YuTreeNode ret = null;

            while (this.CurrToken.Type != ETokenType.SemiColon && this.CurrToken.Type != ETokenType.Eof)
            {
                exp = this.ExpAdd();
                b   = this.Term();

                if (ret == null)
                {
                    ret = new YuTreeNode(exp);
                    ret.Children.Add(new YuTreeNode(a));
                    ret.Children.Add(new YuTreeNode(b));
                }
                else
                {
                    YuTreeNode tmp = new YuTreeNode(exp);
                    tmp.Children.Add(ret);
                    tmp.Children.Add(new YuTreeNode(b));
                    ret = tmp;
                }
            }
            this.SemiColon();

            if (exp == null)
            {
                ret = new YuTreeNode(a);
            }

            return(ret);
        }
Пример #13
0
        public YuToken RParen()
        {
            YuToken ret = this.CurrToken;

            this.Match(ETokenType.RParen);
            return(ret);
        }
Пример #14
0
        public YuToken Let()
        {
            YuToken ret = this.CurrToken;

            this.Match(ETokenType.Let);
            return(ret);
        }
Пример #15
0
        /*
         * public YuTreeNode CalcStat()
         * {
         *  YuToken a = this.Number();
         *  YuToken b = this.ExpAdd();
         *  YuToken c = this.Number();
         *  this.SemiColon();
         *
         *  YuTreeNode ret = new YuTreeNode(b);
         *  ret.Children.Add(new YuTreeNode(a));
         *  ret.Children.Add(new YuTreeNode(c));
         *
         *  return ret;
         * }
         *
         * public YuTreeNode VCalcStat()
         * {
         *  YuToken a = this.Symbol();
         *  YuToken b = this.ExpAdd();
         *  YuToken c = this.Number();
         *  this.SemiColon();
         *
         *  YuTreeNode ret = new YuTreeNode(b);
         *  ret.Children.Add(new YuTreeNode(a));
         *  ret.Children.Add(new YuTreeNode(c));
         *
         *  return ret;
         * }
         */

        public YuTreeNode VarDefStat()
        {
            YuToken a = this.Var();
            YuToken b = this.Symbol();

            this.SemiColon();

            YuTreeNode ret = new YuTreeNode(a);

            ret.Children.Add(new YuTreeNode(b));

            return(ret);
        }
Пример #16
0
        public YuToken Term()
        {
            YuToken ret = this.CurrToken;

            if (ret.Type == ETokenType.Number)
            {
                this.Match(ETokenType.Number);
            }
            else
            {
                this.Match(ETokenType.Symbol);
            }
            return(ret);
        }
Пример #17
0
        public YuTreeNode CallStat()
        {
            YuToken a = this.Call();
            YuToken b = this.Symbol();

            this.LParen();
            this.RParen();
            this.SemiColon();

            YuTreeNode ret = new YuTreeNode(a);

            ret.Children.Add(new YuTreeNode(b));

            return(ret);
        }
Пример #18
0
        public YuTreeNode ProcDefStat()
        {
            YuToken a = this.Def();
            YuToken b = this.Symbol();

            YuTreeNode ret = new YuTreeNode(a);

            ret.Children.Add(new YuTreeNode(b));
            this.LBrace();

            while (this.CurrToken.Type != ETokenType.RBrace && this.CurrToken.Type != ETokenType.Eof)
            {
                ret.Children.Add(this.Statement());
            }

            this.RBrace();

            return(ret);
        }
Пример #19
0
        public YuTreeNode AssignStat()
        {
            this.Let();
            YuToken    a = this.Symbol();
            YuToken    b = this.Equal();
            YuTreeNode n = this.ExpStat();

            /*
             * if (this.CurrToken.Type == ETokenType.Number)
             *  n = this.CalcStat();
             * else
             *  n = this.VCalcStat();
             */


            YuTreeNode ret = new YuTreeNode(b);

            ret.Children.Add(new YuTreeNode(a));
            ret.Children.Add(n);

            return(ret);
        }
Пример #20
0
 public YuTreeNode(YuToken t)
     : base(t)
 {
     this.Children = new List <YuTreeNode>();
 }
Пример #21
0
 public YuTreeLeaf(YuToken t)
 {
     this.Token = t;
 }
Пример #22
0
        public override YuToken NextToken()
        {
            while (this.Idx < this.Src.Length)
            {
                switch (this.Src[this.Idx])
                {
                case ' ':
                case '\t':
                case '\r':
                case '\n':
                    WhiteSpace();
                    continue;

                case '+':
                    this.Consume();
                    return(new YuToken(ETokenType.ExpAdd, "+"));

                case ';':
                    this.Consume();
                    return(new YuToken(ETokenType.SemiColon, ";"));

                case '=':
                    this.Consume();
                    return(new YuToken(ETokenType.Equal, "="));

                case '{':
                    this.Consume();
                    return(new YuToken(ETokenType.LBrace, "{"));

                case '}':
                    this.Consume();
                    return(new YuToken(ETokenType.RBrace, "}"));

                case '(':
                    this.Consume();
                    return(new YuToken(ETokenType.LParen, "("));

                case ')':
                    this.Consume();
                    return(new YuToken(ETokenType.RParen, ")"));

                default:
                    if (this.IsNumeric())
                    {
                        return(this.Number());
                    }
                    if (this.IsLetter())
                    {
                        YuToken token = this.Symbol();

                        if (token.Text.ToUpper().Equals("VAR"))
                        {
                            token = new YuToken(ETokenType.Var, token.Text);
                        }
                        else if (token.Text.ToUpper().Equals("LET"))
                        {
                            token = new YuToken(ETokenType.Let, token.Text);
                        }
                        else if (token.Text.ToUpper().Equals("DEF"))
                        {
                            token = new YuToken(ETokenType.Def, token.Text);
                        }
                        else if (token.Text.ToUpper().Equals("CALL"))
                        {
                            token = new YuToken(ETokenType.Call, token.Text);
                        }

                        return(token);
                    }

                    throw new YuUnKnownTokenException();
                }
            }

            return(new YuToken(ETokenType.Eof, "<EOF>"));
        }
Пример #23
0
 public Parser(Lexer lex)
 {
     this.Lex       = lex;
     this.CurrToken = this.Lex.NextToken();
 }
Пример #24
0
 /// <summary>
 /// トークンを消費する
 /// </summary>
 public void Consume()
 {
     this.CurrToken = this.Lex.NextToken();
 }