Question

I have a single Bison parser definition to apply to several streams. Each stream is produced in chunks at certain intervals, thus I would like to save the state of a given parsing instance, in order to switch among different streams, while keeping the state (with their associated stacks) of each of parsing instance.

I know there is the possibility to switch among several buffers from the scanner, but this does not help me with building a different parsing tree for each stream I am analyzing.

Is there any Bison functionality which allows to perform what function yy_switch_to_buffer() does in flex?

Was it helpful?

Solution

I think you are looking for the pure (reentrant) parser interface, which allows you to maintain separate parser states. You'll probably also want to use a reentrant flex lexer, so that each parser state has its own lexer state. (You could use a single lexer and switch buffers every time you call it, but the reentrant lexer interface is a lot cleaner, and more general since it preserves all lexer state including, for example, start condition and buffer stacks.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top