Yacc/Lex: multiple uses in the same program?

Dave Jones djones at megatest.UUCP
Tue Sep 19 06:06:48 AEST 1989


>From article <727 at larry.sal.wisc.edu>, by jwp at larry.sal.wisc.edu (Jeffrey W Percival):

> 
> But when I link my main program, I run into trouble with ld(1) finding
> multiple definitions of many lex variables.
> 
> How can I do what I want?


Several ways. (In order from probably best to probably worst...)

   1. In your makefile, use the -D option to cc to define the offending
      symbols as something else. For example,

     y.tab.o: y.tab.c y.tab.h
            cc $(CFLAGS) -Dyylval=Mpc_lval -Dyylex=Mpc_lex \
            -Dyyparse=Mpc_parse -Dyyerror=Mpc_error -c y.tab.c

   This technique can fail when the symbol in question occurs in some
   context other than that of a variable or function name, as the name of
   a structure field, for example. But in the case of a "pure" y.tab.c file
   with nothing strange going on in the semantic actions, no harm.

   This is generally a little safer than number 2:

   2. Run an awk or sed script over the y.tab.c file, changing the
      names mechanically. That also should go into the makefile.
      You generally don't want to do such things, because the string
      you are replacing can occur in other contexts, literal strings,
      for example. But in this case, generally no harm.

Number 3 would be the "right" way if there were a standard, powerful
object-file editor universally available: Edit the symbol-table in
the object file. But alas, "ld" is not up to the task. (And even if
it were, it is not universally available on all systems that have
yacc.) So number 3 is probably right out.



More information about the Comp.unix.wizards mailing list