本文整理汇总了C#中Scanner.next方法的典型用法代码示例。如果您正苦于以下问题:C# Scanner.next方法的具体用法?C# Scanner.next怎么用?C# Scanner.next使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Scanner
的用法示例。
在下文中一共展示了Scanner.next方法的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: loadCandidateList
public ArrayList<Candidate> loadCandidateList(BufferedReader dataFile) {
ArrayList<Candidate> toReturn = new ArrayList<Candidate>();
try {
string line = dataFile.readLine();
Scanner scanLine;
ArrayList<double?> featureVectorToAdd;
while (line != null && !(line.equals(""))) {
scanLine = new Scanner(line);
featureVectorToAdd = new ArrayList<double?>();
int intClass = -1
featureVectorToAdd.add/* [13,27] expecting: identifier: (*/scanLine/* [13,72] expecting: ';', ',': .*//* [13,107] expecting: ';', ',': nextDouble*/()/* [13,154] expecting: '{', ';': )*/;
featureVectorToAdd.add/* [14,27] expecting: identifier: (*/scanLine/* [14,72] expecting: ';', ',': .*//* [14,107] expecting: ';', ',': nextDouble*/()/* [14,154] expecting: '{', ';': )*/;
featureVectorToAdd.add/* [15,27] expecting: identifier: (*/scanLine/* [15,72] expecting: ';', ',': .*//* [15,107] expecting: ';', ',': nextDouble*/()/* [15,154] expecting: '{', ';': )*/;
featureVectorToAdd.add/* [16,27] expecting: identifier: (*/scanLine/* [16,72] expecting: ';', ',': .*//* [16,107] expecting: ';', ',': nextDouble*/()/* [16,154] expecting: '{', ';': )*/;
String typeOfPlant = scanLine.next();
/* [19,5] expecting: 'abstract', 'boolean', 'byte', 'char', 'class', 'double', 'enum', 'final', 'float', 'int', 'interface', 'long', 'native', 'private', 'protected', 'public', 'short', 'static', 'strictfp', 'synchronized', 'transient', 'void', 'volatile', identifier, '{', '}', ';', '<', '@': if*/ /* [19,304] expecting: 'abstract', 'boolean', 'byte', 'char', 'class', 'double', 'enum', 'final', 'float', 'int', 'interface', 'long', 'native', 'private', 'protected', 'public', 'short', 'static', 'strictfp', 'synchronized', 'transient', 'void', 'volatile', identifier, '{', '}', ';', '<', '@': (*/typeOfPlant.equals/* [19,621] expecting: identifier: (*//* [19,659] expecting: identifier: "Iris-setosa"*/)) {
intClass = 1;
} else if (typeOfPlant.equals("Iris-versicolor")) {
intClass = 2;
} else if (typeOfPlant.equals("Iris-virginica")) {
intClass = 3;
}
Candidate c = new Candidate(featureVectorToAdd, intClass);
toReturn.add/* [15,17] expecting: identifier: (*/c/* [15,55] expecting: ';', ',': )*/;
line /* [16,10] expecting: identifier: =*/ dataFile/* [16,56] expecting: ';', ',': .*//* [16,91] expecting: ';', ',': readLine*/();
scanLine.close/* [17,19] expecting: identifier: (*//* [17,56] expecting: identifier: )*//* [17,93] expecting: identifier: ;*/
/* [19,4] expecting: identifier: }*/
/* [20,4] expecting: identifier: return*/ toReturn;
} /* [22,5] expecting: EOF: catch*/ /* [22,39] expecting: EOF: (*//* [22,69] expecting: EOF: IOException*/ /* [22,110] expecting: EOF: e*//* [22,141] expecting: EOF: )*/ /* [22,173] expecting: EOF: {*/
// TODO Auto-generated catch block
/* [24,4] expecting: EOF: e*//* [24,33] expecting: EOF: .*//* [24,63] expecting: EOF: printStackTrace*//* [24,107] expecting: EOF: (*/);
}
return null;
}
示例6: parseSimpleType
private Node parseSimpleType(Scanner tokens)
{
Token tok = tokens.peek();
if (tok == PascalTokens.TOPENPAREN)
{
tokens.next();
ArrayList contents = getIDs(tokens);
consume(PascalTokens.TCLOSEPAREN, tokens);
return new Node(PascalNonterminals.SCALAR_TYPE, contents);
}
else if (tok is Identifier)
{
Node id = getID(tokens);
if (tokens.peek() == PascalTokens.TDOTDOT)
{
tokens.next();
ArrayList children = ArrayList.Synchronized(new ArrayList(10));
ArrayList grandchildren = ArrayList.Synchronized(new ArrayList(10));
grandchildren.Add(null);
grandchildren.Add(id);
children.Add(new Node(PascalNonterminals.CONSTANT, grandchildren));
children.Add(parseConstant(tokens));
return new Node(PascalNonterminals.SUBRANGE_TYPE, children);
}
else
return new Node(PascalNonterminals.TYPE_IDENTIFIER, id);
}
else
{
ArrayList children = ArrayList.Synchronized(new ArrayList(10));
children.Add(parseConstant(tokens));
consume(PascalTokens.TDOTDOT, tokens);
children.Add(parseConstant(tokens));
return new Node(PascalNonterminals.SUBRANGE_TYPE, children);
}
}
示例7: 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);
}
示例8: 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);
}
示例9: 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);
}
}
示例10: parseVariable
private Node parseVariable(Identifier id, Scanner tokens)
{
Node base_Renamed = new Node(PascalNonterminals.VARIABLE_NAME, new Node(id));
bool done = false;
while (!done)
{
Token tok = tokens.peek();
if (tok == PascalTokens.TDOT)
{
//CHECKING IF THIS BLOCK GET EVER ACCESSED
//OTHER WISE REMOVE FIELD_SELECT FROM PASCALNONTERMINALS
tokens.next();
ArrayList children = ArrayList.Synchronized(new ArrayList(10));
children.Add(base_Renamed);
children.Add(getID(tokens));
base_Renamed = new Node(PascalNonterminals.FIELD_SELECT, children);
}
else if (tok == PascalTokens.TOPENBRACKET)
{
tokens.next();
ArrayList children = ArrayList.Synchronized(new ArrayList(10));
children.Add(base_Renamed);
children.Add(parseExpression(tokens));
while (tokens.peek() == PascalTokens.TCOMMA)
{
tokens.next();
children.Add(parseExpression(tokens));
}
consume(PascalTokens.TCLOSEBRACKET, tokens);
base_Renamed = new Node(PascalNonterminals.ARRAY_SELECT, children);
}
else
{
done = true;
}
}
return base_Renamed;
}
示例11: parseExpression
private Node parseExpression(Scanner tokens)
{
if (tokens.peek() is StringToken)
return new Node(tokens.next());
Node primary = parseSimpleExpression(tokens);
if (isRelOp(tokens.peek()))
{
ArrayList children = ArrayList.Synchronized(new ArrayList(10));
children.Add(primary);
children.Add(parseRelationalOperator(tokens));
children.Add(parseSimpleExpression(tokens));
return new Node(PascalNonterminals.EXPRESSION, children);
}
else
{
return primary;
}
}
示例12: parseProcedureCall
private Node parseProcedureCall(Identifier id, Scanner tokens)
{
ArrayList children = ArrayList.Synchronized(new ArrayList(10));
children.Add(new Node(id));
if (tokens.peek() == PascalTokens.TOPENPAREN)
{
tokens.next();
children.Add(parseExpression(tokens));
while (tokens.peek() == PascalTokens.TCOMMA)
{
tokens.next();
children.Add(parseExpression(tokens));
}
consume(PascalTokens.TCLOSEPAREN, tokens);
}
return new Node(PascalNonterminals.PROCEDURE_CALL, children);
}
示例13: parseUnsignedNumber
private Node parseUnsignedNumber(Scanner tokens)
{
Token tok = tokens.next();
if ((tok is IntegerToken) || (tok is RealToken) || (tok is Identifier))
return new Node(tok);
else
{
throw new PascalException("Expected: unsigned number; Found: " + tok.ToString());
}
}
示例14: 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;
}
}
示例15: parseMultiplyingOperator
private Node parseMultiplyingOperator(Scanner tokens)
{
if (isMulOp(tokens.peek()))
return new Node(tokens.next());
else
return wrongToken(PascalNonterminals.MULTIPLYING_OPERATOR, tokens.peek());
}