This site uses cookies only for the purpose of identifying user sessions.
This is required to properly register actions.
Exercise
‹26›:
Lists of items separated by commas with optional ending comma
The set of tokens of the language is
{ITEM,,,[,]} (mind the second token, which is a
comma), where the token ITEM represents any non-empty sequence of
alphanumeric characters and underscore. We want to parse the language of lists
of items. The list must be delimited by brackets, and the items separated by
commas, with an optional comma at the end of the list. Examples of correct
expressions are “[eggs_many, ham, SPAM]”, “[bread, 2sausages, potato1,]”,
“[bacon]”, “[,]”, “[]” and examples of incorrect
expressions are “[butter,,jam]”, “[,scone]”. The generated
AST must have the token [ as root, with the items as children. For
instance, the input
[honey,tea,]
produces the following AST
[(honey,tea)
Authors: Nil Mamano
/
Documentation: