Course of Raku / Regexes and grammars / Grammars / The parse tree, make and made / Exercises

Reverse the words

Problem

A grammar can make a value from the values its parts made. Parse a phrase — words of word characters separated by single spaces, with no other punctuation — and produce the phrase with every word reversed.

Let each word token make its own text reversed (with flip), and let TOP combine those into the final phrase. Parse 'hello world' and print .made.

Example

The program prints:

olleh dlrow

Solution

See the solution

Course navigation

Solution: Multiply a pair   |   Solution: Reverse the words