floating-pointlextokenizeellipsis

Tokenizing Ellipsis in a Programming Language to Avoid Floating Points


I am designing a language where I want to use .. to define an integer range. The problem is that 0..10 is tokenized as the floats 0. and .10.

How do I allow support this syntax with flex? Is it is simple as making 0. an invalid float?


Solution

  • This is really up to how you define your lexer. If you define the ellipsis as being a token made up of two periods, and also define your floating point numbers correctly, there should not be a conflict. Just make sure the token for the ellipsis is defined first in your specification. And, yes, 0. should be an invalid float.