This file contains 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
#!/usr/bin/perl | |
use 5.010; | |
use strict; | |
use warnings; | |
use Marpa::R2 2.100; | |
use Data::Dumper; | |
# array: 'A' count ':' element+ | |
# string: 'S' length ':' byte+ |
This file contains 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
# input: "a+"a"a"+a"a"+a | |
Ambiguous parse: 3 alternatives: | |
# ast 0: | |
['x',['x','"',['x',['x',['x',['a']],'+','"',['x',['a']],'"'],['x',['a']]],'"','+',['x',['a']]],['x','"',['x',['a']],'"','+',['x',['a']]]] | |
# ast 1: | |
['x','"',['x',['x',['x',['a']],'+','"',['x',['x',['a']],['x','"',['x',['a']],'"','+',['x',['a']]]],'"'],['x',['a']]],'"','+',['x',['a']]] | |
# ast 2: | |
['x','"',['x',['x',['x',['a']],'+','"',['x',['a']],'"'],['x',['a']]],'"','+',['x',['x',['a']],['x','"',['x',['a']],'"','+',['x',['a']]]]] | |
# input: a"a"+a | |
# ast 0: |
This file contains 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
# input: "a+"a""+a | |
# ast 0: | |
['x','"',['x',['x',['a']],'+','"',['x',['a']],'"'],'"','+',['x',['a']]] | |
# + left-associative: a+a+a | |
Ambiguous parse: 2 alternatives: at C:\cygwin\home\Ruslan\Marpa-R2-work\q27655176.t line 69. | |
# ast 0: | |
['x',['x',['x',['a']],'+',['x',['a']]],'+',['x',['a']]] | |
# ast 1: | |
['x',['x',['a']],'+',['x',['x',['a']],'+',['x',['a']]]] | |
# + lazily eating operands: aa+aa |
This file contains 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
# input: "a+"a""+a | |
# ast dump: | |
[ | |
'x', | |
'"', | |
[ | |
'x', | |
[ | |
'x', | |
[ |
This file contains 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
# + left-associative: a+a+a | |
[ | |
'x', | |
[ | |
'x', | |
[ | |
'x', | |
[ | |
'a', | |
'a' |
This file contains 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
$VAR1 = \[ | |
'S', | |
[ | |
'Id', | |
[ | |
'Identifier', | |
'ABC' | |
] | |
] | |
]; |
This file contains 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
use 5.010; | |
use strict; | |
# | |
# this lexer supports adding lexemes as regexes (not only literals) | |
# and finding tokens by matched alternative number | |
# | |
my $string = <<END; | |
# comment |
This file contains 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
use 5.010; | |
use strict; | |
use warnings; | |
use Marpa::R2; | |
my $g = Marpa::R2::Scanless::G->new( { source => \(<<'END_OF_SOURCE'), | |
:default ::= action => [ value ] | |
lexeme default = action => [ name, value ] latm => 1 |
This file contains 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
# Output of $r->ambiguous(): at C:\cygwin\home\Ruslan\Marpa-R2-work\q26173372-asf.pl line 84. | |
Length of symbol "table" at line 3, column 1 is ambiguous | |
Choices start with: +Team:US | |
Choice 1, length=415, ends at C:\cygwin\home\Ruslan\Marpa-R2-work\q26173372-asf.pl line 85. | |
# Output of $r->value(), max_parses is in effect, so works ok: at C:\cygwin\home\Ruslan\Marpa-R2-work\q26173372-asf.pl line 89. | |
['data',['heading',['string','Soccer']],['tables',['table',['row',['level','+'],['name',['string','Team']],':',['value',['string','US']]],['row',['level','++'],['name',['string','Shirt']],':',['value',['string','Red & White Stripes']]],['row',['level','++'],['name',['string','Shorts']],':',['value',['string','Blue']]],['row',['level','++'],['name',['string','Players']],':',['value',['string','17']]],['row',['level','+++'],['name',['string','Active']],':',['value',['string','11']]],['row',['level','++++'],['name',['string','Forward']],':',['value',['string','2']]],['row',['level','++++'],['name',['string','Midf |
This file contains 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
use 5.010; | |
use strict; | |
# | |
# this lexer supports adding lexemes as regexes (not only literals) | |
# and finding tokens by matched alternative number | |
# | |
my $string = <<END; | |
# comment |