2012-03-11 8 views
0

問題があります: TIプログラミング言語で有効なトークンであるトークンのリストがあります。私は、完全な16進データで構成されたTI-83/84プログラムに有効なトークンを含むテキストをコンパイルするプログラムを作成しようとしています。データをファイルに書き込む方法と、ファイルからデータを取得する方法を知っています。 プログラムを検索して有効なトークンを特定し、プログラムの順序を保持できるプログラムを作成する必要があります。私はすでにトークンをキーワードとし、そのようなテキストを検索することを考えましたが、最初に選択されたトークンが常にテキストの最初のものになるとは限りませんので、その順序は失われます。Java - TI-84トークンを16進コードに変換する

私は自分のトークンオブジェクトを書いていると私は私のパーサでは以下の変数使用しています:

  • ArrayListのトークン - トークンオブジェクトのArrayListを(TI-BASICのすべての有効なトークン)
  • をまた、テキストファイル
  • Stringデータ - -
  • のDataInputStreamのDISファイルからプログラムを抽出するにはloaddataのメソッドを使用していることをテキストデータ(いない問題で、そうではない重要なことはどのように働くか)
  • DataOutputStreamのドス - .8xpファイル書き込み先:

トークンクラス:

public class Token { 

    private String tokenText; 
    int[] hexValue; 
    boolean isTwoByte; 

    /** 
    * The default constructor. 
    * Assigns empty values to all instance variables. 
    */ 
    public Token() { 
    tokenText = ""; 
    hexValue = new int[0]; 
    isTwoByte = false; 
    } 

    /** 
    * Constructs a Token with <tt>text</tt> text and an empty int[] for <tt>hexValue</tt> 
    * @param text the text to be assigned to the Token 
    */ 
    public Token(String text) { 
    tokenText = text; 
    hexValue = new int[0]; 
    isTwoByte = false; 
    } 

    /** 
    * Constructs a Token with an empty String for <tt>text</tt> and <tt>hexValue</tt> value 
    * This is a one-byte Token 
    * @param value the value to be assigned to the Token 
    */ 
    public Token(int value) { 
    tokenText = ""; 
    hexValue = new int[1]; 
    hexValue[0] = value; 
    isTwoByte = false; 
    } 

    /** 
    * Constructs a Token with an empty String for <tt>text</tt> and <tt>hexValue></tt> v1v2 
    * This is a two-byte Token 
    * @param v1 the first byte of the two-byte value that will be assigned to the Token 
    * @param v2 the second byte of the two-byte value 
    */ 
    public Token(int v1, int v2) { 
    tokenText = ""; 
    hexValue = new int[2]; 
    hexValue[0] = v1; hexValue[1] = v2; 
    isTwoByte = true;   
    } 

    /** 
    * Constructs a Token with <tt>text</tt> text and <tt>hexValue</tt> value 
    * This is a one-byte Token 
    * @param text the text to be assigned to the Token 
    * @param value the value to be assigned to the one-byte Token 
    */ 
    public Token(String text, int value) { 
    tokenText = text; 
    hexValue = new int[1]; 
    hexValue[0] = value; 
    isTwoByte = false; 
    } 

    /** 
    * Constructs a Token with tokenText <tt>text</tt> text and <tt>hexValue</tt> v1v2 
    * This is a two-byte Token 
    * @param text the text to be assigned to the Token 
    * @param v1 the first byte of the two-byte value that will be assigned to the Token 
    * @param v2 the second byte of the two-byte value 
    */ 
    public Token(String text, int v1, int v2) { 
    tokenText = text; 
    hexValue = new int[2]; 
    hexValue[0] = v1; hexValue[1] = v2; 
    isTwoByte = true; 
    } 

    /** 
    * Returns the text that is assigned to the particular Token 
    * @return the text that is assigned to the particular Token 
    */ 
    public String getText() { 
    return tokenText; 
    } 

    /** 
    * Returns the byte value of the Token 
    * @return the byte value of the Token 
    */ 
    public int[] getValue() { 
    return hexValue; 
    } 

    /** 
    * Returns <tt>true</tt> if the Token is a two-byte Token, and <tt>false</tt> otherwise 
    * @return <tt>true</tt> if the Token is a two-byte Token, and <tt>false</tt> otherwise 
    */ 
    public boolean isTwoByte() { 
    return isTwoByte; 
    } 

    /** 
    * Sets the tokenText text of the Token to the String passed it. 
    * @param text the new text to be assigned to the Token 
    */ 
    public void setText(String text) { 
    tokenText = text; 
    } 

    /** 
    * Sets the byte value of the Token to the integer passed it. This sets the isTwoByte variable to <tt>false</tt>. 
    * @param value the new byte value to be assigned to the Token 
    */ 
    public void setValue(int value) { 
    hexValue = new int[1]; 
    hexValue[0] = value; 
    isTwoByte = false; 
    } 

    /** 
    * Sets the byte value of the Token to the integers passed it. This sets the isTwoByte variable to <tt>true</tt>. 
    * @param v1 value of the first byte of the two-byte Token 
    * @param v2 value of the second byte 
    */ 
    public void setValue(int v1, int v2) { 
    hexValue = new int[2]; 
    hexValue[0] = v1; hexValue[1] = v2; 
    isTwoByte = true; 
    } 
} 

私は誰かがこれで私を助けることができるようになりますことを願っています。とにかくコードなど、より多くの情報が必要な場合は、問題はありませんが、プロジェクトはオープンソースになります。これに関する助けを前にありがとう。

+1

入力データの外観とそのデータセットの出力のスニペットを表示できますか?うまくいけば、ほんの数行が必要になります。 –

+0

入力データがUTF-8の.txtファイルに保存され、次のようになりされる: :TI-84プログレ の "Hello World" - > STR1 DISP STR1: を停止し、最終的な出力が中に保存しなければなりません次の生16進数のデータ(ヘッダを含まない)を含むべき.8xpファイル: 3E 54 49 71 38 34 29 50 BBC2 BBBF BBB6 3F 2A 48 BBB4 BBBC BBBC BBBF 29 57 BBBF BBC2 BBBC BBB3 2A 04 AA00 3F DE AA00 3E D9 [:] = 3E [ "] 2A =を - ] = 71 [] = 29 [ - >] = [DISP]はDE [停止] = D9を=[Str1] =トークン値が事前に設定された変数AA00 大文字は通常のASCIIエンコーディングと同じです 小文字はBBB0から始まる2バイトトークンです – user1260475

+0

上記の情報のフォーマットが貧弱であるとお詫び申し上げます新しい行。 "Prog"の後と最初の "Str1"の後に改行があるはずです – user1260475

答えて

0

自分で使ったことはありませんが、java.io.StreamTokenizerクラスでは必要なのは何ですか?または、ソースファイル全体を読むことができる場合は、単純なStringTokenizerです。

ファイルを順番に踏んでいるので、注文を保存することについて心配する必要はありません。

+0

StreamTokenizerは有望です。私は、BufferedReaderを使用してStringデータを取得します。しかし、私はStreamTokenizerを使用したことはありません。したがって、あらかじめ作成されたデータベースから特定のトークンを検索するためにどのように使用しますか? – user1260475

+0

ソースコードを線形に解析する必要があります。いずれにしても、トークンの16進値がどこにあるのかを把握する必要があります。 *どのように私はそれは本当に重要ではありません。 入力いただきありがとうございます。 – user1260475

+0

この質問(http://stackoverflow.com/q/672577/732379)には、コンパイラを書くときにいくつかの場所があることを願っています。その質問にはたくさんのリンクがあります。 – chooban

関連する問題