private void RecogSym() { string str = "" + input[i]; if (str == ":" || str == "<" || str == ">") { i++; if (input[i] == '=') { str += input[i]; } else if (input[i] == '>' && str == "<") { str += input[i]; } else { i--; } } for (int j = 21; j <= 37; j++) { if (str == MachineCodes[j]) { Token t = new Token { TokenCount = Tokens.Count, Name = str, Code = j, IdentifierCount = -1 }; Tokens.Add(t); i++; } } }
private void RecogId() { string str = ""; int code; do { str += input[i]; i++; } while (IsAlpha(input[i]) || IsDight(input[i])); //Only if it's alpha or digit, add it into current word code = Reserve(str); Token t = new Token { TokenCount = Tokens.Count, Name = str }; //Store into token list if (code == 0) { t.Code = 18; t.IdentifierCount = Symbols.Count; Symbol s = new Symbol { IdentifierCount = t.IdentifierCount, Name = str, Code = 18 }; //Store into symbol list Symbols.Add(s); } else { t.Code = code; t.IdentifierCount = -1; } Tokens.Add(t); }
private void RecogCons() { string str = input[i].ToString(); bool flag = true; bool point = true; while (flag) { i++; if (IsDight(input[i])) { str += input[i]; } else if (input[i] == '.') { if (point) { str += input[i]; point = false; } else { Error e = new Error(rowNum, str, "Have the second '.' for this number!"); Errors.Add(e); flag = false; } } else { flag = false; } } if (point) { Token t = new Token { TokenCount = Tokens.Count, Name = str, Code = 19, IdentifierCount = Symbols.Count }; Symbol s = new Symbol { IdentifierCount = t.IdentifierCount, Name = str, Code = 19 }; Symbols.Add(s); Tokens.Add(t); } else { Token t = new Token { TokenCount = Tokens.Count, Name = str, Code = 20, IdentifierCount = Symbols.Count }; Symbol s = new Symbol { IdentifierCount = t.IdentifierCount, Name = str, Code = 20 }; Symbols.Add(s); Tokens.Add(t); } }