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 09, af). Use a proto token with two :sym<…> variants, dec and hex. Parse '0xff' and print whether it succeeded.

Example

The program prints:

True

Solution

See the solution

Course navigation

Solution: Inherit a grammar   |   Solution: A number with proto