ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* BNF grammar
@ 2001-10-16 13:27 Marco Kuhlmann
  2001-10-16 14:40 ` Berend de Boer
  2001-10-16 16:24 ` Hans Hagen
  0 siblings, 2 replies; 4+ messages in thread
From: Marco Kuhlmann @ 2001-10-16 13:27 UTC (permalink / raw)


    Hi all!

I would like to define an environment "bnfgrammar" to typeset
grammars in BNF format. What I thought is that you could type

    \startbnfgrammar
      t \BNFis x\in X           \BNFcomment{(variable)}
        \BNFor f(t_1,\dots,t_n) \BNFcomment{(function term)}
    \stopbnfgrammar

and get a properly formatted grammar:

    t ::= x\in X                (variable)
       |  f(t_1,\dots,t_n)      (function term)

My first try was to use a self-defined tabulate environment:

\definetabulate
  [bnfgrammar]
  [|lm|cm|lm|]

\setuptabulate
  [bnfgrammar]
  [inner=\@bnfgrammarsetup]

\def\@bnfgrammarsetup{%
  \def\BNFdf{\NC}
  \def\BNFis{\NC \mathrel{:=} \NC}
  \def\BNFor{\NC \NR \NC \NC \mathrel{|} \NC}}

This got me quite far, as I can now type:

  \startbnfgrammar
    \BNFdf t
    \BNFis x\in X
    \BNFor f(t_1,\dots,t_n)
  \stopbnfgrammar

However, the following problems remain:

1. Pagebreaks should not be allowed in the grammar. (Is there an
   equivalent to the samepage environment for LaTeX?)

2. I would like to get rid of the \BNFdf command. Unfortunately,
   I was not able to write something like

   \def\startbnfgrammar{%
     \start@bnfgrammar \NC}

   with @bnfgrammar being bnfgrammar from above. I guess this has
   to do with that the tabulation scans in everything until the
   next \stoptabulate command and gets confused.

3. How should I implement the \BNFcomment command? I want the
   comment to be placed in a \hbox of a given width, which then
   should be aligned on the right text margin. Normally, I would
   just use \hfill to flush that box to the right, but this does
   not work with tabulate, as all the widths are calculated on
   demand.

Does anyone has a neat solution to this problem? Is there
something better than tabulate for this purpose?

    Cheers,
    Marco

-- 
GMX - Die Kommunikationsplattform im Internet.
http://www.gmx.net


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2001-10-16 18:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-10-16 13:27 BNF grammar Marco Kuhlmann
2001-10-16 14:40 ` Berend de Boer
2001-10-16 16:24 ` Hans Hagen
2001-10-16 18:16   ` Berend de Boer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).