protected List <object> performSyntaxAnalysis( TextReader inR, string sourceName, StreamWriter err, Type nodeClass, HashSet <Exception> pErrors) { OCLWorkbenchLexer lexer = new OCLWorkbenchLexer(inR, sourceName, err, pErrors); OCLWorkbenchParser parser = new OCLWorkbenchParser(sourceName, lexer, err, pErrors); List <object> result = null; OCLCompilerException compilerException = null; try { result = parseNode(parser, nodeClass); } catch (antlr.RecognitionException e) { compilerException = new OCLSyntaticException(e.Message, new SourceLocation(parser.getFilename(), e.getLine(), e.getColumn())); } catch (antlr.TokenStreamRecognitionException e) { compilerException = new OCLSyntaticException(e.Message, new SourceLocation(parser.getFilename(), e.recog.getLine(), e.recog.getColumn())); } catch (antlr.TokenStreamException e) { compilerException = new OCLSyntaticException(e.Message, new SourceLocation(parser.getFilename(), -1, -1)); } catch (Exception e) { if (e.Message != null) { compilerException = new OCLCompilerException(e.Message, new SourceLocation(parser.getFilename(), -1, -1)); } } finally { if ((err != null) && (compilerException != null)) { errors.Add(compilerException); syntaticErrorsCount++; err.WriteLine(compilerException); err.Flush(); } } syntaticErrorsCount += parser.getErrorCount(); if ((err != null) && ((syntaticErrorsCount != 0) || (compilerException != null))) { err.Flush(); } return(result); }
private CSTNode getClassifierRootNode(String source, String inputName) { OCLWorkbenchParser parser; StreamWriter err; StringReader inR = new StringReader(source); String inName = inputName; err = new StreamWriter(Console.OpenStandardOutput()); err.Flush(); HashSet <Exception> errorsList = new HashSet <Exception>(); OCLWorkbenchLexer lexer = new OCLWorkbenchLexer(inR, inName, err, errorsList); parser = new OCLWorkbenchParser(inName, lexer, err, errorsList); CSTNode result = null; try { result = parser.contextDeclarationCS(); } catch (antlr.RecognitionException e) { err.WriteLine(parser.getFilename() + ":" + "[" + e.getLine() + ", " + e.getColumn() + "]: " + e.Message); throw e; } catch (antlr.TokenStreamRecognitionException e) { err.WriteLine(parser.getFilename() + ":" + "[" + e.recog.getLine() + ", " + e.recog.getColumn() + "]: " + e.recog.Message); throw e; } catch (antlr.TokenStreamException ex) { err.WriteLine(parser.getFilename() + ":" + ex.Message); throw ex; } finally { err.Flush(); } if (parser.getErrorCount() != 0) { throw new Exception("syntatic errors in compilation"); } return(result); }