//This code works with yacc but it doesn't work with bison -y. :-(
//The problem is TAB---the compiler doesn't see it at the code of
y.tab.c produced by bison

%token DIGIT
%left '+'
%%
list:
| list '\n'
| list expr '\n' {printf("%c%d\n", TAB, $2);}
;
expr: DIGIT
| expr '+' expr {$$ = $1 + $3;}
;
%%
#define TAB '\t'

int yylex () {
  int c;
  while ((c = getchar()) == ' ' || c == TAB);
  if (isdigit(c)) {
       yylval = c - '0';
       return DIGIT;
  }
  return c;
}

int yyerror() {}

main () {
  yyparse();
}

Reply via email to