Thank you! I use yacc - 1.9 20090221 (this is shown with -V option). I
find the behaviors of *my*  ;-) yacc more convinient than bison. Bison
behaviours also cause stupid problem of  necessity of forward
declaration of the function like yylex or yyerror between %{ %} if
code is compiled with g++. IMHO It is much better to put generated
code of yyparse to the end of text... Does it conflict with POSIX?

%{
#include <cctype>
#include <iostream>
//int yylex(), yyerror(); //necessity for bison & c++
%}
%token DIGIT
%left '+'
%%
list:
| list '\n'
| list expr '\n' {cout << $2 << endl;}
;
expr: DIGIT
| expr '+' expr {$$ = $1 + $3;}
;
%%
int yylex () {
int c;
  if (isdigit(c)) {
       yylval = c - '0';
       return DIGIT;
  }
  return c;
 }

int yyerror() {}

main () {
 yyparse();
}

Reply via email to