Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Language Design: Force unsigned Bitwise Operations And Precedence of Operations
#1
So I've been working on a compiler-parser set for small scripting language for the A-Engine (all character per character. no cheap tokenizers or any string search techniques involved B) ). It's going very well so far. been learning a lot reinventing wheels.

So yes, while I worked on this, I used a lot of bitwise operations to manipulate flags (AND to check, OR to switch on, XOR to switch off, xANDx-1 to check if POT ..etc), and I figured it wouldn't hurt to get those operators in the scripting language. The thing is (I'm really not sure whether I am doing all this properly or not), I got some sort of dynamic typing into this (types are Number, String and None), but since the scripting language is for the A-Engine, a game engine, I don't think people would ever need to do bitwise stuff besides flag manipulation (if that would even be necessary). Now, my Number type is really just float; so for my bitwise operators, I just cast both operands to int then back to my type to return it as a result. I was wondering if I shall cast into unsigned int instead, so that bitwise NOT on 1 returns 0 and not -2 as a result of NOTing the sign byte. By doing so however, I'll have to either not support using bitwise operations on negative numbers or simply just leave out the leftmost byte. I personally am leaning toward just letting the cast be to int, and those who want bitwise NOT to convert 1 to 0 and vice versa would use the logical NOT (!). Suggestions?

The next point involves the precedence of operators. So one of the weird things that hit me was the annoying decision of giving bitwise operator like AND and NOT a lower precedence than most equality related operators (==, >, <..etc). Later I realized: I wasn't the only one, this was only in C++, and that there isn't really a standard order everyone follows; e.g: python's list is very different from C++. So yeah, I thought I could try coming up with one myself to make things more intuitive :P I used C++'s as a base, and the first thing to change was of course that. I also did stuff like give bitwise OR and XOR the same precedence, and added a couple of operators like python's exponentiation (**). Hopefully, there weren't something I overlooked, or was there?

Lastly, I'm considering trying to be very flexible with operand types. e.g:
- "text * number" is 'text' repeated 'number' times. I know this can be done in python.
- "text + number" is length of 'text' + 'number'.
- "text - number" is length of 'text' - 'number'.
- "text / number" is length of 'text' / 'number'.
-etc..basically any attempt to do arithmetic on text that is not otherwise supported will use the length of the text operand(s) instead.
Is this a wise decision? Or should I stick to the classic "unsupported operand types" error messages?

Thanks!
[Image: signature.png]
A-Engine: A new beat em up game engine inspired by LF2. Coming soon

A-Engine Dev Blog - Update #8: Timeout

Reply
Thanks given by:


Messages In This Thread
Language Design: Force unsigned Bitwise Operations And Precedence of Operations - by A-Man - 02-01-2016, 05:41 PM



Users browsing this thread: 1 Guest(s)