groff
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Groff] GNU pic grammar


From: Werner LEMBERG
Subject: [Groff] GNU pic grammar
Date: Sun, 05 May 2002 23:51:35 +0200 (CEST)

My work over the weekend was to extract a complete and exact GNU
grammar.  Enjoy!  Compared to Raymond's pic.ms paper there are a lot
of differences; especially the `with' rules are much more complex.

I'll try to make the `with' rules more compatible with AT&T pic in
the next days.


    Werner


======================================================================

This is the grammar of GNU pic (2002-05-05).

terminals:
  INT             # A positive integer.
  NUMBER          # A floating point number, followed by optionally
                  # by `i' or `I' (which is ignored).
  LABEL           # A string starting with [A-Z], optionally followed
                  # by one or more characters of the set [a-zA-Z0-9_].
  VARIABLE        # A string starting with [a-z], optionally followed
                  # by one or more characters of the set [a-zA-Z0-9_].
  TEXT            # A string enclosed in double quotes.  Instead of
                  # TEXT you can use `sprintf ( TEXT [, <expr> ...] )',
                  # except after the `until' and `last' keywords and
                  # after all ordinal keywords (`th' and friends).
  COMMAND-LINE    # A line starting with a command character
                  # (`.' in groff mode, `\' in TeX mode).
  BALANCED-TEXT   # Text either enclosed with `{' and `}' or with
                  # `X' and `X', where `X' doesn't occur in the text.
  BALANCED-BODY   # Delimiters as in BALANCED-TEXT; the body will
                  # be interpreted as `<command> ...'.
  FILENAME        # Name of a file (TEXT).
  MACRONAME       # Name of a macro (TEXT).


<top> ::=
  <command> ;
  <command> \n

<command> ::=
  <primitive> [<attribute>]
  LABEL : [;] <command>
  LABEL : [;] <command> [<position>]
  { <command> ... }
  VARIABLE [:]= <any-expr>
  up | down | left | right
  COMMAND-LINE
  command <print-arg> ...
  print <print-arg> ...
  sh BALANCED-TEXT
  copy FILENAME
  copy [FILENAME] thru MACRONAME [until TEXT]
  for VARIABLE = <expr> to <expr> [by [*] <expr>] do BALANCED-BODY
  if <any-expr> then BALANCED-BODY [else BALANCED-BODY]
  reset [VARIABLE [,] ...]

<primitive> ::=
  box
  circle
  ellipse
  arc
  line
  arrow
  move
  spline
  TEXT
  plot <expr> [TEXT]
  '[' <command> ... ']'

<attribute> ::=
  h[eigh]t <expr>
  rad[ius] <expr>
  wid[th] <expr>
  diam[eter] <expr>
  up [<expr>]
  down [<expr>]
  right [<expr>]
  left [<expr>]
  from <position>
  to <position>
  at <position>
  with <path>
  by <expr-pair>
  then
  solid
  dotted [<expr>]
  dashed [<expr>]
  fill[ed] [<expr>]
  shaded TEXT
  colo[u]r[ed] TEXT
  outline[d] TEXT
  chop [<expr>]
  same
  invis[ible]
  '<-' | '->' | '<->'
  cw | ccw
  ljust | rjust | above | below
  thick[ness] <expr>
  aligned
  TEXT
  <expr>
  
<print-arg> ::=
  TEXT
  <expr>
  <position>

<any-expr> ::=
  <expr>
  <text-expr>
  <any-expr> <logical-op> <any-expr>
  ! <any-expr>

<logical-op> ::=
  == | != | && | '||'

<expr> ::=
  VARIABLE
  NUMBER
  <place> <place-attribute>
  <expr> <op> <expr>
  - <expr>
  ( <any-expr> )
  ! <expr>
  <func1> ( <any-expr> )
  <func2> ( <any-expr> , <any-expr> )
  rand ( )

<place-attribute>
 .x | .y | .h[eigh]t | .wid[th] | .rad

<op> ::=
  + | - | * | / | % | ^ | '<' | '>' | '<=' | '>='

<func1> ::=
  sin | cos | log | exp | sqrt | int | rand | srand

<func2> ::=
  atan2 | max | min

<text-expr> ::=
  TEXT == TEXT
  TEXT != TEXT

<position> ::=
  <place>
  <expr-pair>
  <position> + <expr-pair>
  <position> - <expr-pair>
  ( <position> , <position> )
  <expr> [of the way] between <position> and <position>
  <expr> '<' <position> , <position> '>'

<expr-pair> ::=
  <expr> , <expr>
  ( expr-pair )

<place> ::=
  <label>
  <label> <corner>
  <corner> [of] <label>
  here

<label> ::=
  LABEL [. LABEL ...]
  <nth-primitive>

<path> ::=
  <relative-path>
  ( <relative-path> , <relative-path> )

<relative-path> ::=
  <corner>
  . LABEL [. LABEL ...] [<corner>]

<corner> ::=
  .n | .e | .w | .s
  .ne | .se | .nw | .sw
  .c[enter] | .start | .end
  .t[op] | .b[ot[tom]] | .l[eft] | .r[ight]
  left | right | <top-of> | <bottom-of>
  <center-of> | <start-of> | <end-of>
  upper left | lower left | upper right | lower right
  upper <left-of> | lower <left-of> | upper <right-of> | lower <right-of>

<xxx-of> ::=
  xxx     # followed by `of'

<nth-primitive> ::=
  <ordinal> <object-type>
  [<ordinal> last <object-type>

<ordinal> ::=
  INT th
  INT st | INT nd | INT rd
  ` <any-expr> 'th

<object-type> ::=
  box
  circle
  ellipse
  arc
  line
  arrow
  spline
  '[]'
  TEXT

reply via email to

[Prev in Thread] Current Thread [Next in Thread]