/// <summary> /// Gets token and identifier tables from lexical analyzer. /// </summary> /// <param name="token">Token table.</param> /// <param name="ident">Identifiers table.</param> public SyntaxAnalyzer(TokenTable token, IdentifiersTable ident, LexicalAnalyzer lAnalyzer) { this.token = token; this.ident = ident; this.lAnalyzer = lAnalyzer; count = this.token.tokensCount(); }
/// <summary> /// Analyzes code and creates token and identifier tables /// </summary> /// <param name="path">file to analize</param> public TokenTable analyze(String path, out IdentifiersTable ident) { text = File.ReadAllText(path); // analyzing by each character for (i = 0; i < text.Length; i++) { next = Convert.ToString(text[i]); // space symbol behavior if (SyntaxTable.isSpaceSymbol(next)) { processCurrent(); continue; } // number check if (SyntaxTable.isNumber(current)) { if (SyntaxTable.isNumber(current + next)) { current += next; continue; } else { processCurrent(); current = next; continue; } } // operator behavior if (SyntaxTable.isOperation(next) > -1) { // complex operation behavior if (!SyntaxTable.isOperationAllowed(current + next)) { processCurrent(); current = next; continue; } else { current += next; continue; } } // check if symbol is valid if (!SyntaxTable.isSymbolAllowed(Convert.ToChar(next))) { error(i); ident = null; return(null); } // check for preceding operator if (current.Length == 1 && (SyntaxTable.isOperation(Convert.ToString(current[0])) > -1)) { processCurrent(); current = next; continue; } current += next; } if (current != "") { processCurrent(); } ident = table; Console.WriteLine("Lexical analysis complete."); return(token); }
/// <summary> /// Analyzes code and creates token and identifier tables /// </summary> /// <param name="path">file to analize</param> public TokenTable analyze(String path, out IdentifiersTable ident) { text = File.ReadAllText(path); // analyzing by each character for (i = 0; i < text.Length; i++) { next = Convert.ToString(text[i]); // space symbol behavior if (SyntaxTable.isSpaceSymbol(next)) { processCurrent(); continue; } // number check if (SyntaxTable.isNumber(current)) { if (SyntaxTable.isNumber(current + next)) { current += next; continue; } else { processCurrent(); current = next; continue; } } // operator behavior if (SyntaxTable.isOperation(next) > -1) { // complex operation behavior if (!SyntaxTable.isOperationAllowed(current + next)) { processCurrent(); current = next; continue; } else { current += next; continue; } } // check if symbol is valid if (!SyntaxTable.isSymbolAllowed(Convert.ToChar(next))) { error(i); ident = null; return null; } // check for preceding operator if (current.Length == 1 && (SyntaxTable.isOperation(Convert.ToString(current[0])) > -1)) { processCurrent(); current = next; continue; } current += next; } if (current != "") processCurrent(); ident = table; Console.WriteLine("Lexical analysis complete."); return token; }