Skip to content

Commit

Permalink
Add clac.1
Browse files Browse the repository at this point in the history
  • Loading branch information
soveran committed Apr 17, 2017
1 parent f359a98 commit b24478a
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 109 deletions.
100 changes: 100 additions & 0 deletions clac.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
.Dd April 17, 2017
.Dt CLAC 1
.
.Sh NAME
.
.Nm clac
.Nd A command line, stack-based calculator with postfix notation

.Sh SYNOPSIS
.
.Nm
.
.Sh DESCRIPTION
.
.Nm
is a command line, stack-based calculator with postfix notation
that displays the stack contents at all times. As you type, the
stack changes are reflected immediately.
.Pp
In a stack-based postfix calculator, entering a number pushes it
on a stack, and arithmetic operations pop their arguments from the
stack and push the result. As all the operations take a fix number
of arguments, there's no room for ambiguity: parenthesis and operator
precedence are not needed. Postfix notation is also known as reverse
Polish notation, or RPN.
.
.Ss Commands
.
When a command requires an argument, it pops a value from the stack.
If the stack is empty, a zero is provided instead. In the descriptions
below, the top of the stack (and thus the first value popped) is
represented by the letter `a`, while the second value popped is
represented by the letter `b`. For example, if the stack is composed
of the number `1`, `2` and `3` (with `3` at the top of the stack),
when we describe the sum then `a` will be `3` and `b` will be `2`.
It is important to note that subtraction and division invert the
order of the arguments before performing the operation: with `1`,
`2` and `3` in the stack, when you type `-` it will pop the values
`3` and `2` and push the result of `2 - 3`. This is in the tradition
of other postfix calculators and programming languages.
.
A description of the available commands follows.
.
.Ss Arithmetic operations
.
.Bl -tag -width Fl
.It Ic +
Pop two values `a` and `b` and push the result of `a + b`.
.
.It Ic -
Pop two values `a` and `b` and push the result of `b - a`.
.
.It Ic *
Pop two values `a` and `b` and push the result of `a * b`.
.
.It Ic /
Pop two values `a` and `b` and push the result of `b / a`.
.El
.
.Ss Modulo operation
.
.Bl -tag -width Fl
.It Ic %
Pop two values `a` and `b` and push the remainder of the Euclidean
division of `b` by `a`.
.El
.
.Ss Exponentiation
.
.Bl -tag -width Fl
.It Ic ^
Pop two values `a` and `b` and push the result of `b ^ a`.
.El
.
.Ss Rounding
.
.Bl -tag -width Fl
.It Ic ceil
Pop the value `a` and push smallest integral value greater than or
equal to `a`.
.It Ic floor
Pop the value `a` and push largest integral value less than or equal
to `a`.
.It Ic round
Pop the value `a` and push integral value nearest to `a`.
.El
.
.Ss Stack manipulation
.
.Bl -tag -width Fl
.It Ic swap
Pop two values `a` and `b` and push the values `a`, `b`.
.It Ic dup
Pop the value `a` and push the values `a`, `a`.
.It Ic _
Push on the stack the result of the last operation.
.El
.
.Sh AUTHOR
.An Michel Martens Aq [email protected]
24 changes: 7 additions & 17 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
FLAGS = -I./deps/linenoise -I./deps/sds
PREFIX?=/usr/local

PANDOC=$(shell which pandoc)
MANPREFIX?=${PREFIX}/share/man

default: clac

Expand All @@ -26,22 +25,13 @@ install: clac
@cp -f clac ${PREFIX}/bin/clac
@chmod 755 ${PREFIX}/bin/clac

install-man: man
@echo installing manpage
@mkdir -p ${PREFIX}/share/man/man1/
@cp -f clac.1 ${PREFIX}/share/man/man1
@echo installing manual pages to ${MANPREFIX}/man1
@mkdir -p ${PREFIX}/bin
@cp -f clac.1 ${MANPREFIX}/man1/clac.1
@chmod 644 ${MANPREFIX}/man1/clac.1

uninstall:
@echo removing executable from ${PREFIX}/bin
@rm ${PREFIX}/bin/clac

uninstall-man: man
@echo uninstalling manpage
@rm -p ${PREFIX}/share/man/man1/clac.1

man: clac.1

clac.1: $(PANDOC)
@echo calling pandoc to generate manpage
@$(PANDOC) man/clac.md -s -t man -o clac.1

@echo removing manual pages from ${MANPREFIX}/man1
@rm ${MANPREFIX}/man1/clac.1
92 changes: 0 additions & 92 deletions man/clac.md

This file was deleted.

0 comments on commit b24478a

Please sign in to comment.