/* 行頭の空白を除去 インデントを行なう. コメントはインデントの対象としない. */ %{ int indent_depth = 0, i; %} %x COMMENT %s BEGINNINGOFL %% "/*" {ECHO; BEGIN(COMMENT);} "*/" {ECHO; BEGIN(INITIAL);} . ECHO; \n {putchar (yytext[0]); BEGIN(BEGINNINGOFL);} { [ \t]+ [{] { for(i=indent_depth; i>0;i--){putchar(' ');putchar(' ');} ECHO; indent_depth++; BEGIN(INITIAL);} [}] { indent_depth--; for(i=indent_depth; i>0;i--){putchar(' ');putchar(' ');} ECHO; BEGIN(INITIAL);} . { for(i=indent_depth; i>0;i--){putchar(' ');putchar(' ');} ECHO; BEGIN(INITIAL);} } [{] {ECHO; indent_depth++;} [}] {ECHO; indent_depth--;} . putchar (yytext[0]); %% main(){ yylex(); }