aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaymaekers Luca <luca@spacehb.net>2025-04-27 11:26:14 +0200
committerRaymaekers Luca <luca@spacehb.net>2025-04-27 11:27:41 +0200
commit762ec93f00bb5c30f37ab1f2f9d71704e5f88eef (patch)
tree99183d644481e22f0771d3cd352aeb97c49bac93
parentc35efff9215570cb905d0ac3cd6cec274fa602a6 (diff)
added READMEmain
-rw-r--r--README.md46
-rwxr-xr-xsource/build.sh1
2 files changed, 47 insertions, 0 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..b7e684b
--- /dev/null
+++ b/README.md
@@ -0,0 +1,46 @@
+# metac: A table-driven preprocessor for C
+
+## Overview
+`metac` is my attempt at a C preprocessor that adds the features I would like C to have. It is
+inspired by Ryan Fleury's article, see resources below.
+
+### Features
+- `@table` keyword for specifying data, eg.
+```
+@table(name, str) MyEnumTable
+{
+ { A "A" }
+ { B "B" }
+ { C "C" }
+}
+```
+- `@expand` keyword for using data from a table, eg.
+```
+typedef enum
+{
+@expand(MyEnumTable t)
+` MyEnum_$a(a.name),`
+ MyEnum_Count
+} MyEnum;
+```
+
+## Build
+Run the build script.
+```sh
+./source/build.sh
+```
+
+## Try it out
+To chek the usage you can run withuot arguments.
+```
+./build/metac
+Usage: ./build/metac filename [output_filename]
+```
+Run the program on the example file.
+```sh
+./build/metac examples/table.c
+```
+Checkout the newly created `table.meta.c`. This is your metaprogram!
+
+# Resources
+- [Ryan Fleury - table-driven code generation](https://www.rfleury.com/p/table-driven-code-generation)
diff --git a/source/build.sh b/source/build.sh
index e21a173..4bce3b9 100755
--- a/source/build.sh
+++ b/source/build.sh
@@ -3,4 +3,5 @@ set -e
ScriptDir="$(dirname "$(readlink -f "$0")")"
+printf 'meta.c\n'
gcc -ggdb -o "$ScriptDir"/../build/metac "$ScriptDir"/meta.c