Course of Raku / Regexes and grammars / Grammars / Grammars, classes, and inheritance / Exercises
A number with proto
Problem
Write a grammar that parses a number, which may be
either a decimal integer (one or more digits) or a hexadecimal literal
(0x followed by hex digits 0–9,
a–f). Use a proto token with
two :sym<…> variants, dec and
hex. Parse '0xff' and print whether it
succeeded.
Example
The program prints:
TrueSolution
Course navigation
← Solution: Inherit a grammar | Solution: A number with proto →