Return-Path: simon.hay@lincoln.ox.ac.uk Received: from 212.135.211.74 (MAIL.HAYWIRED.ORG) by null (org.ibex.mail.protocol.SMTP) with ESMTP for ; Wed, 27 Sep 2006 03:29:56 -0700 Received: from [172.16.0.230] (unknown [172.16.0.230]) by mail.haywired.org (Postfix) with ESMTP id E0FF817FB7; Wed, 27 Sep 2006 11:25:25 +0100 (BST) In-Reply-To: References: <99F37304-CFDF-4FBB-ABA2-25CFC079A685@lincoln.ox.ac.uk> Mime-Version: 1.0 (Apple Message framework v752.2) Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: <41BCD451-2EFF-47D8-8D42-58FD2A2387C9@lincoln.ox.ac.uk> Cc: sbp-interest@research.cs.berkeley.edu Content-Transfer-Encoding: 7bit From: Simon Hay Subject: [sbp-interest] Re: Quick reference? Date: Wed, 27 Sep 2006 11:29:51 +0100 To: Adam Megacz X-Mailer: Apple Mail (2.752.2) Envelope-To: sbp-interest@research.cs.berkeley.edu List-Id: The Scannerless Boolean Parser When I try using s = "safe" "(" [0-9]+ ")" /ws ws = [\r\n ]** to parse safe(12) it works fine: expanding... {1 2} but if I try to parse safe ( 12 ) or anything else with spaces, I get Exception in thread "main" unexpected end of file at 1:6 text: afe(12 expected: at edu.berkeley.sbp.ParseFailed.error(ParseFailed.java:218) at edu.berkeley.sbp.GSS$Phase.shift(GSS.java:269) at edu.berkeley.sbp.GSS$Phase.reset(GSS.java:90) at edu.berkeley.sbp.GSS$Phase.(GSS.java:75) at edu.berkeley.sbp.Parser.parse(Parser.java:40) at edu.berkeley.sbp.chr.CharParser.parse(CharParser.java:16) at sjehtest.main(sjehtest.java:32) Hmm... The interspersing is a really neat idea - if only I could figure out what I'm doing wrong! Simon On 26 Sep 2006, at 22:39, Adam Megacz wrote: > > Simon Hay writes: >> Is there a cheat-sheet/quick reference guide type thing for SBP's >> metagrammar? > > Unfortunately no, although I really should write one. The metagrammar > (tests/meta.g) is a pretty concise reference of all the operators, > although it doesn't say what they do. Part of my reason for stalling > is that I don't yet consider meta.g to be official/frozen yet (whereas > the programmatic API is officially frozen). However, I don't expect > meta.g to change much. See the end of this message for further > explanation. > >> From looking through your examples, it seems like you can use / to >> intersperse things - i.e. /ws means 'with any amount of whitespace >> in between all these previous things', > > Yes, although "ws" needs to be defined as a production, ie > > ws = [\r\n ]** > >> but when I try to actually use it like that it doesn't work. > > Hrm, in what way does it not work? > > The semantics of the "/" operator are this: it binds more weakly than > almost any other operator except "|", so it acts on the largest > possible subexpression to its left. It then inserts the "spacer" > production between each of the subexpression productions. So > > a b c /x > > Means > > a x b x c > > However, note that > > (a b c) /x > > Is just > > (a b c) > > ... because the "/" operator doesn't do anything to single-element > subexpressions, and parenthesis create a single element out of a > sequence of elements. > > Also, note that "*/" is a single operator, as is "**/", "++/", and > "+/". These operators act like the repetition operator, but with a > spacer "factored in" to the recursive production that is generated for > repetition. So, for example > > (A=a+) expands to something like (A=B B= a | a B) > > and > > (A=a+/x) expands to something like (A=B B= a | a x B) > > Although these expansions aren't precisely correct because the > "virtual production" that the repetition operator creates ("B" in the > examples above) special magical abilities that let it hoist its output > into a single parent with N children, rather than a parse tree of > depth N where every node has only a single left child (which is what > you would get with the "literal" expansion). > > The "special magical abilities" mentioned in the preceding paragraph > are, in my opinion, a major "wart" on how the metagrammar works, and > one of the reasons why I'm not yet ready to freeze it the way I have > frozen all APIs in the edu.berkeley.sbp.* root package. > > Thanks again for your questions and comments! > > - a > > -- > PGP/GPG: 5C9F F366 C9CF 2145 E770 B1B8 EFB1 462D A146 C380