First of all, I tried this:

http://www.python-forum.org/pythonforum/viewtopic.php?f=3&t=22068

Then, I decided not, so I will try this:


Code:

def token2bin(inp):
    i = 0
    maxtokenlenght = 16
    while (i<len(inp)):
        out = ''
        out1 = -1
        out2 = -1
        for a in range (maxtokenlenght, 0, -1):
            k = inp[i:i+a]
            try:
                if tr[k] == [] or out == '':
                    pass
                else:
                    out = k
                    j = tr[k]
                    if(j<999):
                        out1 = j
                        out2 = -1
                    else:
                        out1 = int (j / 1000)
                        out2 = j - 1000 * out1
            except:
                pass
        if (out1 == -1):
            pass
        else:
            i += len(out)
            if (out2 == -1):
                o *= str(out1)
            else:
                o *= str(out1) * str(out2)
    return o
print token2bin("Disp ")


And need to make a dictionary named 'tr', but need to learn dictionaries too :S
Well, the alternatives that they're offering are all based around the concept that searching for "D" in the string 'Disp D' will yield two match, not one, which is incorrect for tokenization. Hopefully the second, which appears to be your Pythonization of my code, will do the trick.
KermMartian wrote:
Well, the alternatives that they're offering are all based around the concept that searching for "D" in the string 'Disp D' will yield two match, not one, which is incorrect for tokenization. Hopefully the second, which appears to be your Pythonization of my code, will do the trick.


Yes, the first one has another problem too. It can only find one of each as it is right now, so the code:


Code:
Disp "Hello World!"


has two quotation marks, it would only detect one :S
ScoutDavid wrote:
Yes, indeed I am aware of arrays, duh!


Sure, but unless you know PHP you wouldn't necessarily know that a PHP array is not what most languages call an array. When someone says "array", they often mean something like a list. That isn't what Kerm meant, though.
Kllrnohj wrote:
ScoutDavid wrote:
Yes, indeed I am aware of arrays, duh!


Sure, but unless you know PHP you wouldn't necessarily know that a PHP array is not what most languages call an array. When someone says "array", they often mean something like a list. That isn't what Kerm meant, though.


Ooh, so that's confusing, for me an array is a list and in PHP it's not a list? Wow!

Anyways, what I need is a dictionary which look quite easy to do in Python Very Happy Very Happy
ScoutDavid wrote:
Kllrnohj wrote:
ScoutDavid wrote:
Yes, indeed I am aware of arrays, duh!


Sure, but unless you know PHP you wouldn't necessarily know that a PHP array is not what most languages call an array. When someone says "array", they often mean something like a list. That isn't what Kerm meant, though.


Ooh, so that's confusing, for me an array is a list and in PHP it's not a list? Wow!
It can be a simple list, but as Kllrnohj correctly mentions, that's not what I mean. I'm using an associative array (dictionary, if you will) that maps modified token values to token strings.
Well, I found something very useful:

http://effbot.org/zone/xml-scanner.htm
ScoutDavid wrote:
Well, I found something very useful:

http://effbot.org/zone/xml-scanner.htm
It's a good thought, but personally I'm not sure how useful regex would be in this case. The regex match for the TI token set would be truly enormous.
Well, I found something... It looks like someone has already done it in python and the code is here:

http://tibasicdev.wikidot.com/forum/t-184793/python-ti83-basic-converter
ScoutDavid wrote:
Well, I found something... It looks like someone has already done it in python and the code is here:

http://tibasicdev.wikidot.com/forum/t-184793/python-ti83-basic-converter
Yup, here's the meat of the recompiler, which is very similar to what I do:


Code:
 while readFile.tell() <= fileLength: # Ignore the last 2 bytes (checksum)
                    readLen = 1 + fileLength - readFile.tell()
                    readLen = min([maxKeyLen, readLen])
                    current = readFile.read(readLen)
                      # Try each possible key for the next few characters
                    while (readLen > 1 and not tDict.has_key(current)):
                        readFile.seek(-1*readLen, 1)
                        readLen -= 1
                        current = readFile.read(readLen)
                    if tDict.has_key(current):
                        writeBuffer.append(tDict[current])
                        if (current == "\n") or (current == "\r\n"):
                            lineNum += 1
                            # count line numbers
                    elif current == "&":
                        # The ampersand is the escape sequence character.
                        # If we got here, then:
                        # A) This is the escape sequence &@, indicating that
                        #    the next character should be translated literally.
                        readFile.seek(-1, 1)
                        current = readFile.read(2)
                        if current == "&@":
                            current = readFile.read(1)
                            writeBuffer.append(current)
                        # B) This is an invalid escape sequence. Let's announce that.
                        else:
                            print "%s is an invalid escape sequence on line %s" % (current, lineNum)
                            writeBuffer.append("ERROR %s" % current)
                    else:
                        # A character is unreadable!
                        print "%s not found on line &s" % (current, lineNum)
                        writeBuffer.append("ERROR %s" % current)
                programMeat="".join(writeBuffer)

Code:

while readFile.tell() <= fileLength: # Ignore the last 2 bytes (checksum)
                    readLen = 1 + fileLength - readFile.tell()
                    readLen = min([maxKeyLen, readLen])
                    current = readFile.read(readLen)
                      # Try each possible key for the next few characters
                    while (readLen > 1 and not tDict.has_key(current)):
                        readFile.seek(-1*readLen, 1)
                        readLen -= 1
                        current = readFile.read(readLen)
                    if tDict.has_key(current):
                        writeBuffer.append(tDict[current])
                        if (current == "\n") or (current == "\r\n"):
                            lineNum += 1
                            # count line numbers
                    elif current == "&":
                        # The ampersand is the escape sequence character.
                        # If we got here, then:
                        # A) This is the escape sequence &@, indicating that
                        #    the next character should be translated literally.
                        readFile.seek(-1, 1)
                        current = readFile.read(2)
                        if current == "&@":
                            current = readFile.read(1)
                            writeBuffer.append(current)
                        # B) This is an invalid escape sequence. Let's announce that.
                        else:
                            print "%s is an invalid escape sequence on line %s" % (current, lineNum)
                            writeBuffer.append("ERROR %s" % current)
                    else:
                        # A character is unreadable!
                        print "%s not found on line &s" % (current, lineNum)
                        writeBuffer.append("ERROR %s" % current)
                programMeat="".join(writeBuffer)


The seek command is used, along with a few others :S
Is that a problem? Wink I'd be happy to explain any commands that you don't understand.
KermMartian wrote:
Is that a problem? Wink I'd be happy to explain any commands that you don't understand.


Thanks much!

I don't know how seek works.

I tried running the program but it tells me non-ascii characters :S
ScoutDavid wrote:
KermMartian wrote:
Is that a problem? Wink I'd be happy to explain any commands that you don't understand.


Thanks much!

I don't know how seek works.

I tried running the program but it tells me non-ascii characters :S
seek() basically goes to a specific byte in a file, assuming that there's an implicit pointer into said file. Each time you read n bytes from the file, the pointer moves forward by n characters/bytes. Most programming languages having rewind() and/or seek() to move that pointer to an arbitrary location.
"seek() basically goes to a specific byte in a file, assuming that there's an implicit pointer into said file. Each time you read n bytes from the file, the pointer moves forward by n characters/bytes. Most programming languages having rewind() and/or seek() to move that pointer to an arbitrary location."

Thanks. You had any luck running it?
ScoutDavid wrote:
"seek() basically goes to a specific byte in a file, assuming that there's an implicit pointer into said file. Each time you read n bytes from the file, the pointer moves forward by n characters/bytes. Most programming languages having rewind() and/or seek() to move that pointer to an arbitrary location."

Thanks. You had any luck running it?
Can't say I've bothered trying, personally. Smile SourceCoder is all the converter that I need, plus I have a lot of stuff going on in my life atm.
KermMartian wrote:
ScoutDavid wrote:
"seek() basically goes to a specific byte in a file, assuming that there's an implicit pointer into said file. Each time you read n bytes from the file, the pointer moves forward by n characters/bytes. Most programming languages having rewind() and/or seek() to move that pointer to an arbitrary location."

Thanks. You had any luck running it?
Can't say I've bothered trying, personally. Smile SourceCoder is all the converter that I need, plus I have a lot of stuff going on in my life atm.



looooooooooool.

I have to try it with an older version of Python.
Which file does it say has the non-ASCII characters? Also, which version of python are you running; I assume 3.x?
KermMartian wrote:
Which file does it say has the non-ASCII characters? Also, which version of python are you running; I assume 3.x?


Version 2.6, of course

The dictionary file gives me it :S
ScoutDavid wrote:
KermMartian wrote:
Which file does it say has the non-ASCII characters? Also, which version of python are you running; I assume 3.x?


Version 2.6, of course

The dictionary file gives me it :S
I'd expect that, then, since it probably contains all the funky unicode characters that SourceCoder uses as well. :/
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
» Goto page Previous  1, 2, 3, 4, 5, 6, 7, 8  Next
» View previous topic :: View next topic  
Page 5 of 8
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement