Hello,

First off, great job with everything this site has accomplished! KermMartian, you seem like an incredibly talented person... that Clove thing really blew me away.

Anyway, on to the point. I have begun a project, but have run into a small problem... my complete and utter inexperience (with file structures, reading data from a file one byte at a time, the list goes on actually). What I need to be able to do is read an 8xp file, and properly use the data I get, so that I can convert the program file into a human readable text.

I'm looking to make this the first step towards creating a full (open source!) IDE for the TI-83+ programming language; a desktop IDE to more or less resemble Visual Studio. That means syntax highlighting, indents for If... Then and such, and if I'm feeling particularly ambitious (and masochistic) perhaps some form of Intellisense.

KermMartian actually pointed me to this site and recommended I post here for help. So, does anyone want to help? VB knowledge would be best, or an explanation of the procedures involved in parsing an 8xp file would be awesome sauce too.
VB sucks, learn a real language first (Python, C++, C#, etc...)

I would recommend Python: http://docs.python.org/tut/tut.html
Kllrnohj wrote:
VB sucks, learn a real language first


Okay, thanks for the advice, but not what I wanted.

codemonkey85 wrote:
VB knowledge would be best, or an explanation of the procedures involved in parsing an 8xp file would be awesome sauce too.
Yes, but what you are asking for is language dependent.

The .8xp file is a header+data+checksum format. You can find details of the format here: http://www.ticalc.org/archives/files/fileinfo/200/20062.html

The data is a collection of 1- or 2-byte tokens. There isn't any "parsing" to really be done. Its a straight token->string conversion
Thank you for the quick response.

Kllrnohj wrote:
The .8xp file is a header+data+checksum format. You can find details of the format here:
http://www.ticalc.org/archives/files/fileinfo/200/20062.html


I've been using those documents frequently... thanks to which, I've figured out so far how to pull the program name and program size. Well, the size shows up as 65533 if it's over a certain amount, but otherwise I can get it just fine. Apparently, I'm getting data out of the file incorrectly, and I need to fix that.

Kllrnohj wrote:
The data is a collection of 1- or 2-byte tokens. There isn't any "parsing" to really be done. Its a straight token->string conversion


You're saying VB.Net is incapable of doing this? Or just that you don't know how to because you don't code in VB? If it's the latter, there must be some logic behind it that I can use to create a function for it.

You see, I've never done any file manipulation beyond the basic reading and writing of text files before, so a "straight token->string conversion" isn't as, um, "straight" to me.
codemonkey85 wrote:
You're saying VB.Net is incapable of doing this? Or just that you don't know how to because you don't code in VB? If it's the latter, there must be some logic behind it that I can use to create a function for it.

You see, I've never done any file manipulation beyond the basic reading and writing of text files before, so a "straight token->string conversion" isn't as, um, "straight" to me.


I'm sure its capable of it, but its going to suck. VB.Net is a terrible, terrible language, and if you want any actual coding help, you'll need to learn/use something else. The easiest for you would probably be C# .Net, as then it is still the same libraries and such.

What you need to do is read a single byte (note that characters in C#/VB are wchar_t, which means they are 16-bits, or 2bytes - C# has a Byte type, I would assume VB .Net does as well), and then look that character up in a hashmap which will store the string equivalents. This is really, really easy to do in, say, Python Very Happy
I've looked at C++ before (not C# yet), and it gave me a headache just trying to comprehend it... and Python sounds cool, but I don't want to start everything from scratch now just for this. Someday I want to learn C#/C++, but today's not that day.

If I can get logic help from the people at this site (and specific 8xp help), I'll just get my coding help someplace else. Am I punishing myself doing it this way? Maybe. But I'm stubborn like that.

Kllrnohj wrote:
What you need to do is read a single byte (note that characters in C#/VB are wchar_t, which means they are 16-bits, or 2bytes - C# has a Byte type, I would assume VB .Net does as well), and then look that character up in a hashmap which will store the string equivalents. This is really, really easy to do in, say, Python Very Happy


I need to figure out what this hashmap business is about, and perhaps more importantly I need to figure out how to read only one byte from a file... that's what I thought I was doing at first, but it turned out I was sometimes getting two bytes (I guess). I don't know for sure if there even is a function to read specifically only one byte from a file in VB.Net, now that I think about it.

Is it really fact that VB is a terrible language, or do so many people hate it that there just isn't support for it? I thought with the advent of the .Net framework, the languages were essentially the same now.
Sorry I'm a bit busy today, I'll try to get you some information about parsing this evening.
Okay, so I've figured out how to read the file one byte at a time. I've seen that I can match up my hex values with the token values... the main problem I'm having now is figuring out when to read two bytes (when dealing with two byte tokens).

I have a lookup table set up as a structure, with a spot for the string representing a function name (Like "Disp "), a spot for a hex1 value (the first byte of the token), and a spot for a hex2 value (the second byte, if applicable).

I guess I could take the tokens I know are two bytes, and if I come across a byte value that matches one of those hex1 values, I could read the next byte in the file and try to match it to only the corresponding hex2 values.

Did that make sense?
Yup, you have the right idea. Here's the core of my token->text routine, which is admittedly a very small part of it, but the most important part nonetheless.


Code:
$data = $source;
      $size = ord(substr($data,$ift['size'],1))+256*ord(substr($data,$ift['size']+1,1));
      $token=0;
      $heremem = $ift['heremem'];
      $typedec = ord(substr($data,$heremem+$ift['heretype'],1));
      $heredata = $heremem+$ift['heredata'];
      $type = $types[$typedec];
      $size = ord(substr($data,$heremem+$ift['varsize'],1))+256*ord(substr($data,$heremem+$ift['varsize']+1,1))-2;
      $thisname1 = substr($data,$heremem+$ift['herename'],8);
      if ($filetype == 89) {
         $thisname = $thisname1;
      } else {
         $thisname = '';
         for($i=0;$i<=strlen($thisname1);$i++) {
            if (ord(substr($thisname,$i,1)) == 0) break;
            if (gettype($tf[ord(substr($thisname1,$i,1))]) == 'array') {
               $thisname .= $tf[ord(substr($thisname1,$i,1))][ord(substr($thisname1,$i+1,1))];
               $i++;
               $token++;
            } else {
               $thisname .= $tf[ord(substr($thisname1,$i,1))];
               $token++;
            }
         }
      }


Here's a short section of my translation table for token->text:


Code:
$t83 = array(
0 => '[]',
1 => '►DMS',
2 => '►Dec',
3 => '►Frac',
4 => '→',
5 => 'BoxPlot',
6 => '[',
7 => ']',
8 => '{',

[...]

92 => array(
   0 => '[A]',
   1 => '[B]',
   2 => '[C]',
   3 => '[D]',
   4 => '[E]',
   5 => '[F]',
   6 => '[G]',
   7 => '[H]',
   8 => '[I]',
   9 => '[J]',
),

[...]
Okay, so... this is where I am.

Take the following program:


Code:
ClrHome
While 1
getKey->X
If X!=0
Disp X
If X=105:Stop
End


This is what my interpreter spits out at this point:


Code:
ClrHome
While
getKey->
If !=
Disp
If =:Stop
End


So apparently all I can't get are the numbers and letters. Any suggestions?

If it helps, this is the parsing code I use now:


Code:
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles Button4.Click
        Dim ErrCount As Integer
        Dim offset As Integer = 1
        Dim i As Integer
        Dim iCount As Integer = 0
        'Try
        If fileopen.ShowDialog() <> Windows.Forms.DialogResult.Cancel Then
            If fileopen.FileName = "" Or Nothing Then Exit Sub
            TextBox1.Clear()
            Dim filename_ As String = fileopen.FileName
            Dim fs As FileStream = New FileStream(fileopen.FileName, _
                                                  FileMode.Open, FileAccess.Read)
            Dim str As String = ""
            Dim prgmBytes(2) As Byte
            Dim prgmSize As Short = 0
            i = fs.ReadByte()
            While i <> -1
                i = fs.ReadByte()
                offset += 1

                If offset = 73 Then prgmBytes(0) = i
                If offset = 74 Then prgmBytes(1) = i
                If offset = 75 Then
                    prgmSize = BitConverter.ToInt16(prgmBytes, 0)
                    Me.Text &= " " & prgmSize & " byte(s)"
                End If
                If offset >= 75 And prgmSize <> 0 Then
                    If offset < (prgmSize + 75) Then

                        'If it's a two-byte token:
                        '**************************************************
                        If i = &H5C Or i = &H5D Or i = &H5E _
                        Or i = &H60 _
                        Or i = &H61 Or i = &H63 Or i = &H7E _
                        Or i = &HAA _
                        Or i = &HBB Or i = &HEF Then
                            '**************************************************
                            For ic As Integer = 0 To 563
                                'MsgBox(ic & " - " & Hex(i) & " - " & LookupTable(ic).HEX2)
                                If LookupTable(ic).HEX1 = i Then
                                    ErrCount = ic
                                End If
                            Next
                            '**************************************************
                            'Read next byte
                            i = fs.ReadByte()
                            offset += 1
                            'go down list of hex2 values

                            For ic As Integer = ErrCount To 563
                                'MsgBox(ic & " - " & Hex(i) & " - " & LookupTable(ic).HEX2)
                                If LookupTable(ic).HEX2 = i Then
                                    str &= LookupTable(ic).ID
                                End If
                            Next

                        End If
                        '**************************************************

                        Select Case i

                            'http://tibasicdev.wikidot.com/tokens

                            'If it's a double quotation (chr(34))
                            Case &H2A
                                str &= Chr(34)
                                'If quotes <> begun then
                                'BEGIN QUOTES
                                'Else
                                'END QUOTES
                                'End If

                                'If it's a space
                                '    Case &H29

                                'If it's a (
                                '    Case &H10

                                'If it's a )
                                '    Case &H11

                                'If it's a , (NOT ON THE LOOKUP TABLE)
                                '    Case &H2B

                                'If it's a new line
                            Case &H3F
                                str &= vbNewLine
                            Case Else


                                'If it's a one-byte token:

                                '**************************************************
                                For iC As Integer = 0 To 563
                                    ErrCount = iC
                                    If LookupTable(iC).HEX1 = i Then
                                        str &= LookupTable(iC).ID
                                    End If
                                Next


                                '**************************************************
                        End Select
                    End If
                End If
            End While
            fs.Close()
            If str <> "" Then TextBox1.Text = str
        End If
        'Catch ex As Exception
        '    MsgBox(ex.Message, MsgBoxStyle.OkOnly, "Error " & Err.Number & ":")
        '    MsgBox("Offset: " & offset & vbNewLine & vbNewLine & "byte value: " & Hex(i) _
        '& vbNewLine & vbNewLine & "LookupTable Placement: " & ErrCount, MsgBoxStyle.OkOnly, _
        '"Error Box")
        'End Try
    End Sub
Letters and numbers are one byte tokens, so you might put them in the lookup table to make things easier.
(I hope this makes sens.)
Well, whaddya know? I didn't notice those before... thanks!

Okay, so I'm gonna throw those in there now.

I'm having some other issues too, as it turns out, but I'll edit this post once I fix this and have a more specific idea of what else is wrong.

EDIT: Well ladies and gents, I finally did it... my program for parsing 8xp files appears to be working perfectly.

The only slight problem is that I got my lookup table secondhand, and found out today that some of the text labeling the function names is incorrect, so I'll have to go through and proofread all 563 or so entries. Next thing after that, I'll be working on a program to convert text into an 8xp file (the reverse of what I can do now).

Should be cakewalk from there.
If you'd like my table to check again, you're welcome to it. I believe I have substantially more than 563 entries, though...
You might have problems with the reverse process, your program would have some way to find out what the user means by things like: !=, =<,... The program would be totally confused by something like this: "<=<!=<" or something like it, the user might also want to display =< instead of <smaller or equal> when it is used as a sprite or whatever.
KermMartian wrote:
I believe I have substantially more than 563 entries, though...


Probably, since the table I was using was also incomplete (I had to add the comma, all of the letters and numbers, etc.).

Actually, it would be useful to see your table for missed entries as well. So that would be cool. Very Happy

Also, hey, does anyone know of a good site to upload/store programs? Most sites don't allow it, I think, because of viruses and stuff.

EDIT:

Igrek wrote:
You might have problems with the reverse process, your program would have some way to find out what the user means by things like: !=, =<,... The program would be totally confused by something like this: "<=<!=<" or something like it, the user might also want to display =< instead of <smaller or equal> when it is used as a sprite or whatever.


Yeah, I thought about that briefly... I haven't quite figured out how to approach that problem, but I think I'll have an autocorrect feature to interpret different ways of saying, for example, "not equal to" (<>, !=, etc.). I'll have it correct them all to one, probably !=.

I don't know what I'd do with "<=<!=<", maybe I'd have my program mark it as faulty typing and leave it up to the user to fix it.
I believe that a lot of fonts like arial, times new roman, Comic sans MS,... have the greater/smaller or equal marks, as well as the not equal mark. But it would be cruel to make the user copy these mathematical symbols from the character map every time he needs them. You might prompt when the user types =< weather or not it should be changed to <smaller or equal>. (You could use a pop up window.)
Needless to say, I worked out a solution to that problem, but I'll let you think it over before I reveal it. Smile As far as a place to upload programs, do you mean as in final releases, or as in just a place to store your program temporarily?
Igrek wrote:
I believe that a lot of fonts like arial, times new roman, Comic sans MS,... have the greater/smaller or equal marks, as well as the not equal mark.


Eh, I think I'd rather deal with it the way Visual Studio does it, and just leave it as ">=" or what have you. I'd rather not deal with the actual symbols, for compatibility reasons and for user-friendliness reasons.

And KermMartian, to be honest I don't know if seeing your code would do me much good... I couldn't figure out what was going on in the samples you provided, so I just worked something out on my own anyway. Razz I really need to start learning other languages....

KermMartian wrote:
As far as a place to upload programs, do you mean as in final releases, or as in just a place to store your program temporarily?


I mean like, is there webspace where I can upload a program I've made, that I can link to for other people to download? I would ultimately put my final releases there, so I guess that's what I need. And it would be super-handy if I could host the program I have now, so I can talk people into bug-testing it for me. Very Happy
codemonkey85 wrote:
Igrek wrote:
I believe that a lot of fonts like arial, times new roman, Comic sans MS,... have the greater/smaller or equal marks, as well as the not equal mark.


Eh, I think I'd rather deal with it the way Visual Studio does it, and just leave it as ">=" or what have you. I'd rather not deal with the actual symbols, for compatibility reasons and for user-friendliness reasons.

And KermMartian, to be honest I don't know if seeing your code would do me much good... I couldn't figure out what was going on in the samples you provided, so I just worked something out on my own anyway. Razz I really need to start learning other languages....


Ah, ok, which languages do you know currently? I could explain my retokenizing algorithm in plain English if that would be more helpful.

Quote:
KermMartian wrote:
As far as a place to upload programs, do you mean as in final releases, or as in just a place to store your program temporarily?


I mean like, is there webspace where I can upload a program I've made, that I can link to for other people to download? I would ultimately put my final releases there, so I guess that's what I need. And it would be super-handy if I could host the program I have now, so I can talk people into bug-testing it for me. Very Happy


What's wrong with http://www.cemetech.net/programs/upload.php ? Very Happy
  
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
Page 1 of 2
» 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