Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env perl6
- no precompilation;
- use Grammar::Tracer;
- grammar G {
- token TOP { <s> }
- proto token s { * }
- token s:sym<a> { <one> }
- token s:sym<b> { <one> <two> }
- token s:sym<c> { <one> <two> <three> }
- token s:sym<d> { <one> <two> <three> <four> }
- token one { '1' }
- token two { '2' }
- token three { '3' }
- token four { '4' }
- }
- my $g = G.new;
- say $g.parse: '1234';
- # Output: Match
- # token three { '3' }
- TOP
- | s
- | | s:sym<d>
- | | | one
- # Output No Match
- # token three { <digit> }
- TOP
- | s
- | | s:sym<b>
- | | | one
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement