Message from discussion
"No hash" error in offside-rule left recursive grammar
Received: by 10.91.59.20 with SMTP id m20mr1137898agk.40.1271608052756;
Sun, 18 Apr 2010 09:27:32 -0700 (PDT)
X-BeenThere: lepl@googlegroups.com
Received: by 10.204.35.68 with SMTP id o4ls2777189bkd.1.p; Sun, 18 Apr 2010
09:27:31 -0700 (PDT)
Received: by 10.204.133.78 with SMTP id e14mr272648bkt.24.1271608051589;
Sun, 18 Apr 2010 09:27:31 -0700 (PDT)
Received: by 10.204.133.78 with SMTP id e14mr272647bkt.24.1271608051564;
Sun, 18 Apr 2010 09:27:31 -0700 (PDT)
Return-Path: <danar...@gmail.com>
Received: from mail-bw0-f214.google.com (mail-bw0-f214.google.com [209.85.218.214])
by gmr-mx.google.com with ESMTP id 11si800457bwz.14.2010.04.18.09.27.30;
Sun, 18 Apr 2010 09:27:30 -0700 (PDT)
Received-SPF: pass (google.com: domain of danar...@gmail.com designates 209.85.218.214 as permitted sender) client-ip=209.85.218.214;
Received: by mail-bw0-f214.google.com with SMTP id 6so3976746bwz.33
for <lepl@googlegroups.com>; Sun, 18 Apr 2010 09:27:30 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.204.101.8 with HTTP; Sun, 18 Apr 2010 09:27:30 -0700 (PDT)
In-Reply-To: <79539f3b-e1c6-4def-8b10-cc1c6131fb4d@j17g2000yqa.googlegroups.com>
References: <438fbcc8-3546-4dc3-87d1-e12bc2901b9a@u31g2000yqb.googlegroups.com>
<79539f3b-e1c6-4def-8b10-cc1c6131fb4d@j17g2000yqa.googlegroups.com>
Date: Sun, 18 Apr 2010 19:27:30 +0300
Received: by 10.204.4.81 with SMTP id 17mr3922167bkq.0.1271608050224; Sun, 18
Apr 2010 09:27:30 -0700 (PDT)
Message-ID: <l2w53d4a6461004180927pca244aecof88d94c7272bd334@mail.gmail.com>
Subject: Re: [LEPL] Re: "No hash" error in offside-rule left recursive grammar
From: Daniel Armak <danar...@gmail.com>
To: lepl@googlegroups.com
X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com:
domain of danar...@gmail.com designates 209.85.218.214 as permitted sender)
smtp.mail=danar...@gmail.com; dkim=pass (test mode) header...@gmail.com
X-Original-Sender: danar...@gmail.com
Reply-To: lepl@googlegroups.com
Precedence: list
Mailing-list: list lepl@googlegroups.com; contact lepl+owners@googlegroups.com
List-ID: <lepl.googlegroups.com>
List-Post: <http://groups.google.com/group/lepl/post?hl=en_US>,
<mailto:lepl@googlegroups.com>
List-Help: <http://groups.google.com/support/?hl=en_US>, <mailto:lepl+help@googlegroups.com>
List-Archive: <http://groups.google.com/group/lepl?hl=en_US>
Sender: lepl@googlegroups.com
List-Subscribe: <http://groups.google.com/group/lepl/subscribe?hl=en_US>,
<mailto:lepl+subscribe@googlegroups.com>
List-Unsubscribe: <http://groups.google.com/group/lepl/subscribe?hl=en_US>,
<mailto:lepl+unsubscribe@googlegroups.com>
Content-Type: multipart/alternative; boundary=00151750e4c0208d9904848552ee
--00151750e4c0208d9904848552ee
Content-Type: text/plain; charset=ISO-8859-1
You're right - after thinking about it some more, left recursion isn't
necessary. I can define a rule for several calls in a row and then replace
it with left-associative Call tokens in the AST. IOW, the grammar wouldn't
specify the associativity at all.
Here's the updated code, and it doesn't trigger the bug, either:
CLine = ContinuedBLineFactory(Token(r'\\'))
expr0 = Token("[A-Za-z_][A-Za-z0-9_]*")
expr1 = Delayed()
def calls_to_call(tokens):
if len(tokens) == 1:
return tokens[0]
elif len(tokens) == 2:
return Call(tokens)
else:
return Call((Call((tokens[0], tokens[1])),
calls_to_call(tokens[2:])))
calls = expr0[2:] > calls_to_call
expr1 += calls | expr0
program = (CLine(expr1) & Eos())
program.config.default_line_aware(block_policy=rightmost)
parsed = program.parse("a b c d")
print(parsed[0])
Thanks again - I've tried using several python parsing libraries and lepl is
by far the most powerful!
Daniel Ermak
--
You received this message because you are subscribed to the Google Groups "lepl" group.
To post to this group, send email to lepl@googlegroups.com.
To unsubscribe from this group, send email to lepl+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/lepl?hl=en.
--00151750e4c0208d9904848552ee
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">You're right - after thinking about it some more, left=
recursion isn't necessary. I can define a rule for several calls in a =
row and then replace it with left-associative Call tokens in the AST. IOW, =
the grammar wouldn't specify the associativity at all.=A0<div>
<br><div>Here's the updated code, and it doesn't trigger the bug, e=
ither:</div><div><br></div><div><div>CLine =3D ContinuedBLineFactory(Token(=
r'\\'))</div><div><br></div><div>expr0 =3D Token("[A-Za-z_][A-=
Za-z0-9_]*")</div>
<div><br></div><div>expr1 =3D Delayed()</div><div><br></div><div>def calls_=
to_call(tokens):</div><div>=A0=A0 =A0if len(tokens) =3D=3D 1:</div><div>=A0=
=A0 =A0 =A0 =A0return tokens[0]</div><div>=A0=A0 =A0elif len(tokens) =3D=3D=
2:</div><div>=A0=A0 =A0 =A0 =A0return Call(tokens)</div>
<div>=A0=A0 =A0else:</div><div>=A0=A0 =A0 =A0 =A0return Call((Call((tokens[=
0], tokens[1])), calls_to_call(tokens[2:])))</div><div><br></div><div>calls=
=3D expr0[2:] > calls_to_call</div><div>expr1 +=3D calls | expr0=A0</di=
v><div><br></div><div>
program =3D (CLine(expr1) & Eos())</div><div>program.config.default_lin=
e_aware(block_policy=3Drightmost)</div><div><br></div><div>parsed =3D progr=
am.parse("a b c d")</div><div>print(parsed[0])</div><div><br></di=
v>
</div><div>Thanks again - I've tried using several python parsing libra=
ries and lepl is by far the most powerful!</div></div><div><br></div><div>D=
aniel Ermak</div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups "=
lepl" group.<br />
To post to this group, send email to lepl@googlegroups.com.<br />
To unsubscribe from this group, send email to lepl+unsubscribe@googlegroups=
.com.<br />
For more options, visit this group at http://groups.google.com/group/lepl?h=
l=3Den.<br />