* 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
* Re: BNF grammar
2001-10-16 13:27 BNF grammar Marco Kuhlmann
@ 2001-10-16 14:40 ` Berend de Boer
2001-10-16 16:24 ` Hans Hagen
1 sibling, 0 replies; 4+ messages in thread
From: Berend de Boer @ 2001-10-16 14:40 UTC (permalink / raw)
Cc: ntg-context
Marco Kuhlmann <marco.kuhlmann@gmx.net> writes:
> I would like to define an environment "bnfgrammar" to typeset
> grammars in BNF format. What I thought is that you could type
You might want to take a look at the verb-*.tex files.
This is the preferred way to handle pretty printing. Simple look-ahead
and maintaining some state works surprisingly well.
--
Groetjes,
Berend. (-:
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: BNF grammar
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
1 sibling, 1 reply; 4+ messages in thread
From: Hans Hagen @ 2001-10-16 16:24 UTC (permalink / raw)
Cc: ntg-context
At 03:27 PM 10/16/2001 +0200, Marco Kuhlmann wrote:
>Does anyone has a neat solution to this problem? Is there
>something better than tabulate for this purpose?
as berend suggests, a pretty printing filer will probably do, but i must
admit that i forgot how bn notation works. Is it complicated?
i must also admit that i have promissed bzyl to write some framework for this.
Hans
-------------------------------------------------------------------------
Hans Hagen | PRAGMA ADE | pragma@wxs.nl
Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: +31 (0)38 477 53 69 | fax: +31 (0)38 477 53 74 | www.pragma-ade.com
-------------------------------------------------------------------------
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: BNF grammar
2001-10-16 16:24 ` Hans Hagen
@ 2001-10-16 18:16 ` Berend de Boer
0 siblings, 0 replies; 4+ messages in thread
From: Berend de Boer @ 2001-10-16 18:16 UTC (permalink / raw)
Cc: Marco Kuhlmann, ntg-context
Hans Hagen <pragma@wxs.nl> writes:
> as berend suggests, a pretty printing filer will probably do, but i
> must admit that i forgot how bn notation works. Is it complicated?
No really, easy. You just want to hightlight certain keywords like ::
or characters as (, but that's it.
It's a syntax like yacc/DTD.
--
Groetjes,
Berend. (-:
^ 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).