9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: "J.R. Mauro" <jrm8005@gmail.com>
To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net>
Subject: Re: [9fans] Recursive structural expressions?
Date: Thu, 20 Aug 2009 20:21:55 -0400	[thread overview]
Message-ID: <3aaafc130908201721g78bb3613y9d081aca10fa7d9d@mail.gmail.com> (raw)
In-Reply-To: <d2d1b9ba56eb1f28c751d34dd852cdb5@quanstro.net>

On Thu, Aug 20, 2009 at 5:26 PM, erik quanstrom<quanstro@quanstro.net> wrote:
>> No, I know you can apply them `recursively', I mean something more
>> like an expression in a CFG or yacc.
>>
>> >
>> > can you outline somehow what you're thinking of?
>>
>> Basically, if you could take a bracketed expression in sam and then
>> name it, and then call it recursively.
>>
>> All the problems with CFGs (shift/reduce problems, ambiguities, etc)
>> would possibly apply.
>
> could you give an example in your proposed language?
> i don't see how greedy regular expressions wouldn't kill you.
> example.  let's say you have a SRE that breaks text into lines,
> you couldn't apply that recursively.  in fact i think you'd have
> the same problem with any SRE, since they are greedy and
> can't count.
>
> maybe i'm just confused because 'x' goes from a blob of text
> to a stream of tokens.  where as grammars go from a stream
> of tokens to productions.  maybe you mean to replace the
> traditional tokenizer with named SREs?

Here's an example. Let's make the syntax extra pukey: @#, where # is
1-9, defines a `named procedure', which is the same thing as putting
something in braces in Sam.

x/.*\n/ @1{ ( @1 ) | @1 ( @1 ) ( ) | }

Spaces have been added to reduce ugliness, but in the ``real'' syntax,
the spaces would have to be left out. The last pipe followed by a
space represents the null string. The entire expression should,
despite me being really rusty at CS Theory, match balanced strings of
parentheses.

The problems that would arise with this scheme include:
0) Infinite recursion
1) Shift/reduce errors
2) Ambiguities

I'm not sure if this is as powerful as CFGs, but it is at least more
powerful than regular expressions. Again, I'm not great at theory and
it's been a while since I did any. If we call this syntax S, I have
proven (hopefully correctly) only this:

L(Reg) < L(S) <= L(CFG)

Newsham was thinking about it more lucidly than I was on the IRC
channel about what it's really equivalent to.

Hopefully this makes it clear.

>
> - erik
>
>



  reply	other threads:[~2009-08-21  0:21 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-20 17:52 J.R. Mauro
2009-08-20 19:53 ` erik quanstrom
2009-08-20 20:33   ` J.R. Mauro
2009-08-20 20:39     ` erik quanstrom
2009-08-20 21:14       ` J.R. Mauro
2009-08-20 21:26         ` erik quanstrom
2009-08-21  0:21           ` J.R. Mauro [this message]
2009-08-21  1:01             ` erik quanstrom
2009-08-21  1:14               ` Charles Forsyth
2009-08-22  1:10                 ` J.R. Mauro
2009-08-23 19:59                   ` Aharon Robbins
2009-08-23 21:27                     ` Rob Pike
2009-08-21 13:58               ` J. R. Mauro
2009-08-21 14:24 ` Russ Cox
2009-08-21 14:57   ` J. R. Mauro

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3aaafc130908201721g78bb3613y9d081aca10fa7d9d@mail.gmail.com \
    --to=jrm8005@gmail.com \
    --cc=9fans@9fans.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).