I am currently designing and implementing a small programming language as an extra-credit project in a class I'm taking. My problem is that the language has three numeric types: Long, Double, and Fraction. Fractions can be written in the language as proper or improper fractions (e.g. "2 1/3" or "1/2"). This fact leads to problems such as "2/3.5" (Long/Double) and "2/3"(Long/Long) not being handled correctly by the lexer.The best solution that I see is to change the division operator. So far, I think "\" is the best solution since "//" starts comments.
Would you pick "\", if you were designing the language?
Would you pick something else? If so, what?
Note: changing the way fractions are written is not possible.
Thanks in advance for your help,
-EDIT-
Current operators are:
**
(power)
*
(multiply)
%
(modulus)
+
(add)
-
(subtract and negation)
~
(reciprocal)
!
(NOT)
>
(greater)
<
(less)
>=
(greater-equal)
<=
(less-equal)
==
(equality)
<>
(inequality)
&
(AND)
|
(OR)
^
(XOR)
??
(null-coalesing)
=
(assignment)
Note: I am under no strictly binding demands by my teacher; however, I basically convinced him that I could turn a simple fraction calculator into a language. Changing the fraction's syntax would go against the fraction calculator's syntax for fractions, which is preferably avoided.
I'm not quite sure what's the problem, since I don't know grammar theory. But I would try changing proper fraction syntax, e.g. to 2_1/3
, with underscore rather than space.
About using \
as division operator — I would certainly not like it, since it is used in about every language as an escape character. I wouldn't recommend such overload of meanings.