groff
[Top][All Lists]
Advanced

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

Re: [Groff] groff data structures


From: Tadziu Hoffmann
Subject: Re: [Groff] groff data structures
Date: Wed, 30 Dec 2009 00:31:53 +0100
User-agent: Mutt/1.5.17 (2007-11-01)

> I need to have [snip] a stack data structure.

Here's a very rudimentary implementation using strings -- items
on the stack cannot contain spaces, and no error checking is
performed, but you get the idea.  If necessary, the macros
can be generalized to accept the name of the stack string as
argument (instead of it being hard-coded), so that multiple
stacks can be handled simultaneously using the same macros.

.\"
.\" ----------------------------------------------------------------
.de push
.ds stack \\$1 \\*[stack]
..
.de pop
.pop1 \\$1 \\*[stack]
..
.de pop1
.ds \\$1 \\$2
.shift 2
.ds stack \\$*
..
.\" ----------------------------------------------------------------
.sp 2c
.push foo
pushed `foo', stack now contains `\*[stack]'
.br
.push xxx
pushed `xxx', stack now contains `\*[stack]'
.br
.push hello
pushed `hello', stack now contains `\*[stack]'
.br
.pop result
popped `\*[result]', stack now contains `\*[stack]'
.br
.push world
pushed `world', stack now contains `\*[stack]'
.br
.pop result
popped `\*[result]', stack now contains `\*[stack]'
.br
.pop result
popped `\*[result]', stack now contains `\*[stack]'
.br
.pop result
popped `\*[result]', stack now contains `\*[stack]'
.br






reply via email to

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