Created
March 15, 2016 20:31
-
-
Save anonymous/e0befbf2f05fd84e1c5b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
v6; | |
grammar BUU { | |
token TOP { <abc>+ }; | |
token abc { 'a' <bc>* }; | |
token bc { [ 'b' <c>* ]+ } | |
token c { 'c' }; | |
}; | |
# default result | |
class BuuAbc0 { | |
method TOP($/) { make $/; } | |
method abc($/) { make $/; } | |
method bc($/) { make $/; } | |
method c($/) { make ~$/; } | |
}; | |
class BuuAbc1 { | |
method TOP($/) { make $<abc>>>.ast; } | |
method abc($/) { make $<bc>>>.ast; } | |
method bc($/) { make $<c>>>.ast; } | |
method c($/) { make ~$/; } | |
}; | |
class BuuAbc2 { | |
method TOP($/) { make $<abc>>>.ast; } | |
method abc($/) { make $<bc>>>.ast; } | |
#method bc($/) { make $<c>>>.ast; } | |
method bc($/) { make ~@$<c>; } | |
#method c($/) { make ~3.ast; } # error | |
method c($/) { my $c = 3; make ~$c; } # this do nothing ! | |
}; | |
class BuuAbc3 { | |
method TOP($/) { make ~$<abc>>>.ast; } | |
method abc($/) { make ~$<bc>>>.ast; } | |
#method bc($/) { make ~@$<c>>>.ast; } | |
method bc($/) { make ~$<c>>>.ast; } | |
method c($/) { make 3; } | |
}; | |
class BuuAbc4 { | |
method TOP($/) { make $<abc>>>.ast; } | |
#method abc($/) { make $<bc>>>.ast; } | |
method abc($/) { make ~@$<bc>; } | |
method bc($/) { make ~@$<c>>>.ast; } | |
method c($/) { make 3; } | |
}; | |
class BuuAbc5 { | |
method TOP($/) { make $/; } | |
method abc($/) { make $/; } | |
method bc($/) { make $/; } | |
method c($/) { make 3; } | |
}; | |
class BuuAbc6 { | |
method TOP($/) { make $/<abc>>>.ast; } | |
method abc($/) { make $/; } | |
method bc($/) { make 'cb'; } | |
}; | |
my $r = BUU.parse( "abcabccabbccaababc", :actions( BuuAbc6 ) ); | |
say $r.ast; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment