Thread

  1. scan.l simplifications

    Robert B. Easter <reaster@comptechnews.com> — 2001-01-29T07:36:06Z

    In scan.l, there is:
    
    decimal (({digit}*\.{digit}+)|({digit}+\.{digit}*))
    real 
    ((({digit}*\.{digit}+)|({digit}+\.{digit}*)|({digit}+))([Ee][-+]?{digit}+))
    
    Could this be simplified as:
    
    decimal (({integer}?\.{integer})|({integer}\.{integer}?))
    real ((({decimal})|({integer}))([Ee][-+]?{integer}))
    
    What is the reason if it shouldn't be?  This is just an educational question, 
    I guess. I wouldn't want to waste time writing bad patches. :)  I ran regress 
    with this change and it looked ok.
    
    One reason I can think of right now, is that if the definition of integer or 
    decimal were to change, it might break decimal and real.  Another reason 
    might be a performance loss?
    
    -- 
    -------- Robert B. Easter  reaster@comptechnews.com ---------
    -- CompTechNews Message Board http://www.comptechnews.com/ --
    -- CompTechServ Tech Services http://www.comptechserv.com/ --
    ---------- http://www.comptechnews.com/~reaster/ ------------
    
    
  2. Re: scan.l simplifications

    Tom Lane <tgl@sss.pgh.pa.us> — 2001-01-29T15:03:40Z

    "Robert B. Easter" <reaster@comptechnews.com> writes:
    > In scan.l, there is:
    > decimal (({digit}*\.{digit}+)|({digit}+\.{digit}*))
    > real 
    > ((({digit}*\.{digit}+)|({digit}+\.{digit}*)|({digit}+))([Ee][-+]?{digit}+))
    
    > Could this be simplified as:
    
    > decimal (({integer}?\.{integer})|({integer}\.{integer}?))
    > real ((({decimal})|({integer}))([Ee][-+]?{integer}))
    
    I think it's better style as it stands.  The latter might be fewer
    characters but it's not easier to understand (IMHO anyway), because
    you have to refer back to more nonterminals to decipher it, and said
    nonterminals have meanings much more complicated than digit.
    
    Also, as you noted, it'd link the definitions of integer/decimal/real
    in ways that might cause trouble later.
    
    			regards, tom lane