How is the parser grammar correctness checked and reported in Boost Spirit?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

How is the parser grammar correctness checked and reported in Boost Spirit?

Yiqing
Hi,

In Boost Spirit, the grammar is inlined in the C++ code, no pre-generation for the parser is needed which is good. But how  is the parser grammar correctness checked and reported? Is it done at run time during the parsing? When it fails, it only reports the location where no matching is found, you can’t tell if it’s a parser grammar problem or a syntax problem. And exhaustion tests for each scenario is needed in order to test the correctness of the grammar.

Am I missing something here?

Thanks,

Yiqing Yang
Reply | Threaded
Open this post in threaded view
|

Re: How is the parser grammar correctness checked and reported in Boost Spirit?

Joel de Guzman
On 5/28/15 4:27 AM, Yiqing wrote:

> Hi,
>
> In Boost Spirit, the grammar is inlined in the C++ code, no pre-generation
> for the parser is needed which is good. But how  is the parser grammar
> correctness checked and reported? Is it done at run time during the parsing?
> When it fails, it only reports the location where no matching is found, you
> can’t tell if it’s a parser grammar problem or a syntax problem. And
> exhaustion tests for each scenario is needed in order to test the
> correctness of the grammar.
>
> Am I missing something here?

A declarative PEG grammar should make it obvious (and unambiguous)
whether an error is from the syntax or a problem with the grammar.
That's one of the virtues of a PEG grammar: it has exactly one valid
parse tree. You should be able to actually trace the validity of a
syntax from the grammar. There is no ambiguity in how a grammar is
interpreted.

To check your if it is your grammar's problem, use BOOST_SPIRIT_DEBUG to
see the trace and determine what and where the problem is including the
surrounding context.

Regards,
--
Joel de Guzman
http://www.ciere.com
http://boost-spirit.com
http://www.cycfi.com/


------------------------------------------------------------------------------
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
Reply | Threaded
Open this post in threaded view
|

Re: How is the parser grammar correctness checked and reported in Boost Spirit?

Yiqing
Hi Joel,

Thanks for your explanations.
After reading more about PEG grammar, I understand that it can avoid ambiguous by the always choosing the first rule. How the left recursive in grammar is reported? Still use BOOST_SPIRIT_DEBUG to see the trace?

Thanks,

Yiqing Yang

-----Original Message-----
From: Joel de Guzman [mailto:[hidden email]]
Sent: Wednesday, May 27, 2015 11:29 PM
To: [hidden email]
Subject: Re: [Spirit-general] How is the parser grammar correctness checked and reported in Boost Spirit?

On 5/28/15 4:27 AM, Yiqing wrote:

> Hi,
>
> In Boost Spirit, the grammar is inlined in the C++ code, no
> pre-generation for the parser is needed which is good. But how  is the
> parser grammar correctness checked and reported? Is it done at run time during the parsing?
> When it fails, it only reports the location where no matching is
> found, you can’t tell if it’s a parser grammar problem or a syntax
> problem. And exhaustion tests for each scenario is needed in order to
> test the correctness of the grammar.
>
> Am I missing something here?

A declarative PEG grammar should make it obvious (and unambiguous) whether an error is from the syntax or a problem with the grammar.
That's one of the virtues of a PEG grammar: it has exactly one valid parse tree. You should be able to actually trace the validity of a syntax from the grammar. There is no ambiguity in how a grammar is interpreted.

To check your if it is your grammar's problem, use BOOST_SPIRIT_DEBUG to see the trace and determine what and where the problem is including the surrounding context.

Regards,
--
Joel de Guzman
http://www.ciere.com
http://boost-spirit.com
http://www.cycfi.com/


------------------------------------------------------------------------------
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
------------------------------------------------------------------------------
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
Reply | Threaded
Open this post in threaded view
|

Re: How is the parser grammar correctness checked and reported in Boost Spirit?

Joel de Guzman
On 6/2/15 2:59 AM, YiQing Yang wrote:
> Hi Joel,
>
> Thanks for your explanations.
> After reading more about PEG grammar, I understand that it can avoid ambiguous by the
always choosing the first rule. How the left recursive in grammar is reported? Still use
BOOST_SPIRIT_DEBUG to see the trace?

Yup. BOOST_SPIRIT_DEBUG. But left recursive rules are obvious.
Try writing a function that recursively calls itself without a
terminating condition :-)

Regards,
--
Joel de Guzman
http://www.ciere.com
http://boost-spirit.com
http://www.cycfi.com/

------------------------------------------------------------------------------
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general