ColdFire V1 - インタプリタ始動 [ColdFire (ColdeFire) V1]
インタプリタ作成計画も、ボチボチ走っています。
今日は、文字列表示と改行処理を入れてみました。
*READY :10 "hello world!"/ :20 "what are you talking about ?" :0 00010 "hello world!"/ 00020 "what are you talking about ?" *READY : hello world! what are you talking about ? *READY :
ダブル・クォーテーション(")でくくると、文字列が表示されます。 また、スラッシュ(/)で改行されます。
分岐処理はまだ入っていないので、 空行を含む直接実行の後は強制的にプログラムを実行するようにしました。
// void executeStatement(void) // 文の実行 void executeStatement(void) { char ch; while ((ch = *columnPoint) != 0) { if (ch == ' ') { // 文の区切り columnPoint++; continue; } // 分岐先変数 lineNumber = 0; if (isDelimit(*(columnPoint+1))) { // 一文字コマンド // No commands implemented. } if (ch =='"') { // 文字列表示 columnPoint++; for (;;) { ch = *columnPoint++; if ((ch == 0) || (ch == '"')) { break; } putc(ch); } } else if (ch == '/') { // 改行表示 while (ch == '/') { putc('\n'); ch = *(++columnPoint); } } else { lhsPoint = columnPoint; columnPoint++; } } }
入力行の直接実行の中に行番号の変更を監視する部分が含まれています。
// void executeDirect(void) // ラインバッファ内コマンドの実行 void executeDirect(void) { executeStatement(); // ラインバッファの実行 lineNumber = 1; // 分岐エミュレーション while (lineNumber != 0) { // 分岐したら、 linePoint = findLine(lineNumber); // 分岐先を探す for (;;) { if (linePoint >= textEnd) { // プログラム終端に到達 return; // エディタに戻る } columnPoint = linePoint + 2; // 行番号を飛ばす if (*columnPoint != ' ') { // コメント行をスキップする linePoint = nextLine(linePoint); } else { executeStatement(); // 一行実行 if (lineNumber != 0) { // 行番号が変更されたら break; // 分岐 } // 次の行に進む linePoint = nextLine(linePoint); } } } }
プロジェクトは、 ここを 右クリックして"CFQE20.zip"という名前で保存すると出てきます。
コメント 0