ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Marco Kuhlmann <marco.kuhlmann@gmx.net>
Subject: BNF grammar
Date: Tue, 16 Oct 2001 15:27:35 +0200 (MEST)	[thread overview]
Message-ID: <9815.1003238855@www10.gmx.net> (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


             reply	other threads:[~2001-10-16 13:27 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-10-16 13:27 Marco Kuhlmann [this message]
2001-10-16 14:40 ` Berend de Boer
2001-10-16 16:24 ` Hans Hagen
2001-10-16 18:16   ` Berend de Boer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9815.1003238855@www10.gmx.net \
    --to=marco.kuhlmann@gmx.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).