Newbei question on position_iterator

View: New views
9 Messages — Rating Filter:   Alert me  

Newbei question on position_iterator

by Johnson Chou :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,
I'm a newbie working with spirit 1.8.x. I'm writing a script parser. I encoutered some questions with my code.

The parser has preformance problem when I use different iterator(see code segment below). When I parser the testall.txt with Code segment 1, it will cost less than 3000 ms , for code segement 2, it will cost 204047 ms!!!!

Any body has idea what' wrong with my code?  The parser please see attached file.


Code segment 1:

typedef char const*         iterator_t;
typedef tree_match<iterator_t> parse_tree_match_t;
typedef parse_tree_match_t::tree_iterator iter_t;

CEasyLanguageParserCore parser;
string text_temp (text);
el_skip_grammar my_skip_p;
tree_parse_info<> info = pt_parse<>(text_temp.c_str(),parser,el_skip_grammer_p);
if( info.full)
{
        TRACE("Good!\n");
        return true;
}
else
{
        TRACE("Bad!\n");
        return false;
}
        return true;


Code segement 2:

CEasyLanguageParserCore parser;
string text_temp (text);
el_skip_grammar my_skip_p;
typedef position_iterator<char const*> iterator_t;
iterator_t begin(text.c_str(), text.c_str() + text.length (), filename);
iterator_t end;
 begin.set_tabchars(8);
tree_parse_info<iterator_t> info = ast_parse<>(begin,end,parser,el_skip_grammer_p);

if( info.full)
        {
                TRACE("Good!\n");
                return true;
        }
        else
        {
                TRACE("Bad!\n");
                return false;
        }
        return true;


easylanguage.htestall.txt

Re: Newbei question on position_iterator

by OvermindDL1 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Sun, Nov 8, 2009 at 10:09 AM, Johnson Chou <zhoujohnson@...> wrote:

>
> Hi,
> I'm a newbie working with spirit 1.8.x. I'm writing a script parser. I
> encoutered some questions with my code.
>
> The parser has preformance problem when I use different iterator(see code
> segment below). When I parser the testall.txt with Code segment 1, it will
> cost less than 3000 ms , for code segement 2, it will cost 204047 ms!!!!
>
> Any body has idea what' wrong with my code?  The parser please see attached
> file.
>
>
> Code segment 1:
>
> typedef char const*         iterator_t;
> typedef tree_match<iterator_t> parse_tree_match_t;
> typedef parse_tree_match_t::tree_iterator iter_t;
>
> CEasyLanguageParserCore parser;
> string text_temp (text);
> el_skip_grammar         my_skip_p;
> tree_parse_info<> info =
> pt_parse<>(text_temp.c_str(),parser,el_skip_grammer_p);
> if( info.full)
> {
>        TRACE("Good!\n");
>        return true;
> }
> else
> {
>        TRACE("Bad!\n");
>        return false;
> }
>        return true;
>
>
> Code segement 2:
>
> CEasyLanguageParserCore parser;
> string text_temp (text);
> el_skip_grammar         my_skip_p;
> typedef position_iterator<char const*> iterator_t;
> iterator_t begin(text.c_str(), text.c_str() + text.length (), filename);
> iterator_t end;
>  begin.set_tabchars(8);
> tree_parse_info<iterator_t> info =
> ast_parse<>(begin,end,parser,el_skip_grammer_p);
>
> if( info.full)
>        {
>                TRACE("Good!\n");
>                return true;
>        }
>        else
>        {
>                TRACE("Bad!\n");
>                return false;
>        }
>        return true;

Would help if you attached a full compilable example.
But regardless, the old 1.8 series (Spirit.Classic in other words) is
slower, more difficult to use, etc..  You should be using the 2.1
series (Spirit.Qi), it is a lot easier to write, lot easier to use, a
lot faster, and a lot more consistent.

As for the position_iterator being slow, I am uncertain as to why,
wait for one of the devs to get here and figure it out, but position
handling in Spirit.Qi is a lot easier now as well, no need for special
iterators.

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Spirit-general mailing list
Spirit-general@...
https://lists.sourceforge.net/lists/listinfo/spirit-general

Re: Newbei question on position_iterator

by Johnson Chou :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

OvermindDL1 wrote:
On Sun, Nov 8, 2009 at 10:09 AM, Johnson Chou <zhoujohnson@hotmail.com> wrote:
>
> Hi,
> I'm a newbie working with spirit 1.8.x. I'm writing a script parser. I
> encoutered some questions with my code.
>
> The parser has preformance problem when I use different iterator(see code
> segment below). When I parser the testall.txt with Code segment 1, it will
> cost less than 3000 ms , for code segement 2, it will cost 204047 ms!!!!
>
> Any body has idea what' wrong with my code?  The parser please see attached
> file.
>
>
> Code segment 1:
>
> typedef char const*         iterator_t;
> typedef tree_match<iterator_t> parse_tree_match_t;
> typedef parse_tree_match_t::tree_iterator iter_t;
>
> CEasyLanguageParserCore parser;
> string text_temp (text);
> el_skip_grammar         my_skip_p;
> tree_parse_info<> info =
> pt_parse<>(text_temp.c_str(),parser,el_skip_grammer_p);
> if( info.full)
> {
>        TRACE("Good!\n");
>        return true;
> }
> else
> {
>        TRACE("Bad!\n");
>        return false;
> }
>        return true;
>
>
> Code segement 2:
>
> CEasyLanguageParserCore parser;
> string text_temp (text);
> el_skip_grammar         my_skip_p;
> typedef position_iterator<char const*> iterator_t;
> iterator_t begin(text.c_str(), text.c_str() + text.length (), filename);
> iterator_t end;
>  begin.set_tabchars(8);
> tree_parse_info<iterator_t> info =
> ast_parse<>(begin,end,parser,el_skip_grammer_p);
>
> if( info.full)
>        {
>                TRACE("Good!\n");
>                return true;
>        }
>        else
>        {
>                TRACE("Bad!\n");
>                return false;
>        }
>        return true;

Would help if you attached a full compilable example.
<===OK. I will attach a simplifid version in this reply.
But regardless, the old 1.8 series (Spirit.Classic in other words) is
slower, more difficult to use, etc..  You should be using the 2.1
series (Spirit.Qi), it is a lot easier to write, lot easier to use, a
lot faster, and a lot more consistent.
<== Just begin to try spirit  2.1. Thanks
As for the position_iterator being slow, I am uncertain as to why,
wait for one of the devs to get here and figure it out, but position
handling in Spirit.Qi is a lot easier now as well, no need for special
iterators.
<==I can NOT find document about position_iterator or file_iterator for
spirit 2.1 . May be I missed them. I hope the parser can figure out the line
number and column number while an error occurred in script. The user will feel
better with it .


Thanks

Best Regards

Johnson


easylanguage.zip, the compilable project with Visual Studio 2008 sp1 testall.txt, The script file for test.

Re: Newbei question on position_iterator

by OvermindDL1 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Sun, Nov 8, 2009 at 7:18 PM, Johnson Chou <zhoujohnson@...> wrote:
> <==I can NOT find document about position_iterator or file_iterator for
> spirit 2.1 . May be I missed them. I hope the parser can figure out the line
> number and column number while an error occurred in script. The user will
> feel
> better with it .

As stated, Spirit2.1 is designed better, there is no more
position_iterator or such things (and the file_iterator is replaced
with a more generically powerful multipass_iterator).  Error handling
in Spirit2.1 passes all the information you need, including position
in the iterator stream (of which you can determine line number and
other things) and there are methods of doing the same in the normal
grammar as well with a little custom functor you can make to handle
it.  :)

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Spirit-general mailing list
Spirit-general@...
https://lists.sourceforge.net/lists/listinfo/spirit-general

Re: Newbei question on position_iterator

by temp-9 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> On Sun, Nov 8, 2009 at 7:18 PM, Johnson Chou <zhoujohnson@...>
> wrote:
>> <==I can NOT find document about position_iterator or file_iterator for
>> spirit 2.1 . May be I missed them. I hope the parser can figure out the
>> line
>> number and column number while an error occurred in script. The user
>> will
>> feel
>> better with it .
>
> As stated, Spirit2.1 is designed better, there is no more
> position_iterator or such things (and the file_iterator is replaced
> with a more generically powerful multipass_iterator).  Error handling
> in Spirit2.1 passes all the information you need, including position
> in the iterator stream (of which you can determine line number and
> other things) and there are methods of doing the same in the normal
> grammar as well with a little custom functor you can make to handle
> it.  :)

Can you provide a sample code how to extract file name/line number from an
iterator? Maybe I'm not up to date but the last time I checked Spirit 2x
had no support for position iterator. I had to use some external code to
get this functionality (thanks to Francois Barel). More details can be
found here
http://old.nabble.com/-2x--Please-add-file-position-iterator-to23633865.html#a23752426

Paul



------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Spirit-general mailing list
Spirit-general@...
https://lists.sourceforge.net/lists/listinfo/spirit-general

Re: Newbei question on position_iterator

by OvermindDL1 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, Nov 10, 2009 at 10:10 PM,  <temp@...> wrote:
> Can you provide a sample code how to extract file name/line number from an
> iterator? Maybe I'm not up to date but the last time I checked Spirit 2x
> had no support for position iterator. I had to use some external code to
> get this functionality (thanks to Francois Barel). More details can be
> found here
> http://old.nabble.com/-2x--Please-add-file-position-iterator-to23633865.html#a23752426

The error function gives you a begin/end/error_pos iterators, I just
brute force it (well, another spirit grammar that just detects eol's
and count a size_t up from those).  May not be efficient, but it is an
error case anyway so I do not really care.  :)

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Spirit-general mailing list
Spirit-general@...
https://lists.sourceforge.net/lists/listinfo/spirit-general

Re: Newbei question on position_iterator

by Daniel James :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2009/11/11  <temp@...>:
> Maybe I'm not up to date but the last time I checked Spirit 2x
> had no support for position iterator.

The classic position iterator is compatible with spirit 2. I'm using
them together in my quickbook port. Although it's pretty awkward and
I'd like to change it in the future to use a more standard spirit 2
style.

Daniel

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Spirit-general mailing list
Spirit-general@...
https://lists.sourceforge.net/lists/listinfo/spirit-general

Re: Newbei question on position_iterator

by Joel de Guzman-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Daniel James wrote:
> 2009/11/11  <temp@...>:
>> Maybe I'm not up to date but the last time I checked Spirit 2x
>> had no support for position iterator.
>
> The classic position iterator is compatible with spirit 2. I'm using
> them together in my quickbook port. Although it's pretty awkward and
> I'd like to change it in the future to use a more standard spirit 2
> style.

You have a quickbook Spirit2 port? Wow! Cool!

Anyway, yeah, we intend to somehow 'modernize' position iterator.
If anyone is interested to do it, you're most welsome.

Regards,
--
Joel de Guzman
http://www.boostpro.com
http://spirit.sf.net
http://www.facebook.com/djowel

Meet me at BoostCon
http://www.boostcon.com/home
http://www.facebook.com/boostcon



------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Spirit-general mailing list
Spirit-general@...
https://lists.sourceforge.net/lists/listinfo/spirit-general

Re: Newbei question on position_iterator

by Daniel James :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2009/11/11 Joel de Guzman <joel@...>:
>
> You have a quickbook Spirit2 port? Wow! Cool!

Well, I'm working on a port, I thought the beta period would be a good
time to start. The only parts that are fully working on spirit 2 are
the post processor and code snippet parser.

Daniel

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Spirit-general mailing list
Spirit-general@...
https://lists.sourceforge.net/lists/listinfo/spirit-general