Understanding actions, default and custom, where to start from?

70 views
Skip to first unread message

Daniel Blanch

unread,
Mar 13, 2017, 9:59:35 AM3/13/17
to marpa parser
Hi Marpers,

I've been using Marpa for a while, it seems promising, but I find it difficult to understand how default actions and custom actions work together when trying to get a result. Where can I find a tutorial or documentation to understand it? How did you learn Marpa? Documentation is a bit confusing.

Thank you very much in advance.

Regards.

Daniel.

Ruslan Shvedov

unread,
Mar 13, 2017, 10:53:56 AM3/13/17
to marpa-...@googlegroups.com
Hi Daniel, it helps (at times) to work the other way round—code to doc, e.g., re actions, start from a simple example and read the doc to clarify/elaborate.

Another way is that Marpa can produce a parse value as an abstract syntax tree (ast) (articlecode) that you can traverse recursively, as, e.g., in this simple but functional json parser.  





--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Daniel Blanch

unread,
Mar 13, 2017, 3:15:07 PM3/13/17
to marpa parser
Thank you very much.
To unsubscribe from this group and stop receiving emails from it, send an email to marpa-parser...@googlegroups.com.

Daniel Blanch

unread,
Mar 14, 2017, 11:08:38 AM3/14/17
to marpa parser
Hi, I keep trying to understand the semantics of marpa. Forgive me if my questions are too basic.

I've read the documentation, in particular this http://search.cpan.org/~jkegl/Marpa-R2-3.000000/pod/Semantics.pod.

I've noticed that instead of using actions, it uses bless. I'm not sure if I have understand the reason well enough. What I understand is the following.

1) Marpa's bless, creates objects initializing it with the parse result of the rule instance
2) If the result of other subrules is blessed too, the parent rule will get a reference to the subrules blessed objects.
3) Doing so provides a somehow 'Semantic tree' 
4) After parsing I'll get a reference of the root node i can use to traverse the whole tree and get the result this way.

I'm I right?

So, what's the difference with actions? Is it that with actions the result is computed on the fly? do actions use an AST then or do the parse and the result in just one step.

What's the recomended way of using marpa to translate a language, bless adverb or action adverb?

Than you very much in advance.

Jeffrey Kegler

unread,
Mar 14, 2017, 11:29:39 AM3/14/17
to Marpa Parser Mailing LIst
"Bless" versus actions is just a TIMTOWTDI feature.  I found bless less useful, to the extent I considered removing it in the forthcoming R3 Marpa.  But it has its fans.

If how bless works doesn't leap out at you, stick with actions -- they're all I use.  You can learn how to use bless later -- or never.

The actions can generate an AST, or do all of the semantics immediately.  In fact you can generate an AST just using a default action:

:default ::= action => [name, values]

This separates the parsing from the semantics, so it's easier to visualize what's going on.  Particularly for your first Marpa project, it's often best to start with an AST.

The AST method is also quite powerful and, in terms of speed, reasonable, so that you may wind up sticking with it as your final way of doing things.

--
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+unsubscribe@googlegroups.com.

Ruslan Shvedov

unread,
Mar 14, 2017, 12:53:51 PM3/14/17
to marpa-...@googlegroups.com
This is comparison of AST vs. actions that is IMHO applicable to Marpa semantics.

--

Daniel Blanch

unread,
Mar 15, 2017, 2:42:27 PM3/15/17
to marpa parser

Much clearer now, thanks a lot.


El martes, 14 de marzo de 2017, 16:29:39 (UTC+1), Jeffrey Kegler escribió:
"Bless" versus actions is just a TIMTOWTDI feature.  I found bless less useful, to the extent I considered removing it in the forthcoming R3 Marpa.  But it has its fans.

If how bless works doesn't leap out at you, stick with actions -- they're all I use.  You can learn how to use bless later -- or never.

The actions can generate an AST, or do all of the semantics immediately.  In fact you can generate an AST just using a default action:

:default ::= action => [name, values]

This, with this:

 $Data::Dumper::Deepcopy = 1; # prints all node names

Helped me to understand better what marpa does. 
 

This separates the parsing from the semantics, so it's easier to visualize what's going on.  Particularly for your first Marpa project, it's often best to start with an AST.

The AST method is also quite powerful and, in terms of speed, reasonable, so that you may wind up sticking with it as your final way of doing things.

what if i want to implement a visitor pattern, isn't it what bless method is for? 

On Tue, Mar 14, 2017 at 8:08 AM, Daniel Blanch <daniel.blan...@gmail.com> wrote:
Hi, I keep trying to understand the semantics of marpa. Forgive me if my questions are too basic.

I've read the documentation, in particular this http://search.cpan.org/~jkegl/Marpa-R2-3.000000/pod/Semantics.pod.

I've noticed that instead of using actions, it uses bless. I'm not sure if I have understand the reason well enough. What I understand is the following.

1) Marpa's bless, creates objects initializing it with the parse result of the rule instance
2) If the result of other subrules is blessed too, the parent rule will get a reference to the subrules blessed objects.
3) Doing so provides a somehow 'Semantic tree' 
4) After parsing I'll get a reference of the root node i can use to traverse the whole tree and get the result this way.

I'm I right?

So, what's the difference with actions? Is it that with actions the result is computed on the fly? do actions use an AST then or do the parse and the result in just one step.

What's the recomended way of using marpa to translate a language, bless adverb or action adverb?

Than you very much in advance.





On Monday, March 13, 2017 at 2:59:35 PM UTC+1, Daniel Blanch wrote:
Hi Marpers,

I've been using Marpa for a while, it seems promising, but I find it difficult to understand how default actions and custom actions work together when trying to get a result. Where can I find a tutorial or documentation to understand it? How did you learn Marpa? Documentation is a bit confusing.

Thank you very much in advance.

Regards.

Daniel.

--
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.

Daniel Blanch

unread,
Mar 15, 2017, 3:30:54 PM3/15/17
to marpa parser
Thanks a lot too, very useful.
To unsubscribe from this group and stop receiving emails from it, send an email to marpa-parser...@googlegroups.com.

Ruslan Shvedov

unread,
Mar 16, 2017, 4:01:13 AM3/16/17
to marpa-...@googlegroups.com
On Wed, Mar 15, 2017 at 9:42 PM, Daniel Blanch <daniel.blan...@gmail.com> wrote:

Much clearer now, thanks a lot.

El martes, 14 de marzo de 2017, 16:29:39 (UTC+1), Jeffrey Kegler escribió:
"Bless" versus actions is just a TIMTOWTDI feature.  I found bless less useful, to the extent I considered removing it in the forthcoming R3 Marpa.  But it has its fans.

If how bless works doesn't leap out at you, stick with actions -- they're all I use.  You can learn how to use bless later -- or never.

The actions can generate an AST, or do all of the semantics immediately.  In fact you can generate an AST just using a default action:

:default ::= action => [name, values]

This, with this:

 $Data::Dumper::Deepcopy = 1; # prints all node names

Helped me to understand better what marpa does. 
 

This separates the parsing from the semantics, so it's easier to visualize what's going on.  Particularly for your first Marpa project, it's often best to start with an AST.

The AST method is also quite powerful and, in terms of speed, reasonable, so that you may wind up sticking with it as your final way of doing things.

what if i want to implement a visitor pattern, isn't it what bless method is for? 
IMHO, yes, or the interpreter pattern, as is semantics_package option of the recognizer

BTW, I once wrote a helper module to work with Marpa::R2 ASTs and had my share of infatuation with visitor and interpreter patterns that, unfortunately, I had not time and/or focus to release or maintain. Perhaps you’ll find it interesting and/or useful.
 

On Tue, Mar 14, 2017 at 8:08 AM, Daniel Blanch <daniel.blan...@gmail.com> wrote:
Hi, I keep trying to understand the semantics of marpa. Forgive me if my questions are too basic.

I've read the documentation, in particular this http://search.cpan.org/~jkegl/Marpa-R2-3.000000/pod/Semantics.pod.

I've noticed that instead of using actions, it uses bless. I'm not sure if I have understand the reason well enough. What I understand is the following.

1) Marpa's bless, creates objects initializing it with the parse result of the rule instance
2) If the result of other subrules is blessed too, the parent rule will get a reference to the subrules blessed objects.
3) Doing so provides a somehow 'Semantic tree' 
4) After parsing I'll get a reference of the root node i can use to traverse the whole tree and get the result this way.

I'm I right?

So, what's the difference with actions? Is it that with actions the result is computed on the fly? do actions use an AST then or do the parse and the result in just one step.

What's the recomended way of using marpa to translate a language, bless adverb or action adverb?

Than you very much in advance.





On Monday, March 13, 2017 at 2:59:35 PM UTC+1, Daniel Blanch wrote:
Hi Marpers,

I've been using Marpa for a while, it seems promising, but I find it difficult to understand how default actions and custom actions work together when trying to get a result. Where can I find a tutorial or documentation to understand it? How did you learn Marpa? Documentation is a bit confusing.

Thank you very much in advance.

Regards.

Daniel.

--
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.

--
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+unsubscribe@googlegroups.com.

Ron Savage

unread,
Mar 16, 2017, 6:32:36 PM3/16/17
to marpa parser
Hi Daniel
Have you seen the unofficial Marpa home page: http://savage.net.au/Marpa.html?

Daniel Blanch

unread,
Mar 16, 2017, 9:48:42 PM3/16/17
to marpa parser
Hi Ron,

I skimmed thorough it. I'll read it more carefully when I have time. Thanks.

Daniel Blanch

unread,
Mar 16, 2017, 9:52:56 PM3/16/17
to marpa parser
Thanks I've bookmarked your code, I'll have a look at this when I have time. Thanks again for your support.
Reply all
Reply to author
Forward
0 new messages