-1
我想更好地理解遞歸下降解析器 - 特別是https://github.com/douglascrockford/JSON-js/blob/master/json_parse.js。 我感到困惑的一個功能的目的:麻煩理解遞歸下降解析
next = function (c) {
// If a c parameter is provided, verify that it matches the current character.
if (c && c !== ch) {
error("Expected '" + c + "' instead of '" + ch + "'");
}
// Get the next character. When there are no more characters,
// return the empty string.
ch = text.charAt(at);
at += 1;
return ch;
},
可能有人請幫助我的理解?據我目前的理解(我可能是錯誤的),它會檢查參數(c)是否與字符串中的下一個字符不相同?如果是這樣,這是什麼意思? 任何幫助,將不勝感激。
感謝您的回答。 因此if語句檢查參數(c)是否存在於整個字符串中,還是僅存在於字符串的其餘部分?我有點困惑,因爲'if(c && c!== ch)'似乎表明它正在檢查當前字符是否與下一個字符不相等? 感謝您的耐心等待。 –
不,第一個測試是檢查一個字符是否已經真正傳遞給函數(如果你看其餘的代碼,你可以看到next可以被調用爲next()或者next (' - ')'或類似的)。 – Renzo