public void Advance() { if (tokenQueue.Count > 0) { currentToken = tokenQueue.Dequeue(); } }
public JackTokenizer(StreamReader inputStream) { stream = inputStream; currentToken = null; tokenQueue = new Queue <JackToken>(); blockCommentActive = false; lineNumber = 0; }
/// <summary> /// Helper function for CheckTokenSequence(). Should not be called independently. /// </summary> private bool CheckToken(JackToken jt, string checkValue, out string errorMessage) { bool errorFound = false; bool checkType = false; bool listOfValues = false; bool listOfTypes = false; errorMessage = checkValue; checkType = (checkValue[0] == '?'); listOfValues = (checkValue[0] == '%'); listOfTypes = (checkValue[0] == '^'); if (checkType) { if (jt.Type.ToString() != checkValue.Substring(1)) { errorMessage = checkValue.Substring(1); errorFound = true; } } else if (listOfValues || listOfTypes) { bool matchFound = false; bool isTypeCheck = false; string[] values = checkValue.Split('%', '^', ' '); string matchValue = listOfValues ? jt.Value : jt.Type.ToString(); foreach (string s in values) { if (s == "type") { matchFound = jt.IsType(); } else if (s == matchValue) { matchFound = true; break; } } if (isTypeCheck && !matchFound) { if (jt.Type.ToString() == "identifier") { matchFound = true; } } if (!matchFound) { errorMessage = "one of [" + checkValue.Substring(1) + "]"; errorFound = true; } } else { if (jt.Value != checkValue) { errorMessage = checkValue; errorFound = true; } } return(!errorFound); }
/// <summary> /// Helper function for CheckTokenSequence(). Should not be called independently. /// </summary> private bool CheckToken(JackToken jt, string checkValue) { string dummy; return(CheckToken(jt, checkValue, out dummy)); }