:>
:> In other words, can I create multi-instances of parsers by using yacc?
:>

Yes. If you've already decided to use lex/yacc or flex/bison you can
create multiple instances of a scanner or parser ((without the need to
know about the scanner/parser specific internal mechanisms of these
tools, only C++ issues)).

What should be done for a scanner or parser is the following:

(1) Look at the global variables in the _generated_ *.c output files
that have to be unique for (multiple) parallel running instances
of a scanner or parser, i.e. variables that need to be local to a new
C++ scanner/parser class.

(2) Write a very simple (f)lex script that removes these variable
definitions from the generated *.c files automatically and put these
variable definitions in a new Scanner/Parser class (header file).

(3) Also, let this script remove the type declarations from the
generated *.c files. These type declarations should be added to the
corresponding new Scanner/Parser class.

(4) Some global arrays (in the lex/yacc case) should be declared
static by this script.

The lex/yacc versions require a bit more work than the flex/bison
versions.

I've used lex/yacc in the past. Currently, flex/bison. This simple
approach works well for both scanner/parser combinations.

The (f)lex script for turning the Bison output automatically into a
re-usable file is something like this:

The corresponding script to turn flex output automatically into a
re-usable class that can run in parallel with other scanners requires
more cut/paste work.

This approach allows you to have multiple scanner/parser combinations
for a single language system as well as for multiple language systems
to run concurrently within a single program context.

To give you an idea of a possible Parser class, I've appended a _sketch_
of a Parser class definition.

In a real program you probably want to have 4 classes: 1 class for the
aspects that are 100 percent related to the (yacc/bison) parser, 1 for
the (lex/flex) scanner, 1 for application specific parser issues, and 1
for application specific scanner issues. The inheritance scheme is in
this case like: