Given an infix expression, determine whether all constants are of the same type.
Operators will consist only of these dyadic operators:
Your program or function should take a valid expression string as input, and output a truthy value if the constants in the expression are of the same time, and a falsey value otherwise.
The expression will consist solely of constants, and may contain any of the following types:
- String, of the form
"String"(Always double quotes, can be empty, no escape characters, may contain any ASCII text)
- Integer, of the form
14(Always positive or zero)
- Float, of the form
7.3f(Always positive or zero, always has a decimal component, eg
- Byte, of the form
0-255, Always 2 hexadecimal characters)
- Boolean, of the form
false, case insensitive)
The expression will not contain parentheses, as order of operation doesn't affect type when no type coercion is present.
A lone constant with no operators is a valid expression.
An empty expression is not a valid expression.
You may assume that the expression string contains no whitespace outside of string literals.
Note: Alternatively you may assume that there will always be spaces between constants and operators, as seen in the testcases. If you make this assumption, please specify as such in your answer
You do not have to handle invalid expressions such as
This is code-golf, so fewest bytes wins!
(Whitespace added for readability)
2 + 3 True "Hello" / "World" True true * false True "Hello" + 4 False "Hello" + "4" True 3 + 2.4f / 8 False 0xff * 0xff True 0xff + 2 False 6 True " " + "" True "4 + false" + "word" True