Пример #1
0
        public void ParseList(Token token, ICodeNode parent, TokenType terminator, ErrorCode error)
        {
            var terminator_set = new HashSet<TokenType>(STMT_START_SET);
            terminator_set.Add(terminator);

            while(!token.IsEof && token.TokenType != terminator)
            {
                // parse a statement. The parent node adopts the statement node.
                ICodeNode statement_node = Parse(token);
                parent.Add(statement_node);
                token = InternalScanner.CurrentToken;

                // look for the semicolon between the statements.
                if (token.TokenType == TokenType.SEMICOLON)
                {
                    token = InternalScanner.GetNextToken();
                }
                else if (STMT_START_SET.Contains(token.TokenType))
                {
                    ErrorHandler.Flag(token, ErrorCode.MISSING_SEMICOLON, this);
                }

                // Synchronize at the start of the next statement
                // or at the terminator.
                token = Parser.Synchronize(terminator_set, InternalScanner, this);
            }

            // look for the terminator token
            if (token.TokenType == terminator)
            {
                token = InternalScanner.GetNextToken();
            } else
            {
                ErrorHandler.Flag(token, error, this);
            }
        }
Пример #2
0
        private void ParseConstantList(Token token, ICodeNode constants_node, HashSet<object> constant_set)
        {
            // loop to parse each constant.
            while (CONSTANT_START_SET.Contains(token.TokenType))
            {
                // the constants list node adopts the constant node.
                constants_node.Add(ParseConstant(token, constant_set));

                // synchronize at the comma between constants.
                token = Parser.Synchronize(COMMA_SET, InternalScanner, this);

                // look for the COMMA
                if (token.TokenType == TokenType.COMMA)
                {
                    token = InternalScanner.GetNextToken(); // consume the ,
                } else if (CONSTANT_START_SET.Contains(token.TokenType))
                {
                    ErrorHandler.Flag(token, ErrorCode.MISSING_COMMA, this);
                }
            }
        }