특정 입력 파일을 분석하는이 프로그램에서 작업 중이므로 거의 모든 것이 정확하게 키워드 목록을 제외하고 올바르게 출력됩니다.왜이 목록은 마지막 문자 만 출력합니까?
을 heres 키워드 목록 및 관련 기능에 대한 코드 조각 :
public class Token //Token structure to be added for each Token in the tokenTable
{
public string value;
public string type;
}
internal static class Define_input_output
{
public const string inFile = "input.txt"; //set file to read
public const string outFile = "output.txt"; //set file to write to
}
public static void placeKeywords_in_keywordsTable(List<string> keywords, List<Token> keywordTable)
{
Token newToken = new Token();
for (int i = 0; i < keywords.Count; i++) //loop through each keyword
{
newToken.value = keywords[i]; //add keyword[i] to newToken's value
newToken.type = "KW"; //assign "kw" to newToken's type
keywordTable.Add(newToken); //push newToken to keywordTable
}
}
public static void print_Tables_to_outputFile(StreamWriter output, List<Token> keywordTable)
{
output.Write("\r\n");
output.Write("-".PadRight(21, '-'));
output.Write("\r\n");
output.Write(' ');
output.Write("Keyword ".PadRight(11));
output.Write("|".PadRight(2));
output.Write("Index");
output.Write("\r\n");
output.Write("-".PadRight(21, '-'));
output.Write("\r\n");
for (int i = 0; i < keywordTable.Count; i++) //loop through each element in keywordTable
{
output.Write(' ');
output.Write((keywordTable[i].value).PadRight(10));
output.Write(" |".PadRight(7));
output.Write(i);
output.Write("\r\n");
}
}
static int Main()
{
StreamReader input = new StreamReader(Define_input_output.inFile);//input file
StreamWriter output = new StreamWriter(Define_input_output.outFile);//output file
List<string> keywords = new List<string>() { "else", "if", "int", "return", "void", "while", "+", "-", "*", "/", "<", "<=", ">", ">=", "==", "!=", "=", ";", ",", "(", ")", "[", "]", "{", "}", "/*", "*/" };
List<Token> keywordTable = new List<Token>();
placeKeywords_in_keywordsTable(keywords, keywordTable); //place all the keywords into keywordTable
while (!input.EndOfStream) //read each line until end of file
{
read_inputFile(input, output, keywordTable);
}
print_Tables_to_outputFile(output, keywordTable);
input.Close(); //close input file
output.Close(); //close output file
return 0;
}
문제 메신저 가진 키워드 테이블 만이 "* /"문자가 인쇄되고 있습니다. 그것의 색인이 붙은 26 번 (이는 얼마나 많은 문자가 목록에 있는지부터 인덱싱의 올바른 양입니다). 목록에서 마지막 두 문자를 제거하고 대신 "}"문자가 26 번 인쇄되기 시작했음을 테스트했습니다.
코드를 여러 번 신중하게 살펴본 결과 나는 무엇을 놓치고 있는지 전혀 알지 못합니다. 문제가 무엇인지 알 수 없습니다. 도움을 주시면 감사하겠습니다. 감사!
AWESOME! 감사합니다 – masterofcatastrophe
@masterofcatastrophe - 당신은 환영합니다 :) –
확실한 건, 메신저 그냥 타이머를 기다리고 권자 – masterofcatastrophe