 |
Synthia
Generic and flexible data structure generator
|
Go to the documentation of this file.
19 package ca.uqac.lif.synthia.grammar;
25 import java.util.List;
44 protected static final transient String
SPACE =
" ";
90 List<TokenString> alternatives = rule.getAlternatives();
92 TokenString chosen_string = alternatives.get(chosen_index);
93 StringBuilder out =
new StringBuilder();
94 for (Token t : chosen_string)
96 if (t instanceof StringTerminalToken)
98 out.append(t.getName()).append(
SPACE);
100 else if (t instanceof NumberTerminalToken)
102 out.append(t.getName()).append(
SPACE);
104 else if (t instanceof RegexTerminalToken)
106 out.append(t.getName());
108 else if (t instanceof EpsilonTerminalToken)
112 else if (t instanceof TerminalToken)
114 out.append(t.getName()).append(
SPACE);
116 if (t instanceof NonTerminalToken)
118 BnfRule child_rule =
m_parser.getRule(t.getName());
119 if (child_rule !=
null)
125 return out.toString();
GrammarSentence(BnfParser parser, RandomInteger picker)
Creates a new instance of the picker.
Pickers that produce pseudo-random objects such as numbers.
RandomInteger m_indexPicker
A picker used to choose the cases from the grammar rules to expand.
RandomInteger setInterval(int min, int max)
Sets the interval in which integers are picked.
BnfParser m_parser
The parser whose grammar will be used to generate expressions.
void reset()
Puts the picker back into its initial state.
Picks an integer uniformly in an interval.
Integer pick()
Picks a random integer.
RandomInteger duplicate(boolean with_state)
Creates a copy of the RandomInteger picker.
GrammarSentence duplicate(boolean with_state)
Creates a copy of the picker.
void reset()
Puts the picker back into its initial state.
String pick()
Picks an object.
Picker that generates sentences from a format grammar.
String pickRecursive(BnfRule rule)
Recursively expands a non-terminal symbol from the grammar.
static final transient String SPACE
The character used to separate the tokens.