oftn-oswg / coca

An implementation of C in JavaScript.
Other
10 stars 3 forks source link

Number literals need to be tokenized #8

Open dsamarin opened 13 years ago

dsamarin commented 13 years ago

Number tokenizing is very long and complex. As of now there isn't a suitable token type for them. The long long needs to be represented with 64-bit integers, which JS does not support natively.

Here's some old code with doesn't tokenize, but goes through the basic steps of tokenizing. It is untested. https://github.com/oftn/coca/blob/4ac315fb329a09871277bbe3a033dc79488993c6/CParse.js

devyn commented 13 years ago

We probably won't be able to support long long for a little while, but when we do I would use an object like:

{ size: 64, hi: 0xFF, lo: 0x432 } = 0x000000FF00000432

We'd have to do a few complex things though, like implementation of the Karatsuba algorithm for multiplication.