help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Visual C++


From: Stark Mathews
Subject: Visual C++
Date: Thu, 25 Oct 2001 11:52:59 -0400

Okay. To start, I am using a Win32 port of Bison, which when run with
the --version flag returns

GNU Bison version 1.24

For simplicity's sake I have made a small test program, which is very
similar to the Infix Notation Calculator example in the bison.texinfo file.
Here is the original file before it is parsed. Is it possible to find my
error from this?

                                                Thank you for your time.

/*BEGIN BISON PARSER SECTION */

%{
  #define YYSTYPE int

  #include <math.h>
%}

%token NUM
%left '+' '-'
%left '*' '/'
%left NEGATE
%right '^'

%%
exp: NUM                                { $$ = $1; };
exp: exp '+' exp            { $$ = $1 + $3; };
exp: exp '-' exp                  { $$ = $1 - $3; };
exp: exp '*' exp                              { $$ = $1 * $3; };
exp: exp '/' exp                              { $$ = $1 / $3; };
exp: '-' exp %prec NEGATE   { $$ = -$1; };
exp: exp '^' exp            { $$ = pow($1, $3); };
%%

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <MALLOC.h>
#include <ctype.h>
#include <conio.h>

yylex(){
  char result;

  while (result == ' ' || result == '\t') result = getch();

  if (isdigit(result)){
    ungetch(result);
    scanf("%d", &yylval);
    return NUM;
  }

  if (result == '^') return 0;

  return result;
};

void yyerror(char *error){
  printf(error);
};


/*END BISON PARSER SECTION*/

void main(void){
  yyparse();
};




reply via email to

[Prev in Thread] Current Thread [Next in Thread]