help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Tokens to patterns?


From: Christian Schoenebeck
Subject: Re: Tokens to patterns?
Date: Thu, 31 Dec 2020 14:27:05 +0100

On Mittwoch, 30. Dezember 2020 18:44:54 CET Maury Markowitz wrote:
> Early imperative languages like FORTRAN and BASIC are marked by a large
> number of keywords. In my bison code I have pages of %token lines for PRINT
> and INPUT etc, which I then replicate in my flex with something like PRINT
> { return PRINT; }. This seems wasteful and just the thing the system should
> be automating away, am I missing a way to “autoflex” my tokens?

Such kind of automatic token definition feature does not seem to exist in 
Bison right now. What you could do ATM to reduce the lines of code of your .y 
file's preample is defining some of your tokens in one line, so instead of:

%token ONE
%token TWO
%token THREE

you might do this:

%token ONE TWO THREE

That even seems to work in combination with type specifiers and string 
literals:

%token <sval> ONE "one"
%token <ival> TWO "two"
%token <dval> THREE "three"

->

%token <sval> ONE "one" <ival> TWO "two" <dval> THREE "three"

Not exactly human friendly to read though.

How would you expect an auto token definition to work? You mean Bison shall 
check every "return FOO;" statement on *.l file side and then determine 
whether there is already a macro or symbol "FOO" defined in any source or 
included header file?

Best regards,
Christian Schoenebeck





reply via email to

[Prev in Thread] Current Thread [Next in Thread]