Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.python
Re: simpleparse - what is wrong with my grammar?
Mike C. Fletcher
2/24/2008 6:58:00 PM
Laszlo Nagy wrote:
> The program below gives me "segmentation fault (core dumped)".
>
> Environment:
> Linux gandalf-desktop 2.6.20-16-generic #2 SMP Tue Feb 12 05:41:34
> UTC 2008 i686 GNU/Linux
> Python 2.5.1
>
> What is wrong with my grammar? Can it be an internal error in simpleparse?
>
You've created an infinitely recursing grammar. SimpleParse is a
straightforward recursive descent parser without look-ahead (unless
explicitly coded) or ambiguity resolution. You are asking it to parse
"expr" to see if "expr,binop,expr" is matched. It will continue
recursing down into "expr" until it runs out of ram or otherwise
encounters a system-level fault.
You need to disambiguate your grammar to have it work with SimpleParse.
How you do that will depend on what you really meant by expr,binop,expr:
a&b&c
could be parsed as either:
((a&b)&c)
or:
(a&(b&c))
the following creates a parser that produces the first option (which is,
I *think* what you wanted):
expr := (simple_expr,no_binop)/binop_expr
binop_expr := simple_expr,binop_tail
>simple_expr< := (paren_expr/unop_expr/word)
>no_binop< := ?-binop/end
<end> := EOF
paren_expr := "(",expr,")"
unop_expr := unop,expr
>binop_tail< := binop,expr
unop := ("+"/"-")
binop := ("|"/"&"/"@")
word := [a-zA-Z], [a-zA-Z0-9_]*
the ?- lookahead is reasonably inefficient, but lookahead is always
going around discarding partial results anyway, so it's no worse than
most other formulations.
HTH,
Mike
--
________________________________________________
Mike C. Fletcher
Designer, VR Plumber, Coder
http://www.vrp...
http://blog.vrp...
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Re: simpleparse - what is wrong with my grammar?
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password