help-bison
[Top][All Lists]
Advanced

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

Collecting statistics after parsing


From: Maury Markowitz
Subject: Collecting statistics after parsing
Date: Tue, 4 May 2021 14:09:34 -0400

Before I reinvent the wheel: I'm wondering if anyone has some boilerplate code 
for printing out the frequency of tokens found in the source?

Right now I'm counting out specific tokens, like constants for zero and one, 
strings, etc. This is with explicit code in the bison side that populate some 
extern variables. For instance, I have a simple pattern in my flex to find 
numeric constants, and then on the bison code I do:

factor:
  NUMBER
        {
          numeric_constants_total++;
          if (floorf(num) == num) {
            numeric_constants_int++;
          } else {
            numeric_constants_float++;
          }

It would seem that this would all be much easier to do by post-processing the 
tree? That would isolate the code in a single area, avoid polluting the bison 
source, and remove the need for the externs (main already knows about yy). The 
downside would be that I'd likely have to break up the tokens? One for integers 
and another for floats, etc.


reply via email to

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