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> Subject: New parser rewrite appears to be working nicely From: luser droog 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 I just spent the evening and morning writing a parser for BNF syntax.=20 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} f= orall 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 (::=3D) 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 ( ::=3D ) BNF-parse pq [Terminal transcript. 'Norah' is my laptop's name.] =1B]0;~/pcomb/ps=07 Norah@laptop ~/pcomb/ps $ gsq pc12bnf.ps Error: /undefined in alpha Operand stack: identifier Execution stack: %interp_exit .runexec2 --nostringval-- --nostringval-- --nostrin= gval-- 2 %stopped_push --nostringval-- --nostringval-- --nostring= val-- 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-- --no= stringval-- --nostringval-- 2 %stopped_push Dictionary stack: --dict:737/1123(ro)(G)-- --dict:0/20(G)-- --dict:75/200(L)-- --dic= t: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 =1B]0;~/pcomb/ps=07 Norah@laptop ~/pcomb/ps $ gsq pc12bnf.ps Error: /undefined in BNF Operand stack: BNF --nostringval-- --nostringval-- Execution stack: %interp_exit .runexec2 --nostringval-- --nostringval-- --nostrin= gval-- 2 %stopped_push --nostringval-- --nostringval-- --nostring= val-- 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-- --no= stringval-- --nostringval-- 2 %stopped_push --nostringval-- --nos= tringval-- Dictionary stack: --dict:737/1123(ro)(G)-- --dict:0/20(G)-- --dict:75/200(L)-- --dic= t: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 =1B]0;~/pcomb/ps=07 Norah@laptop ~/pcomb/ps $ gsq pc12bnf.ps Fail [[{(<) eq} (not satisfied)] [[(\n) [0 0]] {0 0 ( ::=3D \n) string-input}]] GS>=1B]0;~/pcomb/ps=07 Norah@laptop ~/pcomb/ps $ gsq pc12bnf.ps Fail [[( after ) (\n)] [[{(<) eq} (not satisfied)] [[( ) [0 0]] {0 1 ( ::=3D \n) string-input}]]] GS>=1B]0;~/pcomb/ps=07 Norah@laptop ~/pcomb/ps $ gsq pc12bnf.ps Fail [[( after ) [(<) (p)]] [[{(>) eq} (not satisfied)] [[(o) [0 4]] {0 5 (stal-= address> ::=3D \n) string-input}]]] GS>=1B]0;~/pcomb/ps=07 Norah@laptop ~/pcomb/ps $ gsq pc12bnf.ps Fail [[( after ) [(<) (p) (o) (s) (t) (a) (l) (-) (a) (d) (d) (r) (e) (s) (s) (>= ) (:) (:) (=3D)]] [[{(-) eq} (not satisfied)] [[(<) [0 23]] {0 24 (name-par= t> \n) string-input}]]] GS>=1B]0;~/pcomb/ps=07 Norah@laptop ~/pcomb/ps $ gsq pc12bnf.ps Fail [[( after ) [(<) (p) (o) (s) (t) (a) (l) (-) (a) (d) (d) (r) (e) (s) (s) (>= ) (:) (:) (=3D)]] [[{dup (A) ge exch (Z) le and} (not satisfied)] [[(<) [0 = 23]] {0 24 (name-part> \n) string-input}]]] GS>=1B]0;~/pcomb/ps=07 Norah@laptop ~/pcomb/ps $ gsq pc12bnf.ps p (o) GS>=1B]0;~/pcomb/ps=07 Norah@laptop ~/pcomb/ps $ gsq pc12bnf.ps stack: [(p) (o) (s) (t) (a) (l) (-) (a) (d) (d) (r) (e) (s) (s) (:) (:) (=3D) (n) = (a) (m) (e) (-) (p) (a) (r) (t)] =1B]0;~/pcomb/ps=07 Norah@laptop ~/pcomb/ps $ gsq pc12bnf.ps stack: [(p) (o) (s) (t) (a) (l) (-) (a) (d) (d) (r) (e) (s) (s) (:) (:) (=3D) (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)] =1B]0;~/pcomb/ps=07 Norah@laptop ~/pcomb/ps $ gsq pc12bnf.ps Error: /undefined in to-string Operand stack: --nostringval-- (<) --nostringval-- --nostringval-- Execution stack: %interp_exit .runexec2 --nostringval-- --nostringval-- --nostrin= gval-- 2 %stopped_push --nostringval-- --nostringval-- --nostring= val-- 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-- --no= stringval-- --nostringval-- 2 %stopped_push --nostringval-- --nos= tringval-- --nostringval-- --nostringval-- --nostringval-- --nostri= ngval-- --nostringval-- --nostringval-- --nostringval-- --nostringv= al-- --nostringval-- Dictionary stack: --dict:737/1123(ro)(G)-- --dict:0/20(G)-- --dict:75/200(L)-- --dic= t: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 =1B]0;~/pcomb/ps=07 Norah@laptop ~/pcomb/ps $ gsq pc12bnf.ps stack: [(postal-address) (:) (:) (=3D) (name-part) (street-address) (zip-part)] =1B]0;~/pcomb/ps=07 Norah@laptop ~/pcomb/ps $