Re: PDF grammar and PostScript grammar

David Z Maze <dmaze@mit.edu>
6 Feb 2002 23:31:13 -0500

          From comp.compilers

Related articles
PDF grammar and PostScript grammar p11111@kr.onet.pl (psobkiew) (2002-01-30)
Re: PDF grammar and PostScript grammar adamo@dblab.ece.ntua.gr (2002-02-06)
Re: PDF grammar and PostScript grammar dmaze@mit.edu (David Z Maze) (2002-02-06)
Re: PDF grammar and PostScript grammar derekn@foolabs.com (2002-02-16)
Re: PDF grammar and PostScript grammar yves.deweerdt@softhome.net (2002-02-28)
| List of all articles for this month |
From: David Z Maze <dmaze@mit.edu>
Newsgroups: comp.compilers
Date: 6 Feb 2002 23:31:13 -0500
Organization: Massachusetts Institute of Technology
References: 02-01-171
Keywords: parse
Posted-Date: 06 Feb 2002 23:31:13 EST

p11111@kr.onet.pl writes:
> I search PDF grammar and PostScript grammar.


I can't really speak to PDF, but PostScript isn't really something
that you can write a useful parser for. The language is stack-based,
and IIRC it's possible to rebind the pre-defined functions. So to
draw a one-inch line near the bottom of the page, you might do


    72 72 moveto
    72 0 rlineto
    stroke


But it would be entirely equivalent to do


    72 dup dup moveto 0 rlineto stroke


In the interest of producing "smaller" code, it seems fairly common to
define aliases for the basic keywords, to:


    /M { moveto } def
    /RL { rlineto } def
    72 72 M 72 0 RL stroke


It would make sense to write a PostScript scanner, which could emit
quoted-name, name, string, and number tokens. But you're not really
going to be able to write a grammar without essentially implementing a
full PostScript interpreter.


If you want to pursue this further, you might look at a free
PostScript interpreter; the predominant one seems to be Ghostscript
(http://www.ghostscript.com/). Older releases of Ghostscript are
available under the GPL; the current release is available under a
different license that forbids commercial redistribution.


--
David Maze dmaze@mit.edu http://www.mit.edu/~dmaze/


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.