Java Language Generator

Implement a LanguageGenerator class that generates valid strings according to the production rules defined by the given Grammar. A Grammar consists of a Supplier field with a get() method that returns a Map<String, String[]> representing the production rules. (STARTER CODE ATTACHED IN DOC)


1) LanguageGenerator(Grammar grammar)


Constructs a new LanguageGenerator for the given grammar.


2) LanguageGenerator(Grammar grammar, Random random)


Constructs a new LanguageGenerator for the given grammar and source of randomness.


3) String generate(String target)


Returns a string generated by following the production rule for the given target. The resulting string should be compact: there should be exactly one space between each terminal and no leading or trailing spaces. Choose between potential production rules for the given target by calling random.nextInt so that each possibility is equally likely to be chosen.


Call the trim method to remove leading and trailing whitespace. Consider introducing a public/private pair to trim leading or trailing spaces from the final result.


Split each string on one or more whitespace characters by calling split("\\s+").

Need a custom answer at your budget?

This assignment has been answered 6 times in private sessions.

© 2024 Codify Tutor. All rights reserved