From 3f660a9b219b03bd5188cd4f0da9a58f507a933a Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Tue, 2 Feb 2010 22:45:20 -0500 Subject: Support #ifdef and #ifndef. --- dimension/directives.rules | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'dimension/directives.rules') diff --git a/dimension/directives.rules b/dimension/directives.rules index 392408d..5a30455 100644 --- a/dimension/directives.rules +++ b/dimension/directives.rules @@ -30,6 +30,18 @@ LANGUAGE_DIRECTIVE: "#declare" "identifier" "=" RVALUE { dmnsn_local_symbol(symtable, "__cond__", cond); dmnsn_delete_astnode(cond); } + | "#ifdef" "(" "identifier" ")" { + dmnsn_astnode *node = dmnsn_find_symbol(symtable, $3); + dmnsn_local_symbol(symtable, "__cond__", + dmnsn_new_ast_integer(node ? 1 : 0)); + free($3); + } + | "#ifndef" "(" "identifier" ")" { + dmnsn_astnode *node = dmnsn_find_symbol(symtable, $3); + dmnsn_local_symbol(symtable, "__cond__", + dmnsn_new_ast_integer(node ? 0 : 1)); + free($3); + } RVALUE: ARITH_EXPR ";" %dprec 2 { $$ = dmnsn_eval($1, symtable); -- cgit v1.2.3