diff options
| author | 2025-09-10 11:19:16 +0200 | |
|---|---|---|
| committer | 2025-09-10 11:19:16 +0200 | |
| commit | 45591bc221bb8268567acdaa523cbac94d31a90e (patch) | |
| tree | 4e992ea4822af8313bd6ce02a574c6e20ad690f6 /lex.h | |
| parent | 59c9eb2a0766bdb7b1c1b1a2045f5381111771e5 (diff) | |
lex: implement basic function-like macro functionality
Diffstat (limited to 'lex.h')
| -rw-r--r-- | lex.h | 28 |
1 files changed, 7 insertions, 21 deletions
@@ -17,6 +17,7 @@ enum toktag { /* single-character tokens' tag value is the character itself */ TKSTRLIT, TKPPHDRH, /* <hdr> (for #include) */ TKPPHDRQ, /* "hdr" (for #include) */ + TKPPMACARG, /* macro param in repl list */ TKEQU = '@', /* == */ TKNEQ, /* != */ TKLTE, /* <= */ @@ -49,7 +50,9 @@ enum toktag { /* single-character tokens' tag value is the character itself */ struct token { short t; /* toktag */ bool litlit; - uint len; + union { + uint len, argidx; + }; struct span span; const char *s; /* for (multi-)character tokens s & len are unused @@ -63,29 +66,12 @@ struct token { * when litlit : s points to start of token within file buffer (normal case) * len == span.sl.len (number literal appears literally in source code) * otherwise s is heap allocated buffer of len bytes + * for macro arg: + * s is like keyword/ident + * argidx is index in macro param list */ }; -struct macro { - const char *name; /* interned */ - const char **param; - struct span0 span; - uchar nparam; - bool fnlike, variadic; - struct rlist { - struct token *tk; - int n; - } rlist; -}; - -struct macrostack { - struct macrostack *link; - struct rlist *args; - struct span0 exspan; - int mac; - int idx; -}; - extern int nerror; struct lexer { struct lexer *save; |