SeedV/SeedLang

Wrong parsing/running behavior of floor division "//"

Closed this issue · 1 comments

Parsing

IReadOnlyList<SyntaxToken> syntaxTokens =
          Executor.ParseSyntaxTokens("9//9", "main", SeedXLanguage.SeedPython, null);

Expected parsed tokens: 4

Actual parsed tokens: 2

Running

As in SeedLang.Shell:

9//9

Expected result (as Python floor division): 1
Actual result: 9

BTW

Calculators only have the "÷" key. And the key is mapped to "/" in SeedCalc code. It doesn't make sense to allow users to input two "÷"s and explain it as a "//" operator.

A similar thing could happen when we support "**“ as the power operator later. Since it doesn't make sense to have two continuous "×" as a power operator.

It seems I need to forbid repeating "/" and "*" in SeedCalc.

On the other hand, continuous "+" and "-" could be good things in SeedLang. Because SeedLang already supports things like "3++++4" and "3+-+-+--4", etc.

But is it friendly to calculator users to support such weird expressions like "3+-+-+--4"? I guess it'd be better to only allow at most two of them, such as "3 + +4", "3 + -5", etc. When the operator is the leftmost token, only allow one of them, such as "+3 +4", "-3 + 4", etc.

Option 1) Implement these calculator-specific logic in SeedCalc.

Option 2) SeedLang provides a language named SeedXLanguage.SeedCalc. In this language, turn off operators like "//" and "**", and limit the continuous "+" and "-" operators as in the above way.

Which one do you prefer? I am okay with either of them.

It seems implementing a SeedCalc language is reasonable. Let me think and decide if it's easy and consistent with other languages.