예제 #1
0
        internal override Syntax_Node ParseLex(Lex.Data data)
        {
            switch (codePhase)
            {
            case CodePhase.Code:
                // TODO parse code
                switch (data.token)
                {
                case Token.Keyword:
                {
                    var keyword = (Keyword)data.number.i_32;
                    switch (keyword)
                    {
                    case Keyword.If:
                        return(AddChild(Syntax_Node.Create <Syntax_If>(data, this)));

                    case Keyword.Loop:
                        return(AddChild(Syntax_Node.Create <Syntax_Loop>(data, this)));

                    case Keyword.Block:
                        return(AddChild(Syntax_Node.Create <Syntax_Block>(data, this)));

                    case Keyword.Return:
                        codePhase = CodePhase.Return;
                        return(this);

                    default:
//							{
//								var exception = new SyntaxException(Syntax.Error.InvalidKeyword);
//								exception.content = keyword.ToString();
//								throw exception;
//							}
                        return(this);
                    }
                }

                default:
//					{
//						var exception = new SyntaxException(Syntax.Error.InvalidToken);
//						exception.content = data.token.ToString();
//						throw exception;
//					}
                    return(this);
                }

            case CodePhase.Return:
                switch (data.token)
                {
                case Token.Keyword:
                    // TODO save
                    if (Syntax.constantKeywordList.Contains((Keyword)data.number.i_32))
                    {
                        // TODO save
                        codePhase = CodePhase.ReturnSeparator;
                        return(this);
                    }
                    else
                    {
                        var exception = new SyntaxException(Syntax.Error.InvalidToken);
                        exception.content = data.token.ToString();
                        throw exception;
                    }

                case Token.Identify:
                    // TODO save
                    codePhase = CodePhase.ReturnSeparator;
                    return(this);

                default:
                    if (Syntax.constantTokenList.Contains(data.token))
                    {
                        // TODO save
                        codePhase = CodePhase.ReturnSeparator;
                        return(this);
                    }
                    else
                    {
                        var exception = new SyntaxException(Syntax.Error.InvalidToken);
                        exception.content = data.token.ToString();
                        throw exception;
                    }
                }

            case CodePhase.ReturnSeparator:
                if (Token.Operator == data.token)
                {
                    var op = (Operator)data.number.i_32;
                    if (Operator.Comma == op)
                    {
                        codePhase = CodePhase.Return;
                        return(this);
                    }
                    else
                    {
                        var exception = new SyntaxException(Syntax.Error.InvalidOperator);
                        exception.content = op.ToString();
                        throw exception;
                    }
                }
                else
                {
                    var exception = new SyntaxException(Syntax.Error.InvalidToken);
                    exception.content = data.token.ToString();
                    throw exception;
                }
            }
            return(this);
        }
예제 #2
0
 internal override void DoConstruct(Lex.Data data)
 {
     base.DoConstruct(data);
     codePhase = CodePhase.Code;
 }