summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKai Stevenson <kai@kaistevenson.com>2023-02-21 19:06:57 -0800
committerKai Stevenson <kai@kaistevenson.com>2023-02-21 19:06:57 -0800
commit84128ce09c6c2f81fb7577fe866939d8096c9d03 (patch)
treea7bd2a3a3cfc9cc5e17f9cab9735c1a420739ddc
parenta51e3c9173b5314d7ba79033f94b82014175ab82 (diff)
added man page
-rw-r--r--Makefile8
-rw-r--r--doc/internal_functions_dictionary10
-rw-r--r--doc/precedent.181
-rw-r--r--src/eval.c2
-rw-r--r--src/precedent.c2
5 files changed, 91 insertions, 12 deletions
diff --git a/Makefile b/Makefile
index a14e3b2..192ebc7 100644
--- a/Makefile
+++ b/Makefile
@@ -3,9 +3,17 @@ CFLAGS+= -Wshadow -Wstrict-prototypes -Wundef -Wpointer-arith
CFLAGS+= -Wunreachable-code -Wswitch-enum -Wformat=2 -g
PREFIX ?= /usr
BINDIR ?= ${PREFIX}/bin
+MANDIR = ${PREFIX}/share/man
generate:
$(CC) -o precedent src/precedent.c src/hashtable.c src/parse.c src/eval.c $(CFLAGS)
+install: precedent
+ install -d ${DESTDIR}${BINDIR} ${DESTDIR}${MANDIR}/man1
+ install precedent ${DESTDIR}${BINDIR}
+ install -m 644 doc/precedent.1 ${DESTDIR}${MANDIR}/man1
clean:
rm precedent
+
+uninstall:
+ -rm -f ${DESTDIR}${BINDIR}/precedent ${DESTDIR}${MANDIR}/man1/precedent.1
diff --git a/doc/internal_functions_dictionary b/doc/internal_functions_dictionary
deleted file mode 100644
index 5238098..0000000
--- a/doc/internal_functions_dictionary
+++ /dev/null
@@ -1,10 +0,0 @@
-root() -- executes all arguments. returns the eval of the last symbol
-ref() -- returns its argument without evaluating it
-eval() -- evaluates its first argument, passing the rest of its arguments into the eval of its first argument
-store() -- stores a pointer to the first argument under the name specified by the eval of the second argument, within the local scope
-update() -- same as store(), but tries to overwrite the value of an already stored key - if the current scope doesn't contain the key, checks upwards. if no scope contains the key, update() does nothing
-eq() -- returns 1 if the eval of all the arguments is the same, 0 if different. accepts any number of arguments
-if() -- if the eval of the first argument is 1, executes all the other arguments
-not() -- if the eval of the first argument is 1, returns 0, and vice versa
-sum() -- returns the sum of the eval of all the arguments
-print() -- prints the eval of the first argument to the console, and a newline character
diff --git a/doc/precedent.1 b/doc/precedent.1
new file mode 100644
index 0000000..6f7a9c4
--- /dev/null
+++ b/doc/precedent.1
@@ -0,0 +1,81 @@
+.TH PRECEDENT 1 "23 Feb 21" "Precedent version 0.1"
+.SH NAME
+precedent \- simple interpreted language
+
+.SH SYNOPSIS
+\fBprecedent\fP <file> [--visualize] [--debug] [--version] [--help]
+
+.SH DESCRIPTION
+Precedent is an interpreted language. The syntax is extremely simple,
+which lends to a writing in a functional paradigm. However, precedent also
+supports imperative programming, with variable scoping and side-effects.
+Precedent supports integers, floats, and strings, with basic functions
+to manipulate each. Precedent has a simple pre-processor supporting
+include statements, so libraries may be written to re-use code.
+
+.SH DICHOTOMY
+Everything in precedent is a symbol. Every symbol is either a key or literal.
+A literal may be an integer, a float, or a string, and is self-evaluating.
+A key exists in some scope, and points to some symbol. There are default ("internal")
+keys, and keys created with store(). A key may accept parameters, making it a function.
+
+.SH SYNTAX
+Spaces, tabs, newlines, and other forms of whitespace are ignored.
+A literal value is defined by its termination with a semicolon. The following
+are examples of literal values: [ 123; hello world; 9.81; ]. A key is defined by its
+termination with a pair of parentheses. The following are examples of key references:
+[ myVar() arg0() ]. A key reference may have any number of arguments, which may be
+literals or key references. The following are examples of key references with arguments:
+[ print(hello world;) print(myVar()) print(eq(1; 2;)) ].
+
+.SH FUNCTIONS
+\fBroot() OR ()\fP
+\-\- Executes all arguments. Returns the evaluation of the last symbol. Used to define a function.
+
+\fBref()\fP
+\-\- Returns a pointer to its first argument, not evaluating it.
+
+\fBeval()\fP
+\-\- Evaluates its first argument, passing the the rest of its arguments as arg0, arg1... etc. Essentially undoes ref().
+
+\fBstore()\fP
+\-\- Stores the evaluation of its first argument under the name specified by the (string) evaluation of its second argument. Use with ref() to store functions, or without to store variables.
+
+\fBupdate()\fP
+\-\- Stores the evaluation of its first argument under the name specified by the (string) evaluation of its second argument, in the same manner as store(). Update() differs from store when the key is not found in the local scope. In this case, update() searches upwards for the first scope containing the key, and overwrites its value.
+
+\fBeq()\fP
+\-\- Evaluates all of its arguments. If they are all equivalent, returns 1. Otherwise, returns 0.
+
+\fBif()\fP
+\-\- If its first argument is not 0, evaluates the rest of its arguments. Does not return a value.
+
+\fBnot()\fP
+\-\- If its first argument is 0, returns 1. Otherwise, returns 0.
+
+\fBsum()\fP
+\-\- Evaluates all its arguments. Returns the sum.
+
+\fBprint()\fP
+\-\- Evaluates its first argument and prints it to the terminal.
+
+.SS Options
+\fB--help\fP
+\-\- Displays usage info.
+
+\fB--version\fP
+\-\- Displays version info, and license information.
+
+\fB--visualize\fP
+\-\- Displays the the program structure before execution.
+
+\fB--debug\fP
+\-\- Writes additional debug information.
+
+.SH AUTHOR
+Developed and maintained by Kai Stevenson
+See https://www.aberrantflux.xyz/cgit/precedent.git for the latest version
+of the software.
+
+.SH "SEE ALSO"
+c(7)
diff --git a/src/eval.c b/src/eval.c
index 4468e6b..0b28ef4 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -11,7 +11,7 @@ sym_t* eval(sym_t* symbol, hashtable_t* parentScope) {
return init_sym_int(*((int*)symbol->name));
}
else if (symbol->litType == FLOAT) {
- return init_sym_float*((float*)symbol->name);
+ return init_sym_float(*((float*)symbol->name));
}
else if (symbol->litType == STRING) {
return init_sym_str((char*)symbol->name);
diff --git a/src/precedent.c b/src/precedent.c
index 5b60e3d..a2791ac 100644
--- a/src/precedent.c
+++ b/src/precedent.c
@@ -22,7 +22,7 @@ int main(int argc, char** argv) {
return 0;
}
else if (strcmp("--help", argv[i]) == 0) {
- printf("usage: precedent <file> [--visualize] [--version] [--help]\n");
+ printf("usage: precedent <file> [--visualize] [--debug] [--version] [--help]\n");
return 0;
}
else if (strcmp("--visualize", argv[i]) == 0) {