#!/usr/bin/awk -f
# "purify_flex.awk"
#	$Id: purify_flex.awk,v 1.3 2008/02/09 02:57:40 fang Exp $
# transforms calls to non-reentrant yylex into reentrant yylex, 
# generated by flex.  

# We accomplish this by declaring the lexer's state as a local object
# and passing it to the yylex routine.  
# The responsibility for hacking the yylex() call is elsewhere, 
# e.g. in a header file that redefines yylex() according to YYLEX_PARAM.

# this script works closely with "lexer/flex_lexer_state.h"

{
	if (match($0, "^yyparse[ ]*\\(.*\\)")) {
		print;
		do {
			getline;	# expecting open brace
			print;
		} while (!match($0,"\\{"));
		# for now the name of the local state object is hard-coded
#		print "/* the lexer's state object was inserted here " \
#			"by \"parser/purify_flex.awk\" */";
#		print "flex::lexer_state _lexer_state(infile);";
	} else {
		print;
	}
}

