Parsing C switch-case and for Statement in AWK -
how parse switch-case statement below awk? want create simple c syntax checker awk. checker must read code , return whether there syntax error or not. if there is, awk should print error on it.
switch(number) { case 1 : number = 'a'; break; case 2 : number = 'b'; break; default : number = 'x'; }
and for() statement, this:
for(i=0;i<10;i++) { number = 'a'; }
my current code switch-case statement was:
#parser_switchcase.awk { for(i=1; i<=nf; i++) { if($i~/switch\([[:alnum:]]+\)/) print("switch(valid_variable)") } }
result first c switch-case code above:
master@master:~/dokumen/root$ awk -f parser_switchcase.awk soalswitch switch(valid_variable)
but needs many improvements. not complete.
i need awk suggestion reading , checking code examples have typed above. exactly, need awk parsing code those, not outside possibility such additional function, additional code, mentioned on codes above. thank you.
using awk c syntax checks brave project. have fun!
i use gcc
syntax checks.try this:
gcc -fsyntax-only test.c
Comments
Post a Comment