Esempio n. 1
0
        // <Factor> ::= "PRODNAME" |
        //              "STRING" |
        //              "(" <Expression> ")" |
        //              "[" <Expression> "]" |
        //              "{" <Expression> "}" .
        private void ParseFactor()
        {
            ParseAction();

            _astBuilder.BeginFactor(_scanner.CurrentToken);

            switch (_scanner.CurrentToken.TokenKind)
            {
            case TokenKind.Identifier:
                _astBuilder.FoundProduction(_scanner.CurrentToken);
                _scanner.Advance();
                break;

            case TokenKind.String:
                _astBuilder.FoundTerminal(_scanner.CurrentToken);
                _scanner.Advance();
                break;

            case TokenKind.LeftParen:
                _astBuilder.BeginParens(_scanner.CurrentToken);
                _scanner.Advance();
                ParseExpression();
                Match(TokenKind.RightParen);
                _astBuilder.EndParens();
                _scanner.Advance();
                break;

            case TokenKind.LeftBracket:
                _astBuilder.BeginOption(_scanner.CurrentToken);
                _scanner.Advance();
                ParseExpression();
                Match(TokenKind.RightBracket);
                _astBuilder.EndOption();
                _scanner.Advance();
                break;

            case TokenKind.LeftBrace:
                _astBuilder.BeginKleene(_scanner.CurrentToken);
                _scanner.Advance();
                ParseExpression();
                Match(TokenKind.RightBrace);
                _astBuilder.EndKleene();
                _scanner.Advance();
                break;
            }

            ParseAction();

            _astBuilder.EndFactor();
        }