Interpreter.frontend.pascal.parsers.StatementParser.ParseList C# (CSharp) Method

ParseList() protected method

protected ParseList ( Token token, ICodeNode parentNode, PascalTokenType terminator, PascalErrorCode errorCode ) : void
token Token
parentNode ICodeNode
terminator PascalTokenType
errorCode PascalErrorCode
return void
        protected internal void ParseList(Token token, ICodeNode parentNode, PascalTokenType terminator, PascalErrorCode errorCode)
        {
            // Loop to parse each statement until the END token or the end of the source file.
            while (!(token is EofToken) && (token.type != terminator))
            {
                // Parse a statement.  The parent node adopts the statement node.
                ICodeNode statementNode = Parse(token);
                parentNode.AddChild(statementNode);

                token = CurrentToken();
                TokenType tokenType = token.type;

                // Look for semicolon between statements.
                if (tokenType == PascalTokenType.SEMICOLON)
                    token = NextToken();

                // If at the start of the next assignment statement, then missing a semicolon.
                else if (tokenType == PascalTokenType.IDENTIFIER)
                    errorHandler.flag(token, PascalErrorCode.MISSING_SEMICOLON, this);

                else if (tokenType != terminator)
                {
                    errorHandler.flag(token, PascalErrorCode.UNEXPECTED_TOKEN, this);
                    token = NextToken();
                }
            }

            if (token.type == terminator)
                token = NextToken();
            else
                errorHandler.flag(token, errorCode, this);
        }

Usage Example

コード例 #1
0
        // Parse a compound statement.
        public override ICodeNode Parse(Token token)
        {
            token = NextToken();

            // Create the compound node.
            ICodeNode compoundNode = ICodeFactory.CreateICodeNode(ICodeNodeTypeImplementation.COMPOUND);

            // Parse the statement list terminated by the END token.
            StatementParser statementParser = new StatementParser(this);
            statementParser.ParseList(token, compoundNode, PascalTokenType.END, PascalErrorCode.MISSING_END);

            return compoundNode;
        }
All Usage Examples Of Interpreter.frontend.pascal.parsers.StatementParser::ParseList