#14 Integer significands in floating-point literals

Test
open
nobody
4
2016-01-24
2014-06-29
Edward Hart
No

The attached patch adds support for floating-point literals with an integer significand, such as 1E-5.

While the standard stipulates the significand should be decimal, this seems like a somewhat arbitrary restriction, considering many other languages allow integer significands.

1 Attachments

Discussion

  • Simon Sobisch

    Simon Sobisch - 2015-06-03

    The solution is good, idea interesting. But I'm unsure if we should do this.
    Can you please check other compiler's manuals? If they have this extension we add it for compatibility purposes.
    In any case I'd like to have this only with a new config setting and don't set this in default.conf - in the current implementation it even can break existing source as 1E-5 is a valid COBOL word (vars, sections, ...).
    Therefore the scanner.l has to lookup the setting and unput everything if the setting isn't active.

     
  • Edward Hart

    Edward Hart - 2015-06-05

    No other compilers appear to have this extension.

    In the current implementation it even can break existing source as 1E-5 is a valid COBOL word

    That's a good point. I doubt many people will be willing to take the (small) risk of breaking their code.

     
  • Edward Hart

    Edward Hart - 2015-06-07

    Attached is version 2, which makes integer-significand support dependent on the config option integer-significands.

    Any further thoughts? If we don't want to add integer significands, I'll like to commit most of this patch anyway so that there's a more helpful error message ("Integer significands are not permitted" instead of "Unexpected identifier").

     
    • Simon Sobisch

      Simon Sobisch - 2015-06-07

      While the patch got better: What happens if a var or section is called 1E6? It's a rare issue but one we should consider.

      In any case: it's enough to have one test for most compiler and runtime configuration options - one to three test progs and multiple AT_CHECK with different options.

      Simon

       
  • Edward Hart

    Edward Hart - 2015-06-08

    Version 3

    Changes:

    • if integer significands are not permitted, no warnings are issued and the compiler acts as normal. Now identifiers like 1E6 will not be mistaken for floating-point literals by default.
    • the two tests in the previous patch have been merged.

    I did briefly consider making literals with integer significands context-sensitive, but I think ambiguities like these are unsolvable:

    01  1E1 USAGE FLOAT-LONG.
    01  1E2 USAGE FLOAT-LONG.
    *> ...
        ADD 1E1 TO 1E2 GIVING whatever
    
     
  • Simon Sobisch

    Simon Sobisch - 2016-01-24
    • labels: --> literals, cobc
    • Priority: 1 --> 4
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks