I've been working on another stack-based golfing language called Stackgoat. In this challenge you'll be writing a Tokenizer for Stackgoat (or really any general stack-based languages).
Examples
"PPCG"23+["PPCG", '23', '+']'a "bc"+['"a"', '"bc"', '+']12 34+-"abc\"de'fg\\"['12', '34', '+', '-', '"abc\"de'fg\\"']"foo['"foo"'](empty input)[]'""['""', '""']
Specification
The three types you'll need to handle are:
- Strings, anything within
""
- Numbers, any sequence of digits
- Operators, any other single character besides whitespace
Whitespace is essentially ignored unless it is within a string or separates two numbers.
String / char spec:
- Strings are delimited by a
"
, and when a\
is encountered, the next character should be escaped. - Chars are prepended by a
'
and the character after the'
should be converted into a string literal.'a
->"a"
'
will always have a character after it- Closing quotes should be auto-inserted
Rules:
- No form of
eval
is allowed
Input / Output:
- Input can be taken through STDIN, function parameters, or your language's equivalent.
- Output should be an array or your language's closest equivalent.