コード例 #1
0
    protected List <object> parseNode(OCLWorkbenchParser parser, Type nodeClass)
    {
        List <object> result = null;
        CSTNode       node   = null;

        if (nodeClass == null)
        {
            result = parser.expressionStream();
        }
        else if (nodeClass == typeof(CSTExpressionInOclCS))
        {
            node = parser.expressionInOCLCS();
        }
        else if (nodeClass == typeof(CSTTypeCS))
        {
            node = parser.typeCS();
        }
        else if (nodeClass == typeof(CSTContextDeclarationCS))
        {
            node = parser.contextDeclarationCS();
        }
        else if (nodeClass == typeof(CSTArgumentCS))
        {
            List <object> arguments = parser.argumentsCS();
            node = (CSTNode)arguments[0];
        }
        else if (nodeClass == typeof(CSTLiteralExpCS))
        {
            node = parser.literalExpCS();
        }
        else if (nodeClass == typeof(CSTVariableDeclarationCS))
        {
            node = parser.variableDeclarationCS();
        }
        else if (nodeClass == typeof(CSTVariableDeclarationCS))
        {
            node = parser.variableDeclarationCS();
        }
        else if (nodeClass == typeof(CSTClassifierAttributeCallExpC))
        {
            node = parser.classifierAttributeCallExpCS();
        }

        if ((result == null) && (node != null))
        {
            result = new List <object>();
            result.Add(node);
        }

        return(result);
    }
コード例 #2
0
        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);
        }