32 lines
501 B
Plaintext
32 lines
501 B
Plaintext
<<
|
|
import test_macros;
|
|
>>
|
|
|
|
ptype int;
|
|
|
|
lex_fn mylexfn;
|
|
|
|
drop /\s+/;
|
|
token lbrace /\{/;
|
|
token rbrace /\}/;
|
|
token plus /\+/;
|
|
token macro;
|
|
token macroname /@[a-zA-Z_]\w*/;
|
|
token num /\d+/ <<
|
|
int n = 0;
|
|
foreach (c; match)
|
|
{
|
|
n *= 10;
|
|
n += (c - '0');
|
|
}
|
|
$$ = n;
|
|
>>
|
|
|
|
Start -> Statements;
|
|
Statements -> ;
|
|
Statements -> Statement Statements;
|
|
Statement -> Add;
|
|
Statement -> MacroStart;
|
|
Add -> num plus num << $$ = $1 + $3; record($$); >>
|
|
MacroStart -> macro macroname lbrace;
|