Date: Thu, 9 Jul 1998 11:34:01 +0300 (IDT) From: Eli Zaretskii To: Anton Helm cc: djgpp AT delorie DOT com Subject: Re: =?iso-8859-1?Q?flex_scanning_a_'=B0'_(degree_sign)?= In-Reply-To: <3.0.5.32.19980708114505.0093ed90@hal.nt.tuwien.ac.at> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Precedence: bulk On Wed, 8 Jul 1998, Anton Helm wrote: > I would like to compile a program that contains such > a flex/bison frontend which is user configurable so > that the user can define which character should be > used on her/his system as the degree sign without > recompiling. > > How can I tell flex to use a 'variable' text to scan > the input for tokens ? AFAIK, Flex, by its very design, cannot produce non-constant tables for the matcher that it generates, since the algorithm it uses chooses the table which matches as much of the possibilities as it can in parallel, and that is only possible with constant tables whose contents is known at scanner-generation time. I can suggest two ways of dealing with your case: 1) Make your scanner recognize all possible characters that can serve as a degree character, and write your code that rejects all the characters but the one which is currently chosen by the application/user. For example: %% ... [a-z] {if (yytext[0] != user_defined_degree_char) yyless (1);} ... (this example assumes that any character in the range a-z can serve as the degree character). A variant of this is to *replace* the currently-chosen degree character by a single ``standard'' character: %% ... [a-z] { if (yytext[0] == user_defined_degree_char) unput (standard_degree_char); else yyless (1); } [d] {/* process the degree character */ ... (this assumes that `d' is the standard_degree_char). 2) Define your own input function which substitutes a single ``standard'' degree character for the current degree character chosen by the user, and override Flex's default input code by one of the available methods described in the manual. This way, the scanner will always see a single character in this role.