[fpc-devel]Calling yyparse() several times fails.
Ralf Paaschen
ralf at pluto.galactic.network
Fri May 3 21:29:33 CEST 2002
Hi.
I wrote the following program to show the problem.
It uses very simple plex and pyacc modules that only try to find out if
a line of the input contais the word "hallo". The main program does the
following:
* open a file
* parse it
* print "----successful parse!----"
* reopen it
* parse it again
...
The first time parsing the file works well.
The second time works almost, but have a look yourself:
LEX: Found HALLO
YACC: Line containing Hallo found.
LEX: Found some text.
YACC: Line with some other text found.
LEX: Found HALLO
YACC: Line containing Hallo found.
---------successful parse!---------------
Reset.
LEX: Found HALLO
YACC: Line containing Hallo found.
LEX: Found some text.
YACC: Line with some other text found.
LEX: Found HALLO
YACC: Line containing Hallo found.
Runtime error 103 at 0x08053A3A
0x08053A3A
0x080480B0
0x00000000
The runtime error is 103 but the return code of the program was 0147
(shown by gdb).
I have tested version 1.0.4 and 1.0.6 of fpc under Linux on i386. Both
with the same result.
I can't say if is a fpc problem or a problem of the state machine
generated by pyacc.
I have added the following files to this mail:
* Makefile - for easier testing :-)
* yaccerror.pp - the main program
* yaccerror_lex.l - the lex file
* yaccerror_yacc.y - the yacc file
* hallofile.txt - the textfile used above
What I have done so far:
- looked through the documentation/examples of tply41a.
- written a program that opens a textfile and displays all lines several times to see if
"Reset" works. It worked.
- some sessions with DDD (frontend for gdb)
- tested fpc 1.0.4 ad 1.0.6
Thank you,
Ralf Paaschen
-------------- next part --------------
program yaccerror;
USES YaccLib, LexLib;
{$I yaccerror_yacc.pas}
{$I yaccerror_lex.pas}
(*----- variables -----------------------------------------------------------*)
var
inputFile : Ansistring;
(*----- main program --------------------------------------------------------*)
begin
(* from LexLib.pas
The variables yyinput and yyoutput are the text files which are
used by the lexical analyzer. By default, they are assigned to
standard input and output, but you may change these assignments
to fit your target application (use the Turbo Pascal standard
routines assign, reset, and rewrite for this purpose). *)
inputFile := 'hallodatei.txt';
Assign (yyinput, inputFile);
Reset(yyinput);
if yyparse=0 then writeln('---------successful parse!---------------');
(*
Assign (yyinput, inputFile);
WriteLn('Assign.');
*)
Reset(yyinput);
WriteLn('Reset.');
yyclear;
if yyparse=0 then Writeln('---------successful parse!---------------');
Reset(yyinput);
WriteLn('Reset.');
yyclear;
if yyparse=0 then Writeln('---------successful parse!---------------');
WriteLn('');
WriteLn('Programm beendet.');
Close(yyinput);
end.
-------------- next part --------------
%{
%}
%%
\n return(ZENDE);
"hallo" begin
WriteLN('LEX: Found HALLO');
return(HALLO);
end;
.* begin
WriteLN('LEX: Found some text.');
return(STUFF);
end;
%%
-------------- next part --------------
%{
%}
%start zeilen
%token HALLO STUFF ZENDE
%%
zeilen :
| zeilen zeile
;
zeile : ZENDE { WriteLn('YACC: Empty line found.'); }
| HALLO ZENDE { WriteLn('YACC: Line containing Hallo found.'); }
| STUFF ZENDE { WriteLn('YACC: Line with some other text found.'); }
;
%%
-------------- next part --------------
COMPILER=fpc -Sd -g
PYACC=pyacc
#PYACC=pyacc -d
all: yaccerror
yaccerror: yaccerror_lex.pas yaccerror_yacc.pas yaccerror.pp
$(COMPILER) yaccerror.pp
yaccerror_lex.pas: yaccerror_lex.l
plex yaccerror_lex.l
yaccerror_yacc.pas: yaccerror_yacc.y
$(PYACC) yaccerror_yacc.y
-------------- next part --------------
"zahl const without tabledata" 6 9 520 y l const
"zahl const" 6 9 520 y l const "table1" "bla"
"zahl decimal" 6 9 520 y l decimal 3 0 "table1" "bla"
"text const" 6 9 "112112" y l const "table1" "bla"
"text substring" 6 9 "gaagaa" y l substring 2 2 "table1" "bla"
"text date" 6 9 "19781031" y l date "table1" "bla"
"kommazahl const" 6 9 "781031" y l const "table1" "bla"
"kommazahl decimal" 6 9 520 y l decimal 3 0 "table1" "bla"
"kommazahl decimal range" 6 9 520 y l decimal 3 0 range 500 600 "table1" "bla"
"kommazahl decimal range" 6 9 520 y l decimal 3 0 range 500 600 "table1" "bla"
More information about the fpc-devel
mailing list