O/H Eric Niebler έγραψε:
George Petasis wrote:
Actually, xpressive throws an exception:
xpressive error: error_stack: There was insufficient memory to determine whether the regular expression could match the specified character sequence. (12)
Any ideas on that? can I increase the stack size under windows?
That's some grammar! I'm amazed you actually got it to compile. :-P As you've already figured out, you're blowing your stack. I can see some ways to simplify your grammar, but I think your best bet would be to switch to a parser generator like Boost.Spirit. Xpressive's exhaustive backtracking behavior makes it use stack space more greedily than Spirit.
I have used spirit in the past. I am trying to use xpressive, because: a) it has backtracking (which is really cool :-) ) b) it is easier to get it compile, at least with VC++ 2005 (I get far more failures with spirit) But of course, backtracking comes with a cost :-) Stack exhaustion...
If you want to try sticking with Xpressive, here are some things to try:
- Increasing your program's stack size. You're using MSVC? See the /STACK switch for the linker.
I have tested up to 262 MB, but no change :-) My grammar is probably too complex :-). How exactly xpressive uses the stack? Is it a recursive descendant parser?
- Avoid using by_ref(a_sregex) where it's not really necessary. For instance, you have lots of regexes like this:
s_scl__com_ = (as_xpr(","));
s_scl__pvl_ = (as_xpr("-"));
s_scl__sls_ = (as_xpr("/"));
Embedded regexes use more stack space and incur a perf hit that you wouldn't get if you had used ordinary strings for this instead.
Its in my plans to fix this, and detect only the cases references are used...
- Use keep() for the parts of your grammar that do not need exhaustive backtracking semantics. keep(<some regex>) matches <some regex> and then reclaims the stack space used by <some regex>. But then <some regex> can only match in one way, and no alternatives are tried.
I didn't know about keep(). I will read the manuals...
- If you have patterns like (string1 | string2 | string3 ...) where stringN are simple string literals, you're better off using a symbol parser (assuming you're using xpressive 2.0). See http://tinyurl.com/2rd5d7.
To say the truth, I tried to use a symbol table, but I didn't manage to get it to compile. I always got an error when I was using the table in the grammar rules. How can I check what version of xpressive I am using? Initially, I downloaded the latest release of the boost library. But the file regex_actions.hpp was missing, so I downloaded an newer release of xpressive (2.0.1 I think)...
Best of luck!
Thanks :-) Regards, George