Ejemplo n.º 1
0
        internal override Syntax_Node ParseLex(Lex.Data data)
        {
            switch (data.token)
            {
            case Token.Keyword:
            {
                var keyword = (Keyword)data.number.i_32;
                switch (keyword)
                {
                case Keyword.Interface:
                    return(AddChild(Syntax_Node.Create <Syntax_Interface>(data, this)));

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

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

            case Token.Identify:
                return(AddChild(Syntax_Node.Create <Syntax_Function>(data, this)));

            default:
            {
                var exception = new SyntaxException(Syntax.Error.InvalidToken);
                exception.content = data.token.ToString();
                throw exception;
            }
            }
        }
Ejemplo n.º 2
0
 internal override void DoConstruct(Lex.Data data)
 {
     base.DoConstruct(data);
     name       = data.str;
     phase      = Phase.ParamsBegin;
     paramType_ = null;
 }
Ejemplo n.º 3
0
        internal override Syntax_Node ParseLex(Lex.Data data)
        {
            switch (phase)
            {
            case Phase.None:
                if (Token.Operator == data.token &&
                    Operator.S_Brackets_Beg == (Operator)data.number.i_32)
                {
                    phase         = Phase.Condition;
                    tailCondition = false;
                    return(this);
                }
                else
                {
                    phase         = Phase.Code;
                    tailCondition = true;
                    return(ParseLex(data));
                }

            case Phase.Condition:
                if (Token.Operator == data.token &&
                    Operator.S_Brackets_End == (Operator)data.number.i_32)
                {
                    if (tailCondition)
                    {
                        return(parent_);
                    }
                    else
                    {
                        phase = Phase.Code;
                        return(this);
                    }
                }
                // TODO
                break;

            case Phase.Code:
                if (Token.Keyword == data.token)
                {
                    var keyword = (Keyword)data.number.i_32;
                    if (tailCondition)
                    {
                        if (Keyword.Until == keyword)
                        {
                            phase = Phase.Condition;
                            return(this);
                        }
                    }
                    else
                    {
                        if (Keyword.End == keyword)
                        {
                            return(parent_);
                        }
                    }
                }
                break;
            }
            return(base.ParseLex(data));
        }
Ejemplo n.º 4
0
        public static T Create <T>(Lex.Data data, Syntax_Node parent) where T : Syntax_Node, new()
        {
            // TODO reuse
            var node = new T();

            node.Construct(data, parent);
            return(node);
        }
Ejemplo n.º 5
0
        internal override Syntax_Node ParseLex(Lex.Data data)
        {
            switch (phase)
            {
            case Phase.ConditionBegin:
                if (Token.Operator == data.token &&
                    Operator.S_Brackets_Beg == (Operator)data.number.i_32)
                {
                    phase = Phase.Condition;
                    return(this);
                }
                else
                {
                    var exception = new SyntaxException(Syntax.Error.InvalidFunction);
                    exception.content = "Need\"(\"";
                    throw exception;
                }

            case Phase.Condition:
                if (Token.Operator == data.token &&
                    Operator.S_Brackets_End == (Operator)data.number.i_32)
                {
                    phase = Phase.Code;
                    return(this);
                }
                // TODO
                break;

            case Phase.Code:
                if (Token.Keyword == data.token)
                {
                    var keyword = (Keyword)data.number.i_32;
                    switch (keyword)
                    {
                    case Keyword.Elseif:
                        phase = Phase.ConditionBegin;
                        return(this);

                    case Keyword.Else:
                        phase = Phase.LastCode;
                        return(this);

                    case Keyword.End:
                        return(parent_);
                    }
                }
                break;

            case Phase.LastCode:
                if (Token.Keyword == data.token &&
                    Keyword.End == (Keyword)data.number.i_32)
                {
                    return(parent_);
                }
                break;
            }
            return(base.ParseLex(data));
        }
Ejemplo n.º 6
0
 internal override Syntax_Node ParseLex(Lex.Data data)
 {
     if (Token.Keyword == data.token &&
         Keyword.End == (Keyword)data.number.i_32)
     {
         return(parent_);
     }
     return(base.ParseLex(data));
 }
Ejemplo n.º 7
0
 internal static void LexDataReceiver(Lex.Data data, Context context)
 {
                 #if LOG_LEX
     Log_LexData(data);
                 #endif
     try
     {
         context.node = context.node.ParseLex(data);
     }
     catch (SyntaxException e)
     {
         e.line = data.line;
         e.row  = data.row;
         e.col  = data.col;
         throw e;
     }
 }
Ejemplo n.º 8
0
 internal abstract Syntax_Node ParseLex(Lex.Data data);
Ejemplo n.º 9
0
 internal virtual void DoConstruct(Lex.Data data)
 {
 }
Ejemplo n.º 10
0
 internal void Construct(Lex.Data data, Syntax_Node p)
 {
     parent_ = p;
     DoConstruct(data);
 }
Ejemplo n.º 11
0
 internal override Syntax_Node ParseLex(Lex.Data data)
 {
     return(this);
 }
Ejemplo n.º 12
0
 internal override void DoConstruct(Lex.Data data)
 {
 }
Ejemplo n.º 13
0
        internal override Syntax_Node ParseLex(Lex.Data data)
        {
            switch (phase)
            {
            case Phase.ParamsBegin:
                if (Token.Operator == data.token &&
                    Operator.S_Brackets_Beg == (Operator)data.number.i_32)
                {
                    phase = Phase.ParamType;
                    return(this);
                }
                else
                {
                    var exception = new SyntaxException(Syntax.Error.InvalidFunction);
                    exception.content = "Need\"(\"";
                    throw exception;
                }

            case Phase.ParamType:
                switch (data.token)
                {
                case Token.Operator:
                    if (Operator.S_Brackets_End == (Operator)data.number.i_32)
                    {
                        phase = Phase.Code;
                        return(this);
                    }
                    else
                    {
                        var exception = new SyntaxException(Syntax.Error.InvalidOperator);
                        exception.content = ((Operator)data.number.i_32).ToString();
                        throw exception;
                    }

                case Token.Keyword:
                    if (Syntax.typeKeywordList.Contains((Keyword)data.number.i_32))
                    {
                        paramType_ = data;
                        phase      = Phase.ParamName;
                        return(this);
                    }
                    else
                    {
                        var exception = new SyntaxException(Syntax.Error.InvalidKeyword);
                        exception.content = ((Keyword)data.number.i_32).ToString();
                        throw exception;
                    }

                case Token.Identify:
                    paramType_ = data;
                    phase      = Phase.ParamName;
                    return(this);

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

            case Phase.ParamName:
                if (Token.Identify == data.token)
                {
                    if (null == paramList)
                    {
                        paramList = new List <KeyValuePair <Lex.Data, Lex.Data> >();
                    }
                    paramList.Add(new KeyValuePair <Lex.Data, Lex.Data>(paramType_, data));
                    paramType_ = null;
                    phase      = Phase.ParamSeparator;
                    return(this);
                }
                else
                {
                    var exception = new SyntaxException(Syntax.Error.InvalidToken);
                    exception.content = data.token.ToString();
                    throw exception;
                }

            case Phase.ParamSeparator:
                if (Token.Operator == data.token)
                {
                    var op = (Operator)data.number.i_32;
                    switch (op)
                    {
                    case Operator.L_Brackets_End:
                        phase = Phase.Code;
                        return(this);

                    case Operator.Comma:
                        phase = Phase.ParamType;
                        return(this);

                    default:
                    {
                        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;
                }

            case Phase.Code:
                if (Token.Keyword == data.token &&
                    Keyword.End == (Keyword)data.number.i_32)
                {
                    return(parent_);
                }
                break;
            }
            return(base.ParseLex(data));
        }
Ejemplo n.º 14
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);
        }
Ejemplo n.º 15
0
 internal override void DoConstruct(Lex.Data data)
 {
     base.DoConstruct(data);
     codePhase = CodePhase.Code;
 }
Ejemplo n.º 16
0
 internal override void DoConstruct(Lex.Data data)
 {
     base.DoConstruct(data);
     phase         = Phase.None;
     tailCondition = false;
 }
Ejemplo n.º 17
0
 internal override void DoConstruct(Lex.Data data)
 {
     base.DoConstruct(data);
     phase = Phase.ConditionBegin;
 }
Ejemplo n.º 18
0
        public static void Log_LexData(Lex.Data data)
        {
            switch (data.token)
            {
            case Token.Keyword:
                Console.ForegroundColor = ConsoleColor.Blue;
                Console.WriteLine((Keyword)data.number.i_32);
                break;

            case Token.Identify:
                Console.ForegroundColor = ConsoleColor.Black;
                Console.WriteLine(data.str);
                break;

            case Token.Operator:
                Console.ForegroundColor = ConsoleColor.Magenta;
                Console.WriteLine((Operator)data.number.i_32);
                break;

            case Token.Int8:
                Console.ForegroundColor = ConsoleColor.DarkYellow;
                Console.WriteLine(data.number.i_8);
                break;

            case Token.UInt8:
                Console.ForegroundColor = ConsoleColor.DarkYellow;
                Console.WriteLine(data.number.ui_8);
                break;

            case Token.Int16:
                Console.ForegroundColor = ConsoleColor.DarkYellow;
                Console.WriteLine(data.number.i_16);
                break;

            case Token.UInt16:
                Console.ForegroundColor = ConsoleColor.DarkYellow;
                Console.WriteLine(data.number.ui_16);
                break;

            case Token.Int32:
                Console.ForegroundColor = ConsoleColor.DarkYellow;
                Console.WriteLine(data.number.i_32);
                break;

            case Token.UInt32:
                Console.ForegroundColor = ConsoleColor.DarkYellow;
                Console.WriteLine(data.number.ui_32);
                break;

            case Token.Int64:
                Console.ForegroundColor = ConsoleColor.DarkYellow;
                Console.WriteLine(data.number.i_64);
                break;

            case Token.UInt64:
                Console.ForegroundColor = ConsoleColor.DarkYellow;
                Console.WriteLine(data.number.ui_64);
                break;

            case Token.Float:
                Console.ForegroundColor = ConsoleColor.DarkYellow;
                Console.WriteLine(data.number.f);
                break;

            case Token.Double:
                Console.ForegroundColor = ConsoleColor.DarkYellow;
                Console.WriteLine(data.number.d);
                break;

            case Token.String:
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine(data.str);
                break;
            }
        }