本文整理汇总了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());
}
示例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());
}
}
示例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());
}
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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());
}
}
示例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;
}
示例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);
}
示例12: parseMultiplyingOperator
private Node parseMultiplyingOperator(Scanner tokens)
{
if (isMulOp(tokens.peek()))
return new Node(tokens.next());
else
return wrongToken(PascalNonterminals.MULTIPLYING_OPERATOR, tokens.peek());
}
示例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;
}
}
示例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);
}
示例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);
}
}