예제 #1
0
파일: Parser.cs 프로젝트: mqrelly/Syntan
        private void Step2()
        {
            #if DEBUG
            if( this.action.Type != ParserTable.ActionType.Step )
                throw new InternalParserException(string.Format(
                    "Internal state is {0}, but ActionType.Reduction expected.",
                    this.action.Type));

            if( this.phase != ParsingPhase.Step1 )
                throw new InternalParserException(string.Format(
                    "Internal phase is {0}, but ParsingPhase.Step1 expected.",
                    this.phase));
            #endif

            this.phase = ParsingPhase.Step2;
            this.stack.Push(this.action.Argument, this.CurrentInputSymbol);

            if( !this.input.MoveNext() )
                throw new UnexpectedEndOfSourceException();
        }
예제 #2
0
파일: Parser.cs 프로젝트: mqrelly/Syntan
        private void Reduction3()
        {
            #if DEBUG
            if( this.action.Type != ParserTable.ActionType.Reduction )
                throw new InternalParserException(string.Format(
                    "Internal state is {0}, but ActionType.Reduction expected.",
                    this.action.Type));

            if( this.phase != ParsingPhase.Reduction2 )
                throw new InternalParserException(string.Format(
                    "Internal phase is {0}, but ParsingPhase.Reduction2 expected.",
                    this.phase));
            #endif

            this.phase = ParsingPhase.Reduction3;
            this.stack.Push(this.goto_state, this.reduction_rule.LeftHandSide);
            this.reduction_rule = null;
        }
예제 #3
0
파일: Parser.cs 프로젝트: mqrelly/Syntan
        private void Step1()
        {
            #if DEBUG
            if( this.action.Type != ParserTable.ActionType.Step )
                throw new InternalParserException(string.Format(
                    "Internal state is {0}, but ActionType.Step expected.",
                    this.action.Type));
            #endif

            this.phase = ParsingPhase.Step1;
        }
예제 #4
0
파일: Parser.cs 프로젝트: mqrelly/Syntan
        /// <summary>
        /// Default constructor.
        /// </summary>
        public Parser()
        {
            this.stack = new ParserStack();

            this.phase = ParsingPhase.NotParsing;
        }
예제 #5
0
파일: Parser.cs 프로젝트: mqrelly/Syntan
        private void Reduction2()
        {
            #if DEBUG
            if( this.action.Type != ParserTable.ActionType.Reduction )
                throw new InternalParserException(string.Format(
                    "Internal state is {0}, but ActionType.Reduction expected.",
                    this.action.Type));

            if( this.phase != ParsingPhase.Reduction1 )
                throw new InternalParserException(string.Format(
                    "Internal phase is {0}, but ParsingPhase.Reduction1 expected.",
                    this.phase));
            #endif

            this.phase = ParsingPhase.Reduction2;
            for( int i = 0; i < this.reduction_rule.RightHandSide.Count; ++i )
                this.stack.Pop();
            this.goto_state = this.table.GetGoto(this.CurrentState, this.grammar.IndexOf(this.reduction_rule.LeftHandSide));
            if( this.goto_state == -1 )
                this.phase = ParsingPhase.Error;
        }
예제 #6
0
파일: Parser.cs 프로젝트: mqrelly/Syntan
        private void Reduction1()
        {
            #if DEBUG
            if( this.action.Type != ParserTable.ActionType.Reduction )
                throw new InternalParserException(string.Format(
                    "Internal state is {0}, but ActionType.Reduction expected.",
                    this.action.Type));
            #endif

            this.phase = ParsingPhase.Reduction1;
            this.reduction_rule = this.grammar.Rules[this.action.Argument];
        }
예제 #7
0
파일: Parser.cs 프로젝트: mqrelly/Syntan
        private void BeginNewPhase()
        {
            this.action = this.table.GetAction(this.CurrentState, this.grammar.IndexOf(this.CurrentInputSymbol));
            switch( this.action.Type )
            {
            case ParserTable.ActionType.Accept:
                this.phase = ParsingPhase.Accept;
                break;

            case ParserTable.ActionType.Error:
                this.phase = ParsingPhase.Error;
                break;

            case ParserTable.ActionType.Reduction:
                this.Reduction1();
                break;

            case ParserTable.ActionType.Step:
                this.Step1();
                break;

            default:
                throw new NotSupportedException(string.Format("ActionType '{0}' not supported.", this.action.Type.ToString()));
            }

            this.step_count += 1;
        }
예제 #8
0
파일: Parser.cs 프로젝트: mqrelly/Syntan
        /// <summary>
        /// Stops the ongoing parsing. If it was not parsing, it will have no effect.
        /// </summary>
        public void Stop()
        {
            if( !this.IsParsing )
                return;

            this.phase = ParsingPhase.NotParsing;
            this.input = null;

            this.OnPhaseChanged();
        }