GetToken() public method

public GetToken ( TokenType type ) : Token
type TokenType
return Token
Ejemplo n.º 1
0
        private void ParseStart(ParseNode parent)
        {
            Token     tok;
            ParseNode n;
            ParseNode node = parent.CreateNode(scanner.GetToken(TokenType.Start), "Start");

            parent.Nodes.Add(node);



            tok = scanner.LookAhead(TokenType.CLASS);
            while (tok.Type == TokenType.CLASS)
            {
                ParseClass(node);
                tok = scanner.LookAhead(TokenType.CLASS);
            }


            tok = scanner.Scan(TokenType.EOF);
            n   = node.CreateNode(tok, tok.ToString());
            node.Token.UpdateRange(tok);
            node.Nodes.Add(n);
            if (tok.Type != TokenType.EOF)
            {
                tree.Errors.Add(new ParseError("Unexpected token '" + tok.Text.Replace("\n", "") + "' found. Expected " + TokenType.EOF.ToString(), 0x1001, 0, tok.StartPos, tok.StartPos, tok.Length));
                return;
            }

            parent.Token.UpdateRange(node.Token);
        }
Ejemplo n.º 2
0
        private void ParseStart(ParseNode parent) // NonTerminalSymbol: Start
        {
            Token tok;
            ParseNode n;
            ParseNode node = parent.CreateNode(scanner.GetToken(TokenType.Start), "Start");
            parent.Nodes.Add(node);


             // Concat Rule
            do { // OneOrMore Rule
                ParseAddExpr(node); // NonTerminal Rule: AddExpr
            tok = scanner.LookAhead(TokenType.NUMBER, TokenType.BROPEN); // OneOrMore Rule

                || tok.Type == TokenType.NUMBER
                || tok.Type == TokenType.BROPEN); // OneOrMore Rule

             // Concat Rule
            tok = scanner.Scan(TokenType.EOF); // Terminal Rule: EOF
            if (tok.Type != TokenType.EOF)
                tree.Errors.Add(new ParseError("Unexpected token '" + tok.Text.Replace("\n", "") + "' found. Expected " + TokenType.EOF.ToString(), 0x1001, 0, tok.StartPos, tok.StartPos, tok.Length));
            n = node.CreateNode(tok, tok.ToString() );
            node.Token.UpdateRange(tok);
            node.Nodes.Add(n);

            parent.Token.UpdateRange(node.Token);
        } // NonTerminalSymbol: Start
Ejemplo n.º 3
0
        private void ParseStart(ParseNode parent) // NonTerminalSymbol: Start
        {
            Token     tok;
            ParseNode n;
            ParseNode node = parent.CreateNode(scanner.GetToken(TokenType.Start), "Start");

            parent.Nodes.Add(node);


            // Concat Rule
            tok = scanner.LookAhead(TokenType.ANY_TEXT, TokenType.ANY_SYMBOL, TokenType.IdKeyword1, TokenType.IdKeyword2, TokenType.TimeKeyword, TokenType.CommentKeyword1, TokenType.CommentKeyword2, TokenType.CommentKeyword3, TokenType.CommentKeyword4, TokenType.StatusKeyword1, TokenType.StatusKeyword2); // ZeroOrMore Rule
            while (tok.Type == TokenType.ANY_TEXT ||
                   tok.Type == TokenType.ANY_SYMBOL ||
                   tok.Type == TokenType.IdKeyword1 ||
                   tok.Type == TokenType.IdKeyword2 ||
                   tok.Type == TokenType.TimeKeyword ||
                   tok.Type == TokenType.CommentKeyword1 ||
                   tok.Type == TokenType.CommentKeyword2 ||
                   tok.Type == TokenType.CommentKeyword3 ||
                   tok.Type == TokenType.CommentKeyword4 ||
                   tok.Type == TokenType.StatusKeyword1 ||
                   tok.Type == TokenType.StatusKeyword2)
            {
                ParseActionNode(node);                                                                                                                                                                                                                                                                                // NonTerminal Rule: ActionNode
                tok = scanner.LookAhead(TokenType.ANY_TEXT, TokenType.ANY_SYMBOL, TokenType.IdKeyword1, TokenType.IdKeyword2, TokenType.TimeKeyword, TokenType.CommentKeyword1, TokenType.CommentKeyword2, TokenType.CommentKeyword3, TokenType.CommentKeyword4, TokenType.StatusKeyword1, TokenType.StatusKeyword2); // ZeroOrMore Rule
            }

            // Concat Rule
            tok = scanner.Scan(TokenType.EOF); // Terminal Rule: EOF
            n   = node.CreateNode(tok, tok.ToString());
            node.Token.UpdateRange(tok);
            node.Nodes.Add(n);
            if (tok.Type != TokenType.EOF)
            {
                tree.Errors.Add(new ParseError("Unexpected token '" + tok.Text.Replace("\n", "") + "' found. Expected " + TokenType.EOF.ToString(), 0x1001, 0, tok.StartPos, tok.StartPos, tok.Length));
                return;
            }

            parent.Token.UpdateRange(node.Token);
        } // NonTerminalSymbol: Start
Ejemplo n.º 4
0
        private void ParseStart(ParseNode parent)
        {
            Token     tok;
            ParseNode n;
            ParseNode node = parent.CreateNode(scanner.GetToken(TokenType.Start), "Start");

            parent.Nodes.Add(node);



            tok = scanner.LookAhead(TokenType.ATTRIBUTEOPEN, TokenType.WHITESPACE, TokenType.GRAMMARSTRING, TokenType.GRAMMARARROW, TokenType.GRAMMARNONKEYWORD, TokenType.GRAMMARKEYWORD, TokenType.CODEBLOCKOPEN, TokenType.DIRECTIVEOPEN, TokenType.GRAMMARCOMMENTLINE, TokenType.GRAMMARCOMMENTBLOCK);
            while (tok.Type == TokenType.ATTRIBUTEOPEN ||
                   tok.Type == TokenType.WHITESPACE ||
                   tok.Type == TokenType.GRAMMARSTRING ||
                   tok.Type == TokenType.GRAMMARARROW ||
                   tok.Type == TokenType.GRAMMARNONKEYWORD ||
                   tok.Type == TokenType.GRAMMARKEYWORD ||
                   tok.Type == TokenType.CODEBLOCKOPEN ||
                   tok.Type == TokenType.DIRECTIVEOPEN ||
                   tok.Type == TokenType.GRAMMARCOMMENTLINE ||
                   tok.Type == TokenType.GRAMMARCOMMENTBLOCK)
            {
                tok = scanner.LookAhead(TokenType.ATTRIBUTEOPEN, TokenType.WHITESPACE, TokenType.GRAMMARSTRING, TokenType.GRAMMARARROW, TokenType.GRAMMARNONKEYWORD, TokenType.GRAMMARKEYWORD, TokenType.CODEBLOCKOPEN, TokenType.DIRECTIVEOPEN, TokenType.GRAMMARCOMMENTLINE, TokenType.GRAMMARCOMMENTBLOCK);
                switch (tok.Type)
                {
                case TokenType.ATTRIBUTEOPEN:
                    ParseAttributeBlock(node);
                    break;

                case TokenType.WHITESPACE:
                case TokenType.GRAMMARSTRING:
                case TokenType.GRAMMARARROW:
                case TokenType.GRAMMARNONKEYWORD:
                case TokenType.GRAMMARKEYWORD:
                    ParseGrammarBlock(node);
                    break;

                case TokenType.CODEBLOCKOPEN:
                    ParseCodeBlock(node);
                    break;

                case TokenType.DIRECTIVEOPEN:
                    ParseDirectiveBlock(node);
                    break;

                case TokenType.GRAMMARCOMMENTLINE:
                case TokenType.GRAMMARCOMMENTBLOCK:
                    ParseCommentBlock(node);
                    break;

                default:
                    tree.Errors.Add(new ParseError("Unexpected token '" + tok.Text.Replace("\n", "") + "' found.", 0x0002, 0, tok.StartPos, tok.StartPos, tok.Length));
                    break;
                }
                tok = scanner.LookAhead(TokenType.ATTRIBUTEOPEN, TokenType.WHITESPACE, TokenType.GRAMMARSTRING, TokenType.GRAMMARARROW, TokenType.GRAMMARNONKEYWORD, TokenType.GRAMMARKEYWORD, TokenType.CODEBLOCKOPEN, TokenType.DIRECTIVEOPEN, TokenType.GRAMMARCOMMENTLINE, TokenType.GRAMMARCOMMENTBLOCK);
            }


            tok = scanner.Scan(TokenType.EOF);
            n   = node.CreateNode(tok, tok.ToString());
            node.Token.UpdateRange(tok);
            node.Nodes.Add(n);
            if (tok.Type != TokenType.EOF)
            {
                tree.Errors.Add(new ParseError("Unexpected token '" + tok.Text.Replace("\n", "") + "' found. Expected " + TokenType.EOF.ToString(), 0x1001, 0, tok.StartPos, tok.StartPos, tok.Length));
                return;
            }

            parent.Token.UpdateRange(node.Token);
        }
Ejemplo n.º 5
0
        private void ParseStart(ParseNode parent)
        {
            Token     tok;
            ParseNode n;
            ParseNode node = parent.CreateNode(scanner.GetToken(TokenType.Start), "Start");

            parent.Nodes.Add(node);



            tok = scanner.LookAhead(TokenType.DIRECTIVEOPEN);
            while (tok.Type == TokenType.DIRECTIVEOPEN)
            {
                ParseDirective(node);
                tok = scanner.LookAhead(TokenType.DIRECTIVEOPEN);
            }


            tok = scanner.LookAhead(TokenType.SQUAREOPEN, TokenType.IDENTIFIER);
            while (tok.Type == TokenType.SQUAREOPEN ||
                   tok.Type == TokenType.IDENTIFIER)
            {
                ParseExtProduction(node);
                tok = scanner.LookAhead(TokenType.SQUAREOPEN, TokenType.IDENTIFIER);
            }


            tok = scanner.Scan(TokenType.EOF);
            n   = node.CreateNode(tok, tok.ToString());
            node.Token.UpdateRange(tok);
            node.Nodes.Add(n);
            if (tok.Type != TokenType.EOF)
            {
                tree.Errors.Add(new ParseError("Unexpected token '" + tok.Text.Replace("\n", "") + "' found. Expected " + TokenType.EOF.ToString(), 0x1001, tok));
                return;
            }

            parent.Token.UpdateRange(node.Token);
        }