Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cospplredman/PPLISP
c-prepocessor lisp
https://github.com/cospplredman/PPLISP
Last synced: 21 days ago
JSON representation
c-prepocessor lisp
- Host: GitHub
- URL: https://github.com/cospplredman/PPLISP
- Owner: cospplredman
- License: mit
- Created: 2023-11-05T20:28:34.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2023-11-05T22:20:03.000Z (about 1 year ago)
- Last Synced: 2024-02-17T10:36:23.022Z (10 months ago)
- Language: C
- Size: 11.7 KB
- Stars: 13
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-c-preprocessor - `cospplredman/PPLISP` - - A set of 45 macros that allow for lisp-like preprocessor meta programming. (Compilers/Interpreters)
README
# PPLISP
this is a set of 45 macros that allow for lisp-like preprocessor meta programming.# USAGE
to use PPLISP in your project just include PPLISP.h
```c
#include "PPLISP.h"
```
including PPLISP.h a second time will undefine all of the PPLISP macros.to evaluate a PPLISP:TM: expression use the following
```c
EXP( EVAL ( /*expr*/ ) )
```
the `EXP` macro applies 3^10 or so scans of the preprocessor and the `EVAL` macro does all of the hard work of figuring out what your expression means.## expressions
a pplisp expression has the following format
`(MACRO, EXPR1, EXPR2, ..., EXPRN)`
the result of evaluating EXPR1, ..., EXPRN are passed to MACRO as ARG1, ... ARGN## primitives
the following macros are defined for use as PPLISP primitives
- QUOTE ($)
evaluates to the list of its unevaluated argumentsthe $ macro appends QUOTE to the front of its argument list
EX: $(a, b, c) => (QUOTE, a, b, c)- CONCAT
concatenates arrays passed to ARG1 and ARG2 and returns the result- IF
if ARG1 evaluates to (T)
then return the result of evaluating ARG2if ARG2 evaluates to (F)
then return the result of evaluting ARG3- FST
returns the first element of the list passed to ARG1- RST
returns all but the first of the elements passed to ARG2- IS_NIL
if the list passed to ARG1 is empty evaluates to (T) otherwise it evaluates to (F)## defining additional PPLISP primitives
to define additional primitives simply make a macro like so
```c
#define M_MACRONAME MACRONAME
#define MACRONAME(ARG1, ARG2, ..., ARGN)EVAL( /*expr*/ )
```
recursive primitives are totally allowed, feel free to experiment!## examples
here is an example of a NOT macro
```c
#define M_NOT NOT/* the trailing \ tells the preprocessor to delete the newline allowing for multiline macro definitions*/
#define NOT(a) EVAL\
((IF,$ a,\
$(F),\
$(T)))/*without the $() EVAL will attempt to evaluate T or F which doesn't make any sense*/
EXP(
EVAL(
(NOT, $(T)) /*evaluates to (F)*/
)
EVAL(
(NOT, $(F)) /*evaluates to (T)*/)
)
)
```