当前位置: 首页>>代码示例>>C#>>正文


C# Scanner.peek方法代码示例

本文整理汇总了C#中Scanner.peek方法的典型用法代码示例。如果您正苦于以下问题:C# Scanner.peek方法的具体用法?C# Scanner.peek怎么用?C# Scanner.peek使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Scanner的用法示例。


在下文中一共展示了Scanner.peek方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: consume

 private void consume(Token desired, Scanner tokens)
 {
     if (tokens.peek() == desired)
         tokens.next();
     else
         wrongToken(desired, tokens.peek());
 }
开发者ID:jayprojects,项目名称:JayPascal,代码行数:7,代码来源:Parser.cs

示例2: getInteger

 private Node getInteger(Scanner tokens)
 {
     if (tokens.peek() is IntegerToken)
         return new Node(tokens.next());
     else
     {
         throw new PascalException("Expected INTEGER, found " + tokens.peek().ToString());
     }
 }
开发者ID:jayprojects,项目名称:JayPascal,代码行数:9,代码来源:Parser.cs

示例3: getID

 private Node getID(Scanner tokens)
 {
     if (tokens.peek() is Identifier)
         return new Node(tokens.next());
     else
     {
         throw new PascalException("Expected IDENTIFIER, found " + tokens.peek().ToString());
     }
 }
开发者ID:jayprojects,项目名称:JayPascal,代码行数:9,代码来源:Parser.cs

示例4: getIDs

 private ArrayList getIDs(Scanner tokens)
 {
     ArrayList identifiers = ArrayList.Synchronized(new ArrayList(10));
     identifiers.Add(getID(tokens));
     while (tokens.peek() == PascalTokens.TCOMMA)
     {
         tokens.next();
         identifiers.Add(getID(tokens));
     }
     return identifiers;
 }
开发者ID:jayprojects,项目名称:JayPascal,代码行数:11,代码来源:Parser.cs

示例5: parseSimpleExpression

        private Node parseSimpleExpression(Scanner tokens)
        {
            Token tok = tokens.peek();
            Node result;

            if ((tok == PascalTokens.TPLUS) || (tok == PascalTokens.TMINUS))
            {

                result = new Node(new IntegerToken(0));
            }
            else
            {
                result = parseTerm(tokens);
            }

            while (isAddOp(tokens.peek()))
            {
                ArrayList children = ArrayList.Synchronized(new ArrayList(10));
                children.Add(result);
                children.Add(parseAddingOperator(tokens));
                children.Add(parseTerm(tokens));

                result = new Node(PascalNonterminals.EXPRESSION, children);
            }
            return result;
        }
开发者ID:jayprojects,项目名称:JayPascal,代码行数:26,代码来源:Parser.cs

示例6: parseSetValue

 private Node parseSetValue(Scanner tokens)
 {
     ArrayList children = ArrayList.Synchronized(new ArrayList(10));
     consume(PascalTokens.TOPENBRACKET, tokens);
     if (tokens.peek() != PascalTokens.TCLOSEBRACKET)
     {
         children.Add(parseElement(tokens));
         while (tokens.peek() == PascalTokens.TCOMMA)
         {
             tokens.next();
             children.Add(parseElement(tokens));
         }
     }
     consume(PascalTokens.TCLOSEBRACKET, tokens);
     return new Node(PascalNonterminals.SET, children);
 }
开发者ID:jayprojects,项目名称:JayPascal,代码行数:16,代码来源:Parser.cs

示例7: parseCompoundStatement

        private Node parseCompoundStatement(Scanner tokens)
        {
            Node tempNode;
            consume(PascalTokens.TBEGIN, tokens);
            ArrayList statements = ArrayList.Synchronized(new ArrayList(10));
            if (tokens.peek() != PascalTokens.TEND)
            {
                statements.Add(parseStatement(tokens));
                while (tokens.peek() == PascalTokens.TSEMICOLON)
                {
                    tokens.next();
                    tempNode = parseStatement(tokens);
                    if(tempNode!=null)
                        statements.Add(tempNode);
                }
            }

            consume(PascalTokens.TEND, tokens);

            return new Node(PascalNonterminals.COMPOUND_STAT, statements);
        }
开发者ID:jayprojects,项目名称:JayPascal,代码行数:21,代码来源:Parser.cs

示例8: parseVariableDeclarations

 private Node parseVariableDeclarations(Scanner tokens)
 {
     ArrayList children = ArrayList.Synchronized(new ArrayList(10));
     if (tokens.peek() != PascalTokens.TVAR)
         return new Node(PascalNonterminals.VARIABLE_DECLARATIONS);
     tokens.next();
     while (tokens.peek() is Identifier)
     {
         children.Add(parseVariableDeclaration(tokens));
         if (tokens.peek() != PascalTokens.TSEMICOLON)
             return wrongToken(PascalTokens.TSEMICOLON, tokens.peek());
         tokens.next();
     }
     return new Node(PascalNonterminals.VARIABLE_DECLARATIONS, children);
 }
开发者ID:jayprojects,项目名称:JayPascal,代码行数:15,代码来源:Parser.cs

示例9: parseVariable

 private Node parseVariable(Scanner tokens)
 {
     Token tok = tokens.peek();
     if (tok is Identifier)
     {
         tokens.next();
         return parseVariable((Identifier) tok, tokens);
     }
     else
     {
         throw new Exception("Attempting to match a variable; found: " + tok.ToString());
     }
 }
开发者ID:jayprojects,项目名称:JayPascal,代码行数:13,代码来源:Parser.cs

示例10: parseElement

 private Node parseElement(Scanner tokens)
 {
     Node exp = parseExpression(tokens);
     if (tokens.peek() == PascalTokens.TDOTDOT)
     {
         tokens.next();
         ArrayList children = ArrayList.Synchronized(new ArrayList(10));
         children.Add(exp);
         children.Add(parseExpression(tokens));
         return new Node(PascalNonterminals.RANGE, children);
     }
     else
         return exp;
 }
开发者ID:jayprojects,项目名称:JayPascal,代码行数:14,代码来源:Parser.cs

示例11: parseStatement

        private Node parseStatement(Scanner tokens)
        {
            Token tok = tokens.peek();
            //let comment handled by preprocessors
            /*
            if (tok == PascalTokens.TCOMMENT)
            {
                do
                {
                    tokens.next();
                    tok = tokens.peek();
                } while (tok == PascalTokens.TCOMMENT);
            }
            */

            if (tok is IntegerToken)
            {
                ArrayList children = ArrayList.Synchronized(new ArrayList(10));
                children.Add(getInteger(tokens));
                consume(PascalTokens.TCOLON, tokens);
                children.Add(parseStatement(tokens));
                return new Node(PascalNonterminals.LABELED_STATEMENT, children);
            }

            else if (tok is Identifier)
            {

                Token CurrentToken = tokens.next();
                Token tmp = tokens.peek();
                if ((tmp == PascalTokens.TOPENPAREN) || (tmp == PascalTokens.TSEMICOLON) || (tmp == PascalTokens.TELSE) || (tmp == PascalTokens.TEND) || (tmp == PascalTokens.TUNTIL))
                {
                    return parseProcedureCall((Identifier) tok, tokens);
                }
                else if (tmp == PascalTokens.TCOLON)
                {
                    ArrayList children = ArrayList.Synchronized(new ArrayList(10));
                    children.Add(new Node(CurrentToken));
                    consume(PascalTokens.TCOLON, tokens);
                    children.Add(parseStatement(tokens));
                    return new Node(PascalNonterminals.LABELED_STATEMENT, children);
                }
                else
                {

                    return parseAssignment((Identifier)tok, tokens);
                }
            }

            else if (tok == PascalTokens.TBEGIN)
            {
                return parseCompoundStatement(tokens);
            }

            else if (tok == PascalTokens.TFOR)
            {
                return parseForStatement(tokens);
            }

            else if (tok == PascalTokens.TGOTO)
            {
                return parseGoto(tokens);
            }

            else if (tok == PascalTokens.TIF)
            {
                return parseIf(tokens);
            }

            else if (tok == PascalTokens.TREPEAT)
            {
                return parseRepeatStatement(tokens);
            }

            else if (tok == PascalTokens.TWHILE)
            {
                return parseWhileLoop(tokens);
            }
            else if (tok == PascalTokens.TWHILE)
            {
                return parseWhileLoop(tokens);
            }
            else if (tok == PascalTokens.TTRUE)
            {
                return new Node(new BooleanToken(true));
            }
            else if (tok == PascalTokens.TFALSE)
            {
                return new Node(new BooleanToken(false));
            }

            else if ((tok == PascalTokens.TSEMICOLON) || (tok == PascalTokens.TEND) || (tok == PascalTokens.TUNTIL))
            {
                return null;
            }

            else
                return wrongToken(PascalNonterminals.STATEMENT, tok);
        }
开发者ID:jayprojects,项目名称:JayPascal,代码行数:98,代码来源:Parser.cs

示例12: parseMultiplyingOperator

 private Node parseMultiplyingOperator(Scanner tokens)
 {
     if (isMulOp(tokens.peek()))
         return new Node(tokens.next());
     else
         return wrongToken(PascalNonterminals.MULTIPLYING_OPERATOR, tokens.peek());
 }
开发者ID:jayprojects,项目名称:JayPascal,代码行数:7,代码来源:Parser.cs

示例13: parseLabelDeclarations

 private Node parseLabelDeclarations(Scanner tokens)
 {
     if (tokens.peek() == PascalTokens.TLABEL)
     {
         tokens.next();
         ArrayList children = ArrayList.Synchronized(new ArrayList(10));
         //children.Add(getInteger(tokens));
         children.Add(getID(tokens));
         while (tokens.peek() == PascalTokens.TCOMMA)
         {
             tokens.next();
             //children.Add(getInteger(tokens));
             children.Add(getID(tokens));
         }
         consume(PascalTokens.TSEMICOLON, tokens);
         return new Node(PascalNonterminals.LABEL_DECLARATIONS, children);
     }
     else
     {
         return null;
     }
 }
开发者ID:jayprojects,项目名称:JayPascal,代码行数:22,代码来源:Parser.cs

示例14: parseIf

 private Node parseIf(Scanner tokens)
 {
     ArrayList children = ArrayList.Synchronized(new ArrayList(10));
     consume(PascalTokens.TIF, tokens);
     children.Add(parseExpression(tokens));
     consume(PascalTokens.TTHEN, tokens);
     children.Add(parseStatement(tokens));
     if (tokens.peek() == PascalTokens.TELSE)
     {
         tokens.next();
         children.Add(parseStatement(tokens));
     }
     return new Node(PascalNonterminals.IF_STAT, children);
 }
开发者ID:jayprojects,项目名称:JayPascal,代码行数:14,代码来源:Parser.cs

示例15: parseConstant

 private Node parseConstant(Scanner tokens)
 {
     Token tok = tokens.peek();
     if (tok is StringToken)
     {
         tokens.next();
         return new Node(tok);
     }
     else
     {
         ArrayList children = ArrayList.Synchronized(new ArrayList(10));
         if ((tok == PascalTokens.TPLUS) || (tok == PascalTokens.TMINUS))
         {
             tokens.next();
             children.Add(new Node(tok));
         }
         else
         {
             children.Add(null);
         }
         children.Add(parseUnsignedNumber(tokens));
         return new Node(PascalNonterminals.CONSTANT, children);
     }
 }
开发者ID:jayprojects,项目名称:JayPascal,代码行数:24,代码来源:Parser.cs


注:本文中的Scanner.peek方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。