- Joined
- Aug 27, 2017
- Messages
- 110
I had the idea to add character literals to cerberus since a while. Until now there were two ways to get the value of a character:
1. write it as a string literal and get the first character of that string:
2. look up the value of the character in a Unicode table:
So I added character literals to my version of trans (within my testing environment). Since the apostrophe character is already used for comments I used back-ticks for character literals:
Note: This feature does not conflict with any existing code. It is also very easy to integrate into the trans tool. The compiler translates character literals directly to integer values. It is also possible to use them in computations, in arrays and anywhere else – and it supports all escape characters
I also had to add a new escape character for back-ticks (which can be used in character literals and within strings):
The only downside I can see at the moment is that it is a new language feature – so it is not supported by any ide at the moment (which means: no syntax highlighting).
So … is there any interest in such a feature? Or any ideas or feedback?
1. write it as a string literal and get the first character of that string:
Code:
Print "*"[0]
2. look up the value of the character in a Unicode table:
Code:
Print 42 'value of '*'
So I added character literals to my version of trans (within my testing environment). Since the apostrophe character is already used for comments I used back-ticks for character literals:
Code:
Print `*`
Note: This feature does not conflict with any existing code. It is also very easy to integrate into the trans tool. The compiler translates character literals directly to integer values. It is also possible to use them in computations, in arrays and anywhere else – and it supports all escape characters
Code:
Print `~u00E6` * -`~n` * -10 + `*`
' => 23042
Print String.FromChars([`H`,`e`,`l`,`l`,`o`,`!`])
' => Hello!
Code:
Print `~g`
' => 96
Print "this is a back-tick -> ~g"
The only downside I can see at the moment is that it is a new language feature – so it is not supported by any ide at the moment (which means: no syntax highlighting).
So … is there any interest in such a feature? Or any ideas or feedback?
Last edited by a moderator: