问题描述
我一直在创建一个词法分析器,一切正常,除了我不希望输出在控制台中包含下一行“#”。我该怎么做?
Token getToken() {
int line,pos;
while (Character.isWhitespace(this.chr)) {
getNextChar();
}
line = this.line;
pos = this.pos;
switch (this.chr) {
case '\u0000': return new Token(TokenType.End_of_input,"",this.line,this.pos);
case '\'': return char_lit(line,pos);
case '<': return follow('=',TokenType.less_than_operator,line,pos);
case '=': return follow('=',TokenType.Assignment_operator,pos);
case '"': return string_lit(this.chr,pos);
case '{': getNextChar(); return new Token(TokenType.opening_brace,pos);
case '}': getNextChar(); return new Token(TokenType.Closing_brace,pos);
case '(': getNextChar(); return new Token(TokenType.opening_parenthesis,pos);
case ')': getNextChar(); return new Token(TokenType.Closing_parenthesis,pos);
case ';': getNextChar(); return new Token(TokenType.Semi_colon,pos);
case ',': getNextChar(); return new Token(TokenType.Comma,pos);
case '#': getNextChar(); return new Token(TokenType.Nextline,pos);
case '□': getNextChar(); return new Token(TokenType.Space_separator,pos);
default: return identifier_or_integer(line,pos);
}
}
void printTokens() {
Token t;
System.out.println("Lexical Analyzer ");
System.out.println("-----------------");
while ((t = getToken()).tokentype != TokenType.End_of_input) {
//except nextline
System.out.println(t);
}
System.out.println(t-);
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)