コード例 #1
0
        private void ParseSharp()
        {
            Token token = this.ReadToken();

            if (token.Type == Scorpio.Compiler.TokenType.Define)
            {
                if (this.m_scriptExecutable.m_Block != Executable_Block.Context)
                {
                    throw new ParserException("#define只能使用在上下文", token);
                }
                this.m_script.PushDefine(this.ReadIdentifier());
            }
            else if (token.Type == Scorpio.Compiler.TokenType.If)
            {
                if (this.m_define == null)
                {
                    if (this.IsDefine())
                    {
                        this.m_define = new DefineState(DefineType.Already);
                    }
                    else
                    {
                        this.m_define = new DefineState(DefineType.Being);
                        this.PopSharp();
                    }
                }
                else if (this.m_define.State == DefineType.Already)
                {
                    if (this.IsDefine())
                    {
                        this.m_Defines.Push(this.m_define);
                        this.m_define = new DefineState(DefineType.Already);
                    }
                    else
                    {
                        this.m_Defines.Push(this.m_define);
                        this.m_define = new DefineState(DefineType.Being);
                        this.PopSharp();
                    }
                }
                else if (this.m_define.State == DefineType.Being)
                {
                    this.m_Defines.Push(this.m_define);
                    this.m_define = new DefineState(DefineType.Break);
                    this.PopSharp();
                }
                else if (this.m_define.State == DefineType.Break)
                {
                    this.m_Defines.Push(this.m_define);
                    this.m_define = new DefineState(DefineType.Break);
                    this.PopSharp();
                }
            }
            else if (token.Type == Scorpio.Compiler.TokenType.Ifndef)
            {
                if (this.m_define == null)
                {
                    if (!this.IsDefine())
                    {
                        this.m_define = new DefineState(DefineType.Already);
                    }
                    else
                    {
                        this.m_define = new DefineState(DefineType.Being);
                        this.PopSharp();
                    }
                }
                else if (this.m_define.State == DefineType.Already)
                {
                    if (!this.IsDefine())
                    {
                        this.m_Defines.Push(this.m_define);
                        this.m_define = new DefineState(DefineType.Already);
                    }
                    else
                    {
                        this.m_Defines.Push(this.m_define);
                        this.m_define = new DefineState(DefineType.Being);
                        this.PopSharp();
                    }
                }
                else if (this.m_define.State == DefineType.Being)
                {
                    this.m_Defines.Push(this.m_define);
                    this.m_define = new DefineState(DefineType.Break);
                    this.PopSharp();
                }
            }
            else if (token.Type == Scorpio.Compiler.TokenType.ElseIf)
            {
                if (this.m_define == null)
                {
                    throw new ParserException("未找到#if或#ifndef", token);
                }
                if ((this.m_define.State == DefineType.Already) || (this.m_define.State == DefineType.Break))
                {
                    this.m_define.State = DefineType.Break;
                    this.PopSharp();
                }
                else if (this.IsDefine())
                {
                    this.m_define.State = DefineType.Already;
                }
                else
                {
                    this.m_define.State = DefineType.Being;
                    this.PopSharp();
                }
            }
            else if (token.Type == Scorpio.Compiler.TokenType.Else)
            {
                if (this.m_define == null)
                {
                    throw new ParserException("未找到#if或#ifndef", token);
                }
                if ((this.m_define.State == DefineType.Already) || (this.m_define.State == DefineType.Break))
                {
                    this.m_define.State = DefineType.Break;
                    this.PopSharp();
                }
                else
                {
                    this.m_define.State = DefineType.Already;
                }
            }
            else
            {
                if (token.Type != Scorpio.Compiler.TokenType.Endif)
                {
                    throw new ParserException("#后缀不支持" + token.Type, token);
                }
                if (this.m_define == null)
                {
                    throw new ParserException("未找到#if或#ifndef", token);
                }
                if (this.m_Defines.Count > 0)
                {
                    this.m_define = this.m_Defines.Pop();
                    if (this.m_define.State == DefineType.Break)
                    {
                        this.PopSharp();
                    }
                }
                else
                {
                    this.m_define = null;
                }
            }
        }
コード例 #2
0
 //解析 #
 private void ParseSharp() {
     Token token = ReadToken();
     if (token.Type == TokenType.Define) {
         if (m_scriptExecutable.m_Block != Executable_Block.Context)
             throw new ParserException("#define只能使用在上下文", token);
         m_script.PushDefine(ReadIdentifier());
     } else if (token.Type == TokenType.If) {
         if (m_define == null) {
             if (IsDefine()) {
                 m_define = new DefineState(DefineType.Already);
             } else {
                 m_define = new DefineState(DefineType.Being);
                 PopSharp();
             }
         } else if (m_define.State == DefineType.Already) {
             if (IsDefine()) {
                 m_Defines.Push(m_define);
                 m_define = new DefineState(DefineType.Already);
             } else {
                 m_Defines.Push(m_define);
                 m_define = new DefineState(DefineType.Being);
                 PopSharp();
             }
         } else if (m_define.State == DefineType.Being) {
             m_Defines.Push(m_define);
             m_define = new DefineState(DefineType.Break);
             PopSharp();
         } else if (m_define.State == DefineType.Break) {
             m_Defines.Push(m_define);
             m_define = new DefineState(DefineType.Break);
             PopSharp();
         }
     } else if (token.Type == TokenType.Ifndef) {
         if (m_define == null) {
             if (!IsDefine()) {
                 m_define = new DefineState(DefineType.Already);
             } else {
                 m_define = new DefineState(DefineType.Being);
                 PopSharp();
             }
         } else if (m_define.State == DefineType.Already) {
             if (!IsDefine()) {
                 m_Defines.Push(m_define);
                 m_define = new DefineState(DefineType.Already);
             } else {
                 m_Defines.Push(m_define);
                 m_define = new DefineState(DefineType.Being);
                 PopSharp();
             }
         } else if (m_define.State == DefineType.Being) {
             m_Defines.Push(m_define);
             m_define = new DefineState(DefineType.Break);
             PopSharp();
         }
     } else if (token.Type == TokenType.ElseIf) {
         if (m_define == null) {
             throw new ParserException("未找到#if或#ifndef", token);
         } else if (m_define.State == DefineType.Already || m_define.State == DefineType.Break) {
             m_define.State = DefineType.Break;
             PopSharp();
         } else if (IsDefine()) {
             m_define.State = DefineType.Already;
         } else {
             m_define.State = DefineType.Being;
             PopSharp();
         }
     } else if (token.Type == TokenType.Else) {
         if (m_define == null) {
             throw new ParserException("未找到#if或#ifndef", token);
         } else if (m_define.State == DefineType.Already || m_define.State == DefineType.Break) {
             m_define.State = DefineType.Break;
             PopSharp();
         } else {
             m_define.State = DefineType.Already;
         }
     } else if (token.Type == TokenType.Endif) {
         if (m_define == null) {
             throw new ParserException("未找到#if或#ifndef", token);
         } else if (m_Defines.Count > 0) {
             m_define = m_Defines.Pop();
             if (m_define.State == DefineType.Break)
                 PopSharp();
         } else {
             m_define = null;
         }
     } else {
         throw new ParserException("#后缀不支持" + token.Type, token);
     }
 }
コード例 #3
0
        //解析 #
        private void ParseSharp()
        {
            Token token = ReadToken();

            if (token.Type == TokenType.Define)
            {
                if (m_scriptExecutable.m_Block != Executable_Block.Context)
                {
                    throw new ParserException("#define只能使用在上下文", token);
                }
                m_script.PushDefine(ReadIdentifier());
            }
            else if (token.Type == TokenType.If)
            {
                if (m_define == null)
                {
                    if (IsDefine())
                    {
                        m_define = new DefineState(DefineType.Already);
                    }
                    else
                    {
                        m_define = new DefineState(DefineType.Being);
                        PopSharp();
                    }
                }
                else if (m_define.State == DefineType.Already)
                {
                    if (IsDefine())
                    {
                        m_Defines.Push(m_define);
                        m_define = new DefineState(DefineType.Already);
                    }
                    else
                    {
                        m_Defines.Push(m_define);
                        m_define = new DefineState(DefineType.Being);
                        PopSharp();
                    }
                }
                else if (m_define.State == DefineType.Being)
                {
                    m_Defines.Push(m_define);
                    m_define = new DefineState(DefineType.Break);
                    PopSharp();
                }
                else if (m_define.State == DefineType.Break)
                {
                    m_Defines.Push(m_define);
                    m_define = new DefineState(DefineType.Break);
                    PopSharp();
                }
            }
            else if (token.Type == TokenType.Ifndef)
            {
                if (m_define == null)
                {
                    if (!IsDefine())
                    {
                        m_define = new DefineState(DefineType.Already);
                    }
                    else
                    {
                        m_define = new DefineState(DefineType.Being);
                        PopSharp();
                    }
                }
                else if (m_define.State == DefineType.Already)
                {
                    if (!IsDefine())
                    {
                        m_Defines.Push(m_define);
                        m_define = new DefineState(DefineType.Already);
                    }
                    else
                    {
                        m_Defines.Push(m_define);
                        m_define = new DefineState(DefineType.Being);
                        PopSharp();
                    }
                }
                else if (m_define.State == DefineType.Being)
                {
                    m_Defines.Push(m_define);
                    m_define = new DefineState(DefineType.Break);
                    PopSharp();
                }
            }
            else if (token.Type == TokenType.ElseIf)
            {
                if (m_define == null)
                {
                    throw new ParserException("未找到#if或#ifndef", token);
                }
                else if (m_define.State == DefineType.Already || m_define.State == DefineType.Break)
                {
                    m_define.State = DefineType.Break;
                    PopSharp();
                }
                else if (IsDefine())
                {
                    m_define.State = DefineType.Already;
                }
                else
                {
                    m_define.State = DefineType.Being;
                    PopSharp();
                }
            }
            else if (token.Type == TokenType.Else)
            {
                if (m_define == null)
                {
                    throw new ParserException("未找到#if或#ifndef", token);
                }
                else if (m_define.State == DefineType.Already || m_define.State == DefineType.Break)
                {
                    m_define.State = DefineType.Break;
                    PopSharp();
                }
                else
                {
                    m_define.State = DefineType.Already;
                }
            }
            else if (token.Type == TokenType.Endif)
            {
                if (m_define == null)
                {
                    throw new ParserException("未找到#if或#ifndef", token);
                }
                else if (m_Defines.Count > 0)
                {
                    m_define = m_Defines.Pop();
                    if (m_define.State == DefineType.Break)
                    {
                        PopSharp();
                    }
                }
                else
                {
                    m_define = null;
                }
            }
            else
            {
                throw new ParserException("#后缀不支持" + token.Type, token);
            }
        }