チューリングマシンのテープを簡易的に再現せよという課題に取り組んでおり、そのTape Classのコードが上手く動かず、ご助言いただければ幸いです。
構成としては、以下のTapeクラスがCellクラスを呼んでいます。そのほかにも関係するクラスはありますが、ここでは割愛します。
Java
1package turing; 2 3import java.util.ArrayList; 4 5public class Tape { 6// public Tape(){ 7 //Prepare cells for tape. 8 Cell cell = new Cell(); 9 ArrayList<Cell> tape = new ArrayList<Cell>() { 10 { 11 add(cell); 12 } 13 }; 14 //Start pointing the index 0 cell as a current cell and assign blank space to it. 15 Cell currentCell = tape.get(0); 16 currentCell.content = ' '; 17// } 18 //Define each method needed for tape. 19 public Cell getCurrentCell() { 20 return currentCell; 21 } 22 public char getContent() { 23 return currentCell.content; 24 } 25 public void setContent(char ch) { 26 currentCell.content = ch; 27 } 28 public void moveLeft() { 29 if (currentCell == tape.get(0)){ //Check whether the current cell is the most left of the tape or not. 30 tape.add(0, cell); //If so, add the new cell to the top of the tape and move left. 31 currentCell = currentCell.prev; 32 } else { 33 currentCell = currentCell.prev; 34 } 35 } 36 public void moveRight() { 37 if (currentCell == tape.get(tape.size()-1)){ //Check whether the current cell is the most right of the tape or not. 38 tape.add(cell); //If so, add the new cell to the last of the tape and move right. 39 currentCell = currentCell.next; 40 } else { 41 currentCell = currentCell.next; 42 } 43 } 44 public String getTapeContents() { 45 String result = null; 46 for (int i = 0; i < tape.size(); i++) { 47 result += tape.get(i).content; 48 } 49 result.trim(); 50 return result; 51 } 52}
Java
1package turing; 2 3 4/** 5 * Represents one cell on a Turing Machine tape. 6 */ 7public class Cell { 8 9 public char content; // The character in this cell. 10 public Cell next; // Pointer to the cell to the right of this one. 11 public Cell prev; // Pointer to the cell to the left of this one. 12 13}
上記のコードのうち、TapeクラスがEclipse上で、以下のエラーメッセージを吐いておりました。
Syntax error on token "content", VariableDeclaratorId expected after this token
該当箇所は、Tapeクラスの、以下の一行です。エラーメッセージを調べましたが、具体的に何がエラーの原因となっているか理解できませんでした。CellクラスのcurrentCellが持つ、contentメンバーに、空白スペースのChar型を代入したい、というのが意図です。
currentCell.content = ' ';
ご助言いただけますと幸いです。
あなたの回答
tips
プレビュー