Parsing single sentences with yacc

vaught@infonode.ingr.com (Thomas E. Vaught)
Fri, 15 Mar 91 16:45:57 GMT

          From comp.compilers

Related articles
Parsing single sentences with yacc vaught@infonode.ingr.com (1991-03-15)
| List of all articles for this month |
Newsgroups: comp.compilers
From: vaught@infonode.ingr.com (Thomas E. Vaught)
Keywords: yacc, question
Organization: Intergraph Corp. Huntsville, AL
Date: Fri, 15 Mar 91 16:45:57 GMT

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]
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.