Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.postscript > #3764
| X-Received | by 2002:ac8:7d8e:0:b0:2f9:3bd1:9d6c with SMTP id c14-20020ac87d8e000000b002f93bd19d6cmr30472124qtd.186.1653932601964; Mon, 30 May 2022 10:43:21 -0700 (PDT) |
|---|---|
| X-Received | by 2002:a9d:6456:0:b0:60b:1c99:bd6a with SMTP id m22-20020a9d6456000000b0060b1c99bd6amr13760489otl.384.1653932601664; Mon, 30 May 2022 10:43:21 -0700 (PDT) |
| Path | csiph.com!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail |
| Newsgroups | comp.lang.postscript |
| Date | Mon, 30 May 2022 10:43:21 -0700 (PDT) |
| Injection-Info | google-groups.googlegroups.com; posting-host=24.207.219.108; posting-account=G1KGwgkAAAAyw4z0LxHH0fja6wAbo7Cz |
| NNTP-Posting-Host | 24.207.219.108 |
| User-Agent | G2/1.0 |
| MIME-Version | 1.0 |
| Message-ID | <9d5d534f-3e2b-41bb-adf5-e4835a61d3f2n@googlegroups.com> (permalink) |
| Subject | New parser rewrite appears to be working nicely |
| From | luser droog <luser.droog@gmail.com> |
| Injection-Date | Mon, 30 May 2022 17:43:21 +0000 |
| Content-Type | text/plain; charset="UTF-8" |
| Content-Transfer-Encoding | quoted-printable |
| Xref | csiph.com comp.lang.postscript:3764 |
Show key headers only | View raw
I just spent the evening and morning writing a parser for BNF syntax.
Pretty meager stuff, I know. But the debugging effort went rather
smoothly thanks to the introduction of error message support.
Even the bare-bones error messages told me which production was
failing.
(pc12.ps)run
/to-string{ dup type /stringtype ne {
dup length string exch 0 exch {3 copy putinterval length add} forall pop } if }
def
/space ( \n) anyof def
/space? //space many def
/alpha (a)(z) range (A)(Z) range alt def
/identifier (-) char //alpha alt some
{to-string} using
def
/terminal (") char (") noneof many
xthen (") char thenx def
/non-terminal (<) char //identifier
xthen (>) char thenx def
/Symbol //non-terminal def
/Expression //terminal //non-terminal alt //space? thenx some def
/BNF //space? //Symbol xthen //space? thenx
(::=) str then //space? thenx
//Expression then //space? thenx
def
/BNF-parse {
0 0 3 2 roll string-input BNF
dup first /OK eq { second first } if
} def
(
<postal-address> ::= <name-part> <street-address> <zip-part>
) BNF-parse
pq
[Terminal transcript. 'Norah' is my laptop's name.]
]0;~/pcomb/ps
Norah@laptop ~/pcomb/ps
$ gsq pc12bnf.ps
Error: /undefined in alpha
Operand stack:
identifier
Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push 1990 1 3 %oparray_pop 1989 1 3 %oparray_pop 1977 1 3 %oparray_pop 1833 1 3 %oparray_pop --nostringval-- %errorexec_pop .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push
Dictionary stack:
--dict:737/1123(ro)(G)-- --dict:0/20(G)-- --dict:75/200(L)-- --dict:37/58(L)-- --dict:2/2(L)-- --dict:62/120(L)--
Current allocation mode is local
GPL Ghostscript 9.54.0: Unrecoverable error, exit code 1
]0;~/pcomb/ps
Norah@laptop ~/pcomb/ps
$ gsq pc12bnf.ps
Error: /undefined in BNF
Operand stack:
BNF --nostringval-- --nostringval--
Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push 1990 1 3 %oparray_pop 1989 1 3 %oparray_pop 1977 1 3 %oparray_pop 1833 1 3 %oparray_pop --nostringval-- %errorexec_pop .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval--
Dictionary stack:
--dict:737/1123(ro)(G)-- --dict:0/20(G)-- --dict:75/200(L)-- --dict:37/58(L)-- --dict:2/2(L)-- --dict:69/120(L)--
Current allocation mode is local
Current file position is 611
GPL Ghostscript 9.54.0: Unrecoverable error, exit code 1
]0;~/pcomb/ps
Norah@laptop ~/pcomb/ps
$ gsq pc12bnf.ps
Fail
[[{(<) eq} (not satisfied)] [[(\n) [0 0]] {0 0 ( <postal-address> ::= <name-part> <street-address> <zip-part>\n) string-input}]]
GS>]0;~/pcomb/ps
Norah@laptop ~/pcomb/ps
$ gsq pc12bnf.ps
Fail
[[( after ) (\n)] [[{(<) eq} (not satisfied)] [[( ) [0 0]] {0 1 ( <postal-address> ::= <name-part> <street-address> <zip-part>\n) string-input}]]]
GS>]0;~/pcomb/ps
Norah@laptop ~/pcomb/ps
$ gsq pc12bnf.ps
Fail
[[( after ) [(<) (p)]] [[{(>) eq} (not satisfied)] [[(o) [0 4]] {0 5 (stal-address> ::= <name-part> <street-address> <zip-part>\n) string-input}]]]
GS>]0;~/pcomb/ps
Norah@laptop ~/pcomb/ps
$ gsq pc12bnf.ps
Fail
[[( after ) [(<) (p) (o) (s) (t) (a) (l) (-) (a) (d) (d) (r) (e) (s) (s) (>) (:) (:) (=)]] [[{(-) eq} (not satisfied)] [[(<) [0 23]] {0 24 (name-part> <street-address> <zip-part>\n) string-input}]]]
GS>]0;~/pcomb/ps
Norah@laptop ~/pcomb/ps
$ gsq pc12bnf.ps
Fail
[[( after ) [(<) (p) (o) (s) (t) (a) (l) (-) (a) (d) (d) (r) (e) (s) (s) (>) (:) (:) (=)]] [[{dup (A) ge exch (Z) le and} (not satisfied)] [[(<) [0 23]] {0 24 (name-part> <street-address> <zip-part>\n) string-input}]]]
GS>]0;~/pcomb/ps
Norah@laptop ~/pcomb/ps
$ gsq pc12bnf.ps
p
(o)
GS>]0;~/pcomb/ps
Norah@laptop ~/pcomb/ps
$ gsq pc12bnf.ps
stack:
[(p) (o) (s) (t) (a) (l) (-) (a) (d) (d) (r) (e) (s) (s) (:) (:) (=) (n) (a) (m) (e) (-) (p) (a) (r) (t)]
]0;~/pcomb/ps
Norah@laptop ~/pcomb/ps
$ gsq pc12bnf.ps
stack:
[(p) (o) (s) (t) (a) (l) (-) (a) (d) (d) (r) (e) (s) (s) (:) (:) (=) (n) (a) (m) (e) (-) (p) (a) (r) (t) (s) (t) (r) (e) (e) (t) (-) (a) (d) (d) (r) (e) (s) (s) (z) (i) (p) (-) (p) (a) (r) (t)]
]0;~/pcomb/ps
Norah@laptop ~/pcomb/ps
$ gsq pc12bnf.ps
Error: /undefined in to-string
Operand stack:
--nostringval-- (<) --nostringval-- --nostringval--
Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push 1990 1 3 %oparray_pop 1989 1 3 %oparray_pop 1977 1 3 %oparray_pop 1833 1 3 %oparray_pop --nostringval-- %errorexec_pop .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- --nostringval-- --nostringval-- --nostringval-- --nostringval-- --nostringval-- --nostringval-- --nostringval-- --nostringval--
Dictionary stack:
--dict:737/1123(ro)(G)-- --dict:0/20(G)-- --dict:75/200(L)-- --dict:37/58(L)-- --dict:2/2(L)-- --dict:70/120(L)--
Current allocation mode is local
Current file position is 779
GPL Ghostscript 9.54.0: Unrecoverable error, exit code 1
]0;~/pcomb/ps
Norah@laptop ~/pcomb/ps
$ gsq pc12bnf.ps
stack:
[(postal-address) (:) (:) (=) (name-part) (street-address) (zip-part)]
]0;~/pcomb/ps
Norah@laptop ~/pcomb/ps
$
Back to comp.lang.postscript | Previous | Next — Next in thread | Find similar
New parser rewrite appears to be working nicely luser droog <luser.droog@gmail.com> - 2022-05-30 10:43 -0700 Re: New parser rewrite appears to be working nicely luser droog <luser.droog@gmail.com> - 2022-06-03 19:11 -0700
csiph-web