Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.postscript > #3701
| Newsgroups | comp.lang.postscript |
|---|---|
| Date | 2021-11-11 15:02 -0800 |
| References | <9771d0c6-d9c6-41da-a89f-202d7dcb81e1n@googlegroups.com> <831710ef-7c4c-462d-883e-d69adf4be0f5n@googlegroups.com> <c8e1813b-c31f-437a-a251-ffa4e4cf77e2n@googlegroups.com> |
| Message-ID | <5cd381d2-d712-4d2e-b14a-6635f4d86682n@googlegroups.com> (permalink) |
| Subject | qapplaH (was Re: PS Level 1 grammar) |
| From | luser droog <luser.droog@gmail.com> |
On Tuesday, November 9, 2021 at 10:56:46 AM UTC-6, luser droog wrote:
> On Monday, November 8, 2021 at 11:49:30 AM UTC-6, luser droog wrote:
> > On Sunday, November 7, 2021 at 6:40:43 PM UTC-6, luser droog wrote:
> > > Here's a rough draft of the grammar for a PS tokenizer using my new functions.
> A little more fleshed out, formatted, and slightly tested.
[snip]
> Still need to interpret
> the hex characters and do some handling for procedures.
> And e notation.
>
> Then a further challenge if I actually want to emulate the
> `token` operator. I'll need to reliably recreate the remainder substring.
> This string may or may not be reliably tucked into the lazy
> remainder list still in string form. So some fiddly business may
> be needed to reconstruct this string.
>
It is done. All that stuff.
https://github.com/luser-dr00g/pcomb/blob/f2d20f01a4a4a0fb28e184143f66d0d0f0584bdb/ps/struct2.ps
https://github.com/luser-dr00g/pcomb/blob/f2d20f01a4a4a0fb28e184143f66d0d0f0584bdb/ps/pc11a.ps
https://github.com/luser-dr00g/pcomb/blob/f2d20f01a4a4a0fb28e184143f66d0d0f0584bdb/ps/pc11atoken.ps
$ cat pc11atoken.ps
%errordict/typecheck{pq}put
(pc11a.ps)run <<
/middle { 1 1 index length 2 sub getinterval }
/interpret-octal { 0 exch { first 48 sub exch 8 mul add } forall }
/interpret-hex {
{ dup (9) le { first 48 sub }{ first 55 sub dup 15 gt { 32 sub } if } ifelse } map
dup length 2 mod 1 eq { [ 0 ] compose } if
[ exch 2 { aload pop exch 16 mul add to-char } fortuple ]
to-string }
/interpret-ascii85 {
{ dup (z) eq { pop (!)(!)(!)(!)(!) }{ dup ( \t\n) within { pop } if } ifelse } map
[ 1 index length 5 mod { (u) } repeat ] compose
[ exch 5 {
0 exch { first 33 sub exch 85 mul add } forall
4 { dup 256 mod exch 256 idiv } repeat pop 4 aa reverse
{ to-char } forall
} fortuple ]
to-string }
>> begin
/delimiters ( \t\n()/%[]<>{}) def
/initials ([]) anyof def
/delimiter delimiters anyof def
/octal (0)(7) range def
/digit (0)(9) range def
/alpha (a)(z) range (A)(Z) range alt def
/regular delimiters noneof def
/spaces ( \t\n) anyof many def
/rad-digit //digit //alpha alt def
/rad-integer //digit //digit maybe then (#) char then //rad-digit some then def
/number //digit some def
/opt-number //digit many def
/eE (eE) anyof (+-) anyof maybe then //number then def
/integer (+-) anyof maybe //number then def
/real (+-) anyof maybe
//number (.) char then //opt-number then //eE maybe then
(.) char //number then //eE maybe then alt
//number //eE then alt
then def
/name //regular some def
/ps-char {-777 exec} def
/escape (\\) char
(\\) char
(\() char alt
(\)) char alt
(n) char { pop (\n) one } using alt
(r) char { pop (\r) one } using alt
(t) char { pop (\t) one } using alt
(b) char { pop (\b) one } using alt
(f) char { pop (\f) one } using alt
//octal //octal maybe then //octal maybe then
{ fix interpret-octal to-char one } using alt
xthen def
/ps-string (\() char //ps-char executeonly many then (\)) char then def
//ps-char 0 //escape
//ps-string alt
(()) noneof alt put
/hex-char //digit (a)(f) range (A)(F) range alt alt def
/hex-string (<) char
//spaces //hex-char xthen many then //spaces thenx
(>) char then def
/ascii85-char ( )(z) range (\t\n) anyof alt def
/ascii85-string (<~) str
//spaces //ascii85-char xthen many xthen //spaces thenx
(~>) str thenx def
/object {-777 exec} def
/ps-token //spaces //object xthen def
//object 0 //rad-integer { fix to-string cvi } using
//real { fix to-string cvr } using alt
//integer { fix to-string cvi } using alt
(/) char (/) char then //name then { fix to-string rest rest cvn load } using alt
(/) char //name maybe then { fix to-string rest cvn cvlit } using alt
//name { fix to-string cvn cvx } using alt
//ps-string { fix to-string middle } using alt
//hex-string { fix middle interpret-hex } using alt
//ascii85-string { fix interpret-ascii85 } using alt
({) char
//ps-token many executeonly xthen
//spaces %{(s)= ps}using
(}) char %{(b)= ps}using
xthen
thenx { first cvx } using alt
//initials (<<) str alt (>>) str alt { fix to-string cvn cvx } using alt
put
/remainder-length {
dup zero eq { pop 0 }{
dup type /arraytype ne { what? }{
dup xcheck {
2 get length
}{
second remainder-length 1 add
} ifelse
} ifelse } ifelse
} def
/mytoken {
dup length 0 gt {
dup 0 0 3 2 roll string-input //ps-token exec +is-ok { % s result=ok
second aload pop % s res rem
%dup zero eq { 3 -1 roll pop pop () exch true }{
%dup type /arraytype eq 1 index xcheck and { 3 -1 roll pop 2 get exch true }{
3 -1 roll exch remainder-length 1 index length 1 index sub exch getinterval
exch true
%} ifelse } ifelse
}{ % s result=not-ok
pop pop false
} ifelse
}{ pop false } ifelse
} def
/test-mytoken {
/s exch def
s token %1 index type =
s mytoken %1 index type =
} def
{
0 0 (47) string-input //integer exec pc
0 0 (47) string-input //number exec pc
0 0 (8#117) string-input
//digit //digit maybe then (#) char then //rad-digit some then exec pc
%quit
0 0 (8#117) string-input //rad-integer exec pc
0 0 (1.17) string-input //real exec pc
} pop
(8#117) test-mytoken pc
(47) test-mytoken pc
(string) test-mytoken pc
([stuff) test-mytoken pc
(/litname) test-mytoken pc
(42.42) test-mytoken pc
((a\\117 \\\\string\\n)) test-mytoken pc
/thing 12 def
(//thing) test-mytoken pc
(<abc def >) test-mytoken pc
(name[delim) test-mytoken pc
({a proc}) test-mytoken pc
(/(str)) test-mytoken pc
(2e5) test-mytoken pc
(<~ 9jq o^~>) test-mytoken pc
quit
$ gsnd -dNOSAFER pc11atoken.ps
GPL Ghostscript 9.52 (2020-03-19)
Copyright (C) 2020 Artifex Software, Inc. All rights reserved.
This software is supplied under the GNU AGPLv3 and comes with NO WARRANTY:
see the file COPYING for details.
stack:
true
79
()
true
79
()
:stack
stack:
true
47
()
true
47
()
:stack
stack:
true
string
()
true
string
()
:stack
stack:
true
[
(stuff)
true
[
(stuff)
:stack
stack:
true
/litname
()
true
/litname
()
:stack
stack:
true
42.42
()
true
42.42
()
:stack
stack:
true
(aO \\string\n)
()
true
(aO \\string\n)
()
:stack
stack:
true
12
()
true
12
()
:stack
stack:
true
(\253\315\357)
()
true
(\253\315\357)
()
:stack
stack:
true
name
([delim)
true
name
([delim)
:stack
stack:
true
{a proc}
()
true
{a proc}
()
:stack
stack:
true
/
(\(str\))
true
/
(\(str\))
:stack
stack:
true
200000.0
()
true
200000.0
()
:stack
stack:
true
(Man )
()
true
(Man )
()
:stack
Back to comp.lang.postscript | Previous | Next — Previous in thread | Find similar
PS Level 1 grammar luser droog <luser.droog@gmail.com> - 2021-11-07 16:40 -0800
Re: PS Level 1 grammar luser droog <luser.droog@gmail.com> - 2021-11-08 09:49 -0800
Re: PS Level 1 grammar luser droog <luser.droog@gmail.com> - 2021-11-09 08:56 -0800
qapplaH (was Re: PS Level 1 grammar) luser droog <luser.droog@gmail.com> - 2021-11-11 15:02 -0800
csiph-web