vaught@infonode.ingr.com (Thomas E. Vaught) (03/16/91)
Is there a way in which I can use yacc to parse a grammar one sentence, a production which makes up a sentence, at a time? Because of the potential size of the data files I am dealing with and the degree of interaction required with the parsing, I need to process a single sentence at a time. Yacc seems to reinitialize its state each time yyparse is called, thus it destroys the lookahead it obtained previously. If yacc cannot do this, is there another parser generator, which might be able to do such a thing? Thanks in advance, and any answers or commentary by email would be appreciated. Email: thom@infonode.ingr.com [If you can identify sentence ends lexically, it's pretty easy -- the yacc grammar parses a single sentence, the lexer returns a zero EOF token at the end of the sentence, and the driver keeps calling yyparse() until it sees an EOF on the input file. This is the usual way to parse Fortran and other such statement-oriented languages. Note that if you have any block structure, you have to do a lot of work yourself, since you can't embed inter-statement relationships in the grammar. The other thing to note is that if the start production is a left-recursive loop the yacc state stack is only going to be one entry deeper when parsing the whole file than it would be if you parse one sentence at a time. -John] -- Send compilers articles to compilers@iecc.cambridge.ma.us or {ima | spdcc | world}!iecc!compilers. Meta-mail to compilers-request.