Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.postscript > #3696

Re: Got the regular expression parser working again hurray!

Newsgroups comp.lang.postscript
Date 2021-11-05 17:21 -0700
References <5dc1e95f-c48c-4bfd-bdfb-d83a44234be8n@googlegroups.com> <sm3hr9$qan$1@dont-email.me>
Message-ID <950f8de4-d105-439d-b22e-d04e74cc3aacn@googlegroups.com> (permalink)
Subject Re: Got the regular expression parser working again hurray!
From luser droog <luser.droog@gmail.com>

Show all headers | View raw


On Friday, November 5, 2021 at 10:15:55 AM UTC-5, Jeffrey H. Coffield wrote:
> On 11/04/2021 07:04 PM, luser droog wrote: 
> > For the umpteenth time I've rewritten my parser combinators. 
> > With any luck, they finally have all the necessary bells and 
> > whistles added to be useful for other stuff.
> I spent a significant amount of time writing several versions of a 
> generalized parser and never got all the "bells and whistles" that I 
> wanted. Then I came across Antlr4 which is in Java and while I admire 
> your intent to parse Postscript in Postscript, Antlr4 has tons of "bells 
> and whistles" and can be applied to practically any language, although I 
> don't see that anyone has posted a PostScript grammar yet. There about 
> 250 different languages currently available at : 
> 
> https://github.com/antlr/grammars-v4 
> 
> There is a grammar for something called RPN which sounds like it could 
> be a starting point. 
> 
> https://github.com/antlr/grammars-v4/tree/master/rpn 
> 
> Antlr4 takes some time to learn and I'm not sure how much Java you would 
> need to know (I program about 80% in Java now) but if it sounded like 
> something you are interested in, I would be willing to help. There is a 
> great book "The Definitive Antlr 4 Reference". 
> 
> I am not associated directly with Antlr4 but have submitted some patches. 
> 
> Jeff Coffield 
> www.digitalsynergyinc.com

Thanks, I'll check those out. I've had Antlr suggested to me many times before
but I've shied away thus far, probably from squeamish feelings about Java.
(If only Sun NeWS had been successful, we might never have needed Java.)

But I had to use Java for several school projects last year while finally 
completing my degree. It's not so scary anymore. I'm pretty happy with
the composability of my functions the way they work now, but there are
probably ways to optimize the execution or use a different model behind
the scenes and maintain a similar interface. I'm also going to need a 
nice syntax for describing grammars so I can write a parser for /that/
and have it translate to the combinators. Then you can have any color
you want as long as it's black.

Which bells and whistles were you still missing? My latest version adds
error messages which were sorely lacking in previous ones. But I've also
gotten a handle on how to do lazy execution. And bizarrely enough, I've
been able to prototype in PostScript and then re-code in C, despite the
dissimilarity between those (the C one kinda pretends to be Lisp, tho).

For PostScript Level 1, the grammar is actually super simple.

<Object> :: <Single>
         || { <Object> * }

<Single> :: <Integer> | <Real> | <Name> | <String>

Some fiddly stuff further down the tree. But it's just the one production
for procedures that needs a CFG. The rest of the language is strictly
Regular. Level 2 adds a few more kinds of Single, like binary name 
tokens and binary object encodings. 

So probably no one has written a grammar for PS for popular parsing
libraries because it doesn't get you anywhere. You get just [Object
Object Object ...]. It would get you like 2% closer to being able to
write a translator or interpreter for PostScript. Whereas with almost
any other structured language the grammar gets you roughly 50% there.

Back to comp.lang.postscript | Previous | NextPrevious in thread | Find similar


Thread

Got the regular expression parser working again hurray! luser droog <luser.droog@gmail.com> - 2021-11-04 19:04 -0700
  Re: Got the regular expression parser working again hurray! "Jeffrey H. Coffield" <jeffrey@digitalsynergyinc.com> - 2021-11-05 08:15 -0700
    Re: Got the regular expression parser working again hurray! luser droog <luser.droog@gmail.com> - 2021-11-05 17:21 -0700

csiph-web