Discussion:
Rule ordering question
Michael Spertus
2018-08-08 05:20:38 UTC
Permalink
Thanks for helping me to get to a (surprising) answer to my previous
question. I was hoping you could help me with another. I want the following
grammar to parse 'xy' as a single statement

statements ::= statement+
statement ::= xy | x | y
x ::= 'x'
y ::= 'y'
xy ::= 'x' 'y'
Unfortunately, it always parses as two statements, even if I use the
attached "high_rule_only" code and rank the statement alternatives as

statement ::= xy rank => 1 | x | y


I still get two statements. Is there a way I can do this with ordering, or
do I need to do something like traverse the ASF? Note that I need to do
this at the ::= level rather than with lexemes because in the actual
grammar I care about x and y are complicated rules themselves.

Thanks,
Mike
--
You received this message because you are subscribed to the Google Groups "marpa parser" group.
To unsubscribe from this group and stop receiving emails from it, send an email to marpa-parser+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Michael Spertus
2018-08-08 05:33:23 UTC
Permalink
This time with attachment :/
Post by Michael Spertus
Thanks for helping me to get to a (surprising) answer to my previous
question. I was hoping you could help me with another. I want the following
grammar to parse 'xy' as a single statement
statements ::= statement+
statement ::= xy | x | y
x ::= 'x'
y ::= 'y'
xy ::= 'x' 'y'
Unfortunately, it always parses as two statements, even if I use the
attached "high_rule_only" code and rank the statement alternatives as
statement ::= xy rank => 1 | x | y
I still get two statements. Is there a way I can do this with ordering, or
do I need to do something like traverse the ASF? Note that I need to do
this at the ::= level rather than with lexemes because in the actual
grammar I care about x and y are complicated rules themselves.
Thanks,
Mike
--
You received this message because you are subscribed to the Google Groups "marpa parser" group.
To unsubscribe from this group and stop receiving emails from it, send an email to marpa-parser+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Lukas Atkinson
2018-08-08 07:01:11 UTC
Permalink
Your grammar as written is ambiguous and therefore Marpa gives you all
parses in an unspecified order – to see them, iterate over the value
like

while (my $ref = $recce->value) {
print Dumper $$ref;
}

Marpa's ranks are a bit unintuitive, I previously ran into very
similar problems. This lead to the Marpa::R2::Semantics::Rank
document[1] being written (Thanks Jeffrey!). That document shows a
related example. The solution seems to be to spell out the sequence
rule explicitly:

statements ::= xy rank => 1
statements ::= x
statements ::= y
statements ::= statements xy rank => 1
statements ::= statements x
statements ::= statements y

The docs emphasize: “The rank of a parse choice is the rank of the
rule of its cause”, which suggests the problem is the intermediate
statement rule. If I understand correctly, the "statements ::=
statement+" sequence rule has no choices because it always gets a
statement at each position (not a choice between x and xy). And the
rank within statement does not matter because … I still don't
understand this 100%.

[1]: https://metacpan.org/pod/release/JKEGL/Marpa-R2-5.043_043/pod/Semantics/Rank.pod
Post by Michael Spertus
This time with attachment :/
Thanks for helping me to get to a (surprising) answer to my previous question. I was hoping you could help me with another. I want the following grammar to parse 'xy' as a single statement
Post by Michael Spertus
statements ::= statement+
statement ::= xy | x | y
x ::= 'x'
y ::= 'y'
xy ::= 'x' 'y'
Unfortunately, it always parses as two statements, even if I use the attached "high_rule_only" code and rank the statement alternatives as
Post by Michael Spertus
statement ::= xy rank => 1 | x | y
I still get two statements. Is there a way I can do this with ordering, or do I need to do something like traverse the ASF? Note that I need to do this at the ::= level rather than with lexemes because in the actual grammar I care about x and y are complicated rules themselves.
Thanks,
Mike
--
You received this message because you are subscribed to the Google Groups "marpa parser" group.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "marpa parser" group.
To unsubscribe from this group and stop receiving emails from it, send an email to marpa-parser+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Michael Spertus
2018-08-08 18:31:31 UTC
Permalink
Thanks for the link, Amon. As I suspected, it says you should travers the
ASF in such cases...

In a related question, is there any way for me to reject a rule during the
read() by listening for a prediction/completion events? A number of my
rules have conditions on their arguments that are known not to be
BNF-friendly. I know I can bail from those in a semantic action, but I
would like to reject before an exponential explosion in the number of
ambiguous parses. Does that make sense?

Thanks,

Mike
Post by Lukas Atkinson
Your grammar as written is ambiguous and therefore Marpa gives you all
parses in an unspecified order – to see them, iterate over the value
like
while (my $ref = $recce->value) {
print Dumper $$ref;
}
Marpa's ranks are a bit unintuitive, I previously ran into very
similar problems. This lead to the Marpa::R2::Semantics::Rank
document[1] being written (Thanks Jeffrey!). That document shows a
related example. The solution seems to be to spell out the sequence
statements ::= xy rank => 1
statements ::= x
statements ::= y
statements ::= statements xy rank => 1
statements ::= statements x
statements ::= statements y
The docs emphasize: “The rank of a parse choice is the rank of the
rule of its cause”, which suggests the problem is the intermediate
statement rule. If I understand correctly, the "statements ::=
statement+" sequence rule has no choices because it always gets a
statement at each position (not a choice between x and xy). And the
rank within statement does not matter because 
 I still don't
understand this 100%.
https://metacpan.org/pod/release/JKEGL/Marpa-R2-5.043_043/pod/Semantics/Rank.pod
Post by Michael Spertus
This time with attachment :/
On Wednesday, August 8, 2018 at 12:20:39 AM UTC-5, Michael Spertus
Post by Michael Spertus
Thanks for helping me to get to a (surprising) answer to my previous
question. I was hoping you could help me with another. I want the following
grammar to parse 'xy' as a single statement
Post by Michael Spertus
Post by Michael Spertus
Post by Michael Spertus
statements ::= statement+
statement ::= xy | x | y
x ::= 'x'
y ::= 'y'
xy ::= 'x' 'y'
Unfortunately, it always parses as two statements, even if I use the
attached "high_rule_only" code and rank the statement alternatives as
Post by Michael Spertus
Post by Michael Spertus
Post by Michael Spertus
statement ::= xy rank => 1 | x | y
I still get two statements. Is there a way I can do this with ordering,
or do I need to do something like traverse the ASF? Note that I need to do
this at the ::= level rather than with lexemes because in the actual
grammar I care about x and y are complicated rules themselves.
Post by Michael Spertus
Post by Michael Spertus
Thanks,
Mike
--
You received this message because you are subscribed to the Google
Groups "marpa parser" group.
Post by Michael Spertus
To unsubscribe from this group and stop receiving emails from it, send
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "marpa parser" group.
To unsubscribe from this group and stop receiving emails from it, send an email to marpa-parser+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Jeffrey Kegler
2018-08-08 18:40:45 UTC
Permalink
It make *lots* of sense and I've considered it as a feature in R3. It will
never happen in R2 -- it'd be a massive risky change and R2 is stable.

Incidentally, a limited implementation of it is how LATM lexing works. As
a special case, I selectively turn on and off predictions in Earley set 0
of the lexer.
Post by Michael Spertus
Thanks for the link, Amon. As I suspected, it says you should travers the
ASF in such cases...
In a related question, is there any way for me to reject a rule during the
read() by listening for a prediction/completion events? A number of my
rules have conditions on their arguments that are known not to be
BNF-friendly. I know I can bail from those in a semantic action, but I
would like to reject before an exponential explosion in the number of
ambiguous parses. Does that make sense?
Thanks,
Mike
Post by Lukas Atkinson
Your grammar as written is ambiguous and therefore Marpa gives you all
parses in an unspecified order – to see them, iterate over the value
like
while (my $ref = $recce->value) {
print Dumper $$ref;
}
Marpa's ranks are a bit unintuitive, I previously ran into very
similar problems. This lead to the Marpa::R2::Semantics::Rank
document[1] being written (Thanks Jeffrey!). That document shows a
related example. The solution seems to be to spell out the sequence
statements ::= xy rank => 1
statements ::= x
statements ::= y
statements ::= statements xy rank => 1
statements ::= statements x
statements ::= statements y
The docs emphasize: “The rank of a parse choice is the rank of the
rule of its cause”, which suggests the problem is the intermediate
statement rule. If I understand correctly, the "statements ::=
statement+" sequence rule has no choices because it always gets a
statement at each position (not a choice between x and xy). And the
rank within statement does not matter because 
 I still don't
understand this 100%.
[1]: https://metacpan.org/pod/release/JKEGL/Marpa-R2-5.043_043/
pod/Semantics/Rank.pod
Post by Michael Spertus
This time with attachment :/
On Wednesday, August 8, 2018 at 12:20:39 AM UTC-5, Michael Spertus
Post by Michael Spertus
Thanks for helping me to get to a (surprising) answer to my previous
question. I was hoping you could help me with another. I want the following
grammar to parse 'xy' as a single statement
Post by Michael Spertus
Post by Michael Spertus
Post by Michael Spertus
statements ::= statement+
statement ::= xy | x | y
x ::= 'x'
y ::= 'y'
xy ::= 'x' 'y'
Unfortunately, it always parses as two statements, even if I use the
attached "high_rule_only" code and rank the statement alternatives as
Post by Michael Spertus
Post by Michael Spertus
Post by Michael Spertus
statement ::= xy rank => 1 | x | y
I still get two statements. Is there a way I can do this with
ordering, or do I need to do something like traverse the ASF? Note that I
need to do this at the ::= level rather than with lexemes because in the
actual grammar I care about x and y are complicated rules themselves.
Post by Michael Spertus
Post by Michael Spertus
Thanks,
Mike
--
You received this message because you are subscribed to the Google
Groups "marpa parser" group.
Post by Michael Spertus
To unsubscribe from this group and stop receiving emails from it, send
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"marpa parser" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "marpa parser" group.
To unsubscribe from this group and stop receiving emails from it, send an email to marpa-parser+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Michael Spertus
2018-08-08 21:50:16 UTC
Permalink
Thanks for the response Jeffrey. That would be awesome. Consider this a
vote for early bailing (Earley bailing?) in R3.

Mike
Post by Jeffrey Kegler
It make *lots* of sense and I've considered it as a feature in R3. It
will never happen in R2 -- it'd be a massive risky change and R2 is stable.
Incidentally, a limited implementation of it is how LATM lexing works. As
a special case, I selectively turn on and off predictions in Earley set 0
of the lexer.
Post by Michael Spertus
Thanks for the link, Amon. As I suspected, it says you should travers the
ASF in such cases...
In a related question, is there any way for me to reject a rule during
the read() by listening for a prediction/completion events? A number of my
rules have conditions on their arguments that are known not to be
BNF-friendly. I know I can bail from those in a semantic action, but I
would like to reject before an exponential explosion in the number of
ambiguous parses. Does that make sense?
Thanks,
Mike
Post by Lukas Atkinson
Your grammar as written is ambiguous and therefore Marpa gives you all
parses in an unspecified order – to see them, iterate over the value
like
while (my $ref = $recce->value) {
print Dumper $$ref;
}
Marpa's ranks are a bit unintuitive, I previously ran into very
similar problems. This lead to the Marpa::R2::Semantics::Rank
document[1] being written (Thanks Jeffrey!). That document shows a
related example. The solution seems to be to spell out the sequence
statements ::= xy rank => 1
statements ::= x
statements ::= y
statements ::= statements xy rank => 1
statements ::= statements x
statements ::= statements y
The docs emphasize: “The rank of a parse choice is the rank of the
rule of its cause”, which suggests the problem is the intermediate
statement rule. If I understand correctly, the "statements ::=
statement+" sequence rule has no choices because it always gets a
statement at each position (not a choice between x and xy). And the
rank within statement does not matter because 
 I still don't
understand this 100%.
https://metacpan.org/pod/release/JKEGL/Marpa-R2-5.043_043/pod/Semantics/Rank.pod
Post by Michael Spertus
This time with attachment :/
On Wednesday, August 8, 2018 at 12:20:39 AM UTC-5, Michael Spertus
Post by Michael Spertus
Thanks for helping me to get to a (surprising) answer to my previous
question. I was hoping you could help me with another. I want the following
grammar to parse 'xy' as a single statement
Post by Michael Spertus
Post by Michael Spertus
Post by Michael Spertus
statements ::= statement+
statement ::= xy | x | y
x ::= 'x'
y ::= 'y'
xy ::= 'x' 'y'
Unfortunately, it always parses as two statements, even if I use the
attached "high_rule_only" code and rank the statement alternatives as
Post by Michael Spertus
Post by Michael Spertus
Post by Michael Spertus
statement ::= xy rank => 1 | x | y
I still get two statements. Is there a way I can do this with
ordering, or do I need to do something like traverse the ASF? Note that I
need to do this at the ::= level rather than with lexemes because in the
actual grammar I care about x and y are complicated rules themselves.
Post by Michael Spertus
Post by Michael Spertus
Thanks,
Mike
--
You received this message because you are subscribed to the Google
Groups "marpa parser" group.
Post by Michael Spertus
To unsubscribe from this group and stop receiving emails from it, send
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"marpa parser" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "marpa parser" group.
To unsubscribe from this group and stop receiving emails from it, send an email to marpa-parser+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Michael Spertus
2018-08-08 22:21:12 UTC
Permalink
Forgot to ask: Is there a way for me to access a rule's rank from within
its semantic action? That way I could simulate the tree ordering from
indirect ranks during ASF pruning

Thanks,
Mike
Post by Michael Spertus
Thanks for the response Jeffrey. That would be awesome. Consider this a
vote for early bailing (Earley bailing?) in R3.
Mike
Post by Jeffrey Kegler
It make *lots* of sense and I've considered it as a feature in R3. It
will never happen in R2 -- it'd be a massive risky change and R2 is stable.
Incidentally, a limited implementation of it is how LATM lexing works.
As a special case, I selectively turn on and off predictions in Earley set
0 of the lexer.
Post by Michael Spertus
Thanks for the link, Amon. As I suspected, it says you should travers
the ASF in such cases...
In a related question, is there any way for me to reject a rule during
the read() by listening for a prediction/completion events? A number of my
rules have conditions on their arguments that are known not to be
BNF-friendly. I know I can bail from those in a semantic action, but I
would like to reject before an exponential explosion in the number of
ambiguous parses. Does that make sense?
Thanks,
Mike
Post by Lukas Atkinson
Your grammar as written is ambiguous and therefore Marpa gives you all
parses in an unspecified order – to see them, iterate over the value
like
while (my $ref = $recce->value) {
print Dumper $$ref;
}
Marpa's ranks are a bit unintuitive, I previously ran into very
similar problems. This lead to the Marpa::R2::Semantics::Rank
document[1] being written (Thanks Jeffrey!). That document shows a
related example. The solution seems to be to spell out the sequence
statements ::= xy rank => 1
statements ::= x
statements ::= y
statements ::= statements xy rank => 1
statements ::= statements x
statements ::= statements y
The docs emphasize: “The rank of a parse choice is the rank of the
rule of its cause”, which suggests the problem is the intermediate
statement rule. If I understand correctly, the "statements ::=
statement+" sequence rule has no choices because it always gets a
statement at each position (not a choice between x and xy). And the
rank within statement does not matter because 
 I still don't
understand this 100%.
https://metacpan.org/pod/release/JKEGL/Marpa-R2-5.043_043/pod/Semantics/Rank.pod
Post by Michael Spertus
This time with attachment :/
On Wednesday, August 8, 2018 at 12:20:39 AM UTC-5, Michael Spertus
Post by Michael Spertus
Thanks for helping me to get to a (surprising) answer to my previous
question. I was hoping you could help me with another. I want the following
grammar to parse 'xy' as a single statement
Post by Michael Spertus
Post by Michael Spertus
Post by Michael Spertus
statements ::= statement+
statement ::= xy | x | y
x ::= 'x'
y ::= 'y'
xy ::= 'x' 'y'
Unfortunately, it always parses as two statements, even if I use the
attached "high_rule_only" code and rank the statement alternatives as
Post by Michael Spertus
Post by Michael Spertus
Post by Michael Spertus
statement ::= xy rank => 1 | x | y
I still get two statements. Is there a way I can do this with
ordering, or do I need to do something like traverse the ASF? Note that I
need to do this at the ::= level rather than with lexemes because in the
actual grammar I care about x and y are complicated rules themselves.
Post by Michael Spertus
Post by Michael Spertus
Thanks,
Mike
--
You received this message because you are subscribed to the Google
Groups "marpa parser" group.
Post by Michael Spertus
To unsubscribe from this group and stop receiving emails from it,
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google
Groups "marpa parser" group.
To unsubscribe from this group and stop receiving emails from it, send
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "marpa parser" group.
To unsubscribe from this group and stop receiving emails from it, send an email to marpa-parser+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Jeffrey Kegler
2018-08-08 22:44:29 UTC
Permalink
IIRC, no. You could always create an array of ranks indexed by rule
number, though the need to duplicate the information is, I admit, annoying.
Post by Michael Spertus
Forgot to ask: Is there a way for me to access a rule's rank from within
its semantic action? That way I could simulate the tree ordering from
indirect ranks during ASF pruning
Thanks,
Mike
Post by Michael Spertus
Thanks for the response Jeffrey. That would be awesome. Consider this a
vote for early bailing (Earley bailing?) in R3.
Mike
Post by Jeffrey Kegler
It make *lots* of sense and I've considered it as a feature in R3. It
will never happen in R2 -- it'd be a massive risky change and R2 is stable.
Incidentally, a limited implementation of it is how LATM lexing works.
As a special case, I selectively turn on and off predictions in Earley set
0 of the lexer.
Post by Michael Spertus
Thanks for the link, Amon. As I suspected, it says you should travers
the ASF in such cases...
In a related question, is there any way for me to reject a rule during
the read() by listening for a prediction/completion events? A number of my
rules have conditions on their arguments that are known not to be
BNF-friendly. I know I can bail from those in a semantic action, but I
would like to reject before an exponential explosion in the number of
ambiguous parses. Does that make sense?
Thanks,
Mike
Post by Lukas Atkinson
Your grammar as written is ambiguous and therefore Marpa gives you all
parses in an unspecified order – to see them, iterate over the value
like
while (my $ref = $recce->value) {
print Dumper $$ref;
}
Marpa's ranks are a bit unintuitive, I previously ran into very
similar problems. This lead to the Marpa::R2::Semantics::Rank
document[1] being written (Thanks Jeffrey!). That document shows a
related example. The solution seems to be to spell out the sequence
statements ::= xy rank => 1
statements ::= x
statements ::= y
statements ::= statements xy rank => 1
statements ::= statements x
statements ::= statements y
The docs emphasize: “The rank of a parse choice is the rank of the
rule of its cause”, which suggests the problem is the intermediate
statement rule. If I understand correctly, the "statements ::=
statement+" sequence rule has no choices because it always gets a
statement at each position (not a choice between x and xy). And the
rank within statement does not matter because 
 I still don't
understand this 100%.
[1]: https://metacpan.org/pod/release/JKEGL/Marpa-R2-5.043_043/
pod/Semantics/Rank.pod
Post by Michael Spertus
This time with attachment :/
On Wednesday, August 8, 2018 at 12:20:39 AM UTC-5, Michael Spertus
Post by Michael Spertus
Thanks for helping me to get to a (surprising) answer to my
previous question. I was hoping you could help me with another. I want the
following grammar to parse 'xy' as a single statement
Post by Michael Spertus
Post by Michael Spertus
Post by Michael Spertus
statements ::= statement+
statement ::= xy | x | y
x ::= 'x'
y ::= 'y'
xy ::= 'x' 'y'
Unfortunately, it always parses as two statements, even if I use
the attached "high_rule_only" code and rank the statement alternatives as
Post by Michael Spertus
Post by Michael Spertus
Post by Michael Spertus
statement ::= xy rank => 1 | x | y
I still get two statements. Is there a way I can do this with
ordering, or do I need to do something like traverse the ASF? Note that I
need to do this at the ::= level rather than with lexemes because in the
actual grammar I care about x and y are complicated rules themselves.
Post by Michael Spertus
Post by Michael Spertus
Thanks,
Mike
--
You received this message because you are subscribed to the Google
Groups "marpa parser" group.
Post by Michael Spertus
To unsubscribe from this group and stop receiving emails from it,
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google
Groups "marpa parser" group.
To unsubscribe from this group and stop receiving emails from it, send
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"marpa parser" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "marpa parser" group.
To unsubscribe from this group and stop receiving emails from it, send an email to marpa-parser+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...