This page (revision-8) was last changed on 20-Jun-2014 20:54 by Dieter Käppel

This page was created on 26-Apr-2012 14:22 by Dieter Käppel

Only authorized users are allowed to rename pages.

Only authorized users are allowed to delete pages.

Page revision history

Version Date Modified Size Author Changes ... Change note
8 20-Jun-2014 20:54 11 KB Dieter Käppel to previous
7 20-Jun-2014 20:54 11 KB Dieter Käppel to previous | to last
6 20-Jun-2014 20:52 11 KB Dieter Käppel to previous | to last
5 20-Jun-2014 20:48 10 KB Dieter Käppel to previous | to last
4 20-Jun-2014 20:30 9 KB Dieter Käppel to previous | to last
3 01-Nov-2012 00:11 5 KB Dieter Käppel to previous | to last
2 26-Apr-2012 14:43 2 KB Dieter Käppel to previous | to last
1 26-Apr-2012 14:22 2 KB Dieter Käppel to last

Page References

Incoming links Outgoing links

Version management

Difference between version and

At line 127 added 40 lines
Die Implementierung sieht dann so aus:
{{{
public class ChoiceParser extends Parser {
private String[] choices;
public ChoiceParser(Parsers parsers, String name, String... choices) {
super(parsers, name);
this.choices = choices;
}
@Override
public ParseNode parse(Scanner scanner) {
int position = scanner.position;
for (int i = 0; i < choices.length; ++i) {
String parser = choices[i];
ParseNode child = parse(parser, scanner);
if (child != null) {
if (name() == null || name().charAt(0) == '_')
return child;
return new NonTerminal(this, child);
}
scanner.position(position);
}
scanner.error(this, position);
return null;
}
@Override
public String toString() {
String result = name() + " := ";
for (int i = 0; i < choices.length; ++i) {
if (i > 0) result += " | ";
result += "\"" + choices[i] + "\"";
}
return result;
}
}
}}}