Skip to content

Commit

Permalink
finish condition macro
Browse files Browse the repository at this point in the history
  • Loading branch information
tutuwel committed Oct 28, 2023
1 parent 696af1f commit 9cf8d1e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions phase1/lex.l
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ id [_a-zA-Z][_0-9a-zA-Z]*
"#define" {yylval=strdup("DEFINE\n"); BEGIN(macro); return DEFINE;}
"#include" {yylval=strdup("INCLUDE\n"); BEGIN(macro); return INCLUDE;}
"#ifdef" {yylval=strdup("IFDEF\n"); BEGIN(macro); return IFDEF;}
"#else" {yylval=strdup("MACROELSE\n"); BEGIN(macro); return MACROELSE;}
"#endif" {yylval=strdup("ENDIF\n"); BEGIN(macro); return ENDIF;}
"#else" {yylval=strdup("MACROELSE\n"); return MACROELSE;}
"#endif" {yylval=strdup("ENDIF\n"); return ENDIF;}
<macro>{
"," {yylval=strdup("COMMA\n");return COMMA;}
"<" {return LT;}
Expand Down
2 changes: 1 addition & 1 deletion phase1/syntax.y
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ Stmt:

| FOR LP Exp SEMI Exp SEMI Exp RP Stmt {asprintf(&$$,"Stmt (%d)\n%s\n", @$.first_line, concat_shift($1,$2,$3,$4,$5,$6,$7,$8,$9));}
| IFDEF Stmt ENDIF {asprintf(&$$,"Stmt (%d)\n%s\n", @$.first_line, concat_shift($1,$2,$3));}
| IFDEF Stmt MACROELSE Stmt ENDIF {asprintf(&$$,"Stmt (%d)\n%s\n", @$.first_line, concat_shift($1,$2,$3,$4,$5));}
| IFDEF MACRO Stmt MACROELSE Stmt ENDIF {asprintf(&$$,"Stmt (%d)\n%s\n", @$.first_line, concat_shift($1,$2,$3,$4,$5));}



Expand Down
22 changes: 11 additions & 11 deletions phase1/test-ex/test_3.spl
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
#define MACRO_NAME1 replacement_text1
#include <header_file.h>
#include "header_file.h"
int test_1_r01(int a, int b){
c = 'c';
if (a > b)
{
return a;
}
else
{
return b;
}
}
#define DEBUG 1

int main() {
#ifdef DEBUG
printf('Debug mode is enabled.\n');
#else
printf('Debug mode is disabled.\n');
#endif

return 0;
}

0 comments on commit 9cf8d1e

Please sign in to comment.