Reputation: 53
I'm writing a postscript grammar, then use Antlr4 to parse .ps file. I don't find any grammar file for postscript. Does anyone have the grammar file for postscript? Thanks!
Upvotes: 0
Views: 240
Reputation: 19504
The only part of the language that needs a grammar is the {
... }
construct. The rest can be handled by regular expressions, and in many cases the executable arrays can be implemented with extra recursion or looping patched onto a framework that is 99% regular expressions.
The description of the language is a relatively short part of the PLRM (at least the important first few sections). In brief,
{}[]()<>/
) characters.[
yields an executable name]
yields an executable name(
begins a string which may contain balanced parens and escapes<
begins a hex string (or ASCII85 string if the next character is ~
)/
introduces the following token as a literal name{
accumulate tokens until matching }
and create an executable array. The sequence of tokens may contain balanced {
and }
pairs which construct subarraysUpvotes: 2