diff options
author | Raymaekers Luca <luca@spacehb.net> | 2025-03-19 14:00:00 +0100 |
---|---|---|
committer | Raymaekers Luca <luca@spacehb.net> | 2025-03-19 14:00:00 +0100 |
commit | 0f209a7807ddac50b6a020d16e3a1ef591488b88 (patch) | |
tree | 99183d644481e22f0771d3cd352aeb97c49bac93 | |
parent | c6250781ce505cd66e1c4df2740325ebcadaf0f9 (diff) |
added READMEmain
-rw-r--r-- | README.md | 46 | ||||
-rwxr-xr-x | source/build.sh | 1 |
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 |