]> git.sur5r.net Git - cc65/blobdiff - test/ref/yacc.c
Merge pull request #381 from pfusik/static-forward-decl
[cc65] / test / ref / yacc.c
index 3baefd348d50c0f7d730b0f028b80514747a2886..ab72e24c0881e48868e4d35c6160464b6ae7e3d0 100644 (file)
@@ -6,6 +6,8 @@
 
 /*#define STANDALONE*/
 
+#include "common.h"
+
 #ifndef YACCDBG
 
 #include <stdio.h>
@@ -19,6 +21,9 @@
 
 #endif
 
+FILE *infile, *outfile;
+#define getchar() fgetc(infile)
+
 /* hack the original tables to work with both petscii and ascii */
 #define CHARSETHACK
 
@@ -61,7 +66,6 @@ int yymorfg;
 extern char *yysptr, yysbuf[];
 int yytchar;
 
-/*FILE *yyin ={stdin}, *yyout ={stdout};*/
 #define yyin  infile
 #define yyout outfile
 
@@ -558,13 +562,13 @@ yylook()
                }
 
 # ifdef LEXDEBUG
-               if((*(lsp-1)-yysvec-1)<0)
+               if (lsp == yylstate)
                {
                        fprintf(yyout,"yylook:  stopped (end)\n");
                }
                else
                {
-                       fprintf(yyout,"yylook:  stopped at %d with\n",*(lsp-1)-yysvec-1);
+                       fprintf(yyout,"yylook:  stopped at %d with:\n",*(lsp-1)-(yysvec+1));
                }
 # endif
                while (lsp-- > yylstate)
@@ -590,7 +594,7 @@ yylook()
                                yyleng = yylastch-yytext+1;
                                yytext[yyleng] = 0;
 # ifdef LEXDEBUG
-                               fprintf(yyout,"\nyylook:  match action %d\n",*yyfnd);
+                               fprintf(yyout,"yylook:  match action %d\n",*yyfnd);
                                fprintf(yyout,"yylook:  done loops: %d\n",testbreak);
 # endif
                                return(*yyfnd++);
@@ -665,7 +669,13 @@ yyunput(c)
 main() 
 {
         printf("main start\n");
+        infile = fopen("yacc.in","rb");
+        if (infile == NULL) {
+            return EXIT_FAILURE;
+        }
+        outfile = stdout;
         yyparse();
+        fclose(infile);
         printf("main end\n");
         return 0;
 }