Esempio n. 1
0
        public void VarDeclarationTests()
        {
            string           txt         = "int var";
            AntlrInputStream inputStream = new AntlrInputStream(txt);
            BogieLangLexer   lexer       = new BogieLangLexer(inputStream);

            lexer.AddErrorListener(new ParserErrorHandler <int>());
            CommonTokenStream commonTokenStream = new CommonTokenStream(lexer);
            BogieLangParser   parser            = new BogieLangParser(commonTokenStream);

            parser.AddErrorListener(new ParserErrorHandler <object>());
            BogieLangParser.VarDeclarationContext VarDeclarationContext = parser.varDeclaration();
            BogieLangBaseVisitor <object>         visitor = new BogieLangBaseVisitor <object>();

            visitor.Visit(VarDeclarationContext);
            Assert.True(parser.NumberOfSyntaxErrors == 0);


            txt         = "int var=123";
            inputStream = new AntlrInputStream(txt);
            lexer       = new BogieLangLexer(inputStream);
            lexer.AddErrorListener(new ParserErrorHandler <int>());
            commonTokenStream = new CommonTokenStream(lexer);
            parser            = new BogieLangParser(commonTokenStream);
            parser.AddErrorListener(new ParserErrorHandler <object>());
            VarDeclarationContext = parser.varDeclaration();
            visitor = new BogieLangBaseVisitor <object>();
            visitor.Visit(VarDeclarationContext);
            Assert.True(parser.NumberOfSyntaxErrors == 0);


            txt         = "int var=funcCall()";
            inputStream = new AntlrInputStream(txt);
            lexer       = new BogieLangLexer(inputStream);
            lexer.AddErrorListener(new ParserErrorHandler <int>());
            commonTokenStream = new CommonTokenStream(lexer);
            parser            = new BogieLangParser(commonTokenStream);
            parser.AddErrorListener(new ParserErrorHandler <object>());
            VarDeclarationContext = parser.varDeclaration();
            visitor = new BogieLangBaseVisitor <object>();
            visitor.Visit(VarDeclarationContext);
            Assert.True(parser.NumberOfSyntaxErrors == 0);


            txt         = " \t     \nint \t     \nvar \t     \n= \t     \nfuncCall() \t     \n";
            inputStream = new AntlrInputStream(txt);
            lexer       = new BogieLangLexer(inputStream);
            lexer.AddErrorListener(new ParserErrorHandler <int>());
            commonTokenStream = new CommonTokenStream(lexer);
            parser            = new BogieLangParser(commonTokenStream);
            parser.AddErrorListener(new ParserErrorHandler <object>());
            VarDeclarationContext = parser.varDeclaration();
            visitor = new BogieLangBaseVisitor <object>();
            visitor.Visit(VarDeclarationContext);
            Assert.True(parser.NumberOfSyntaxErrors == 0);
        }
Esempio n. 2
0
        public void LiteralTests()
        {
            string           txt         = "1";
            AntlrInputStream inputStream = new AntlrInputStream(txt);
            BogieLangLexer   lexer       = new BogieLangLexer(inputStream);

            lexer.AddErrorListener(new ParserErrorHandler <int>());
            CommonTokenStream commonTokenStream = new CommonTokenStream(lexer);
            BogieLangParser   parser            = new BogieLangParser(commonTokenStream);

            parser.AddErrorListener(new ParserErrorHandler <object>());
            BogieLangParser.LiteralContext literalContext = parser.literal();
            BogieLangBaseVisitor <object>  visitor        = new BogieLangBaseVisitor <object>();

            visitor.Visit(literalContext);
            Assert.True(parser.NumberOfSyntaxErrors == 0);


            txt         = "1.0";
            inputStream = new AntlrInputStream(txt);
            lexer       = new BogieLangLexer(inputStream);
            lexer.AddErrorListener(new ParserErrorHandler <int>());
            commonTokenStream = new CommonTokenStream(lexer);
            parser            = new BogieLangParser(commonTokenStream);
            parser.AddErrorListener(new ParserErrorHandler <object>());
            literalContext = parser.literal();
            visitor        = new BogieLangBaseVisitor <object>();
            visitor.Visit(literalContext);
            Assert.True(parser.NumberOfSyntaxErrors == 0);


            txt         = "false";
            inputStream = new AntlrInputStream(txt);
            lexer       = new BogieLangLexer(inputStream);
            lexer.AddErrorListener(new ParserErrorHandler <int>());
            commonTokenStream = new CommonTokenStream(lexer);
            parser            = new BogieLangParser(commonTokenStream);
            parser.AddErrorListener(new ParserErrorHandler <object>());
            literalContext = parser.literal();
            visitor        = new BogieLangBaseVisitor <object>();
            visitor.Visit(literalContext);
            Assert.True(parser.NumberOfSyntaxErrors == 0);


            txt         = "\"asd8 99asd\"";
            inputStream = new AntlrInputStream(txt);
            lexer       = new BogieLangLexer(inputStream);
            lexer.AddErrorListener(new ParserErrorHandler <int>());
            commonTokenStream = new CommonTokenStream(lexer);
            parser            = new BogieLangParser(commonTokenStream);
            parser.AddErrorListener(new ParserErrorHandler <object>());
            literalContext = parser.literal();
            visitor        = new BogieLangBaseVisitor <object>();
            visitor.Visit(literalContext);
            Assert.True(parser.NumberOfSyntaxErrors == 0);
        }
Esempio n. 3
0
        public void ProgramTests()
        {
            string           txt         = "void funcName(){}";
            AntlrInputStream inputStream = new AntlrInputStream(txt);
            BogieLangLexer   lexer       = new BogieLangLexer(inputStream);

            lexer.AddErrorListener(new ParserErrorHandler <int>());
            CommonTokenStream commonTokenStream = new CommonTokenStream(lexer);
            BogieLangParser   parser            = new BogieLangParser(commonTokenStream);

            parser.AddErrorListener(new ParserErrorHandler <object>());
            BogieLangParser.ProgramContext ProgramContext = parser.program();
            BogieLangBaseVisitor <object>  visitor        = new BogieLangBaseVisitor <object>();

            visitor.Visit(ProgramContext);
            Assert.True(parser.NumberOfSyntaxErrors == 0);


            txt         = "void funcName(int abc,string str,void lol){}";
            inputStream = new AntlrInputStream(txt);
            lexer       = new BogieLangLexer(inputStream);
            lexer.AddErrorListener(new ParserErrorHandler <int>());
            commonTokenStream = new CommonTokenStream(lexer);
            parser            = new BogieLangParser(commonTokenStream);
            parser.AddErrorListener(new ParserErrorHandler <object>());
            ProgramContext = parser.program();
            visitor        = new BogieLangBaseVisitor <object>();
            visitor.Visit(ProgramContext);
            Assert.True(parser.NumberOfSyntaxErrors == 0);


            txt = "void funcName(){}" +
                  "void funcName(int abc,string str,void lol){}" +
                  "void funcName(int abc,string str,void lol){int intvar" +
                  "\nint intvar=123" +
                  "\nintvar=0.1" +
                  "\nfuncCall(lol)" +
                  "\nreturn funcCall()" +
                  "\n}";
            inputStream = new AntlrInputStream(txt);
            lexer       = new BogieLangLexer(inputStream);
            lexer.AddErrorListener(new ParserErrorHandler <int>());
            commonTokenStream = new CommonTokenStream(lexer);
            parser            = new BogieLangParser(commonTokenStream);
            parser.AddErrorListener(new ParserErrorHandler <object>());
            ProgramContext = parser.program();
            visitor        = new BogieLangBaseVisitor <object>();
            visitor.Visit(ProgramContext);
            Assert.True(parser.NumberOfSyntaxErrors == 0);
        }
Esempio n. 4
0
        public void WhileTests()
        {
            string           txt         = "while(true){}";
            AntlrInputStream inputStream = new AntlrInputStream(txt);
            BogieLangLexer   lexer       = new BogieLangLexer(inputStream);

            lexer.AddErrorListener(new ParserErrorHandler <int>());
            CommonTokenStream commonTokenStream = new CommonTokenStream(lexer);
            BogieLangParser   parser            = new BogieLangParser(commonTokenStream);

            parser.AddErrorListener(new ParserErrorHandler <object>());
            BogieLangParser.WhileControlContext WhileControlContext = parser.whileControl();
            BogieLangBaseVisitor <object>       visitor             = new BogieLangBaseVisitor <object>();

            visitor.Visit(WhileControlContext);
            Assert.True(parser.NumberOfSyntaxErrors == 0);


            txt         = "while(true){int b=0}";
            inputStream = new AntlrInputStream(txt);
            lexer       = new BogieLangLexer(inputStream);
            lexer.AddErrorListener(new ParserErrorHandler <int>());
            commonTokenStream = new CommonTokenStream(lexer);
            parser            = new BogieLangParser(commonTokenStream);
            parser.AddErrorListener(new ParserErrorHandler <object>());
            WhileControlContext = parser.whileControl();
            visitor             = new BogieLangBaseVisitor <object>();
            visitor.Visit(WhileControlContext);
            Assert.True(parser.NumberOfSyntaxErrors == 0);


            txt         = @"while(true)
{
    int b=0
    b = 1
    funcCall(b)
    while(false){return 1}
    return 0
}";
            inputStream = new AntlrInputStream(txt);
            lexer       = new BogieLangLexer(inputStream);
            lexer.AddErrorListener(new ParserErrorHandler <int>());
            commonTokenStream = new CommonTokenStream(lexer);
            parser            = new BogieLangParser(commonTokenStream);
            parser.AddErrorListener(new ParserErrorHandler <object>());
            WhileControlContext = parser.whileControl();
            visitor             = new BogieLangBaseVisitor <object>();
            visitor.Visit(WhileControlContext);
            Assert.True(parser.NumberOfSyntaxErrors == 0);
        }
Esempio n. 5
0
        public void FunctionCallTests()
        {
            string            txt               = "funcCall()";
            AntlrInputStream  inputStream       = new AntlrInputStream(txt);
            BogieLangLexer    lexer             = new BogieLangLexer(inputStream);
            CommonTokenStream commonTokenStream = new CommonTokenStream(lexer);
            BogieLangParser   parser            = new BogieLangParser(commonTokenStream);

            BogieLangParser.FunctionCallContext functionCallContext = parser.functionCall();
            BogieLangBaseVisitor <object>       visitor             = new BogieLangBaseVisitor <object>();

            visitor.Visit(functionCallContext);
            FunctionCall functionCall = FunctionCall.Compile(functionCallContext);

            Assert.True(functionCall.Identifier == "funcCall");
            Assert.True(functionCall.Arguments.Count == 0);


            txt         = "funcCall(\"arg\")";
            inputStream = new AntlrInputStream(txt);
            lexer       = new BogieLangLexer(inputStream);
            lexer.AddErrorListener(new ParserErrorHandler <int>());
            commonTokenStream = new CommonTokenStream(lexer);
            parser            = new BogieLangParser(commonTokenStream);
            parser.AddErrorListener(new ParserErrorHandler <object>());
            functionCallContext = parser.functionCall();
            visitor             = new BogieLangBaseVisitor <object>();
            visitor.Visit(functionCallContext);
            functionCall = FunctionCall.Compile(functionCallContext);
            Assert.True(functionCall.Identifier == "funcCall");
            Assert.True(functionCall.Arguments[0].Literal.String == "arg");


            txt         = "funcCall(10.0,funcCall2())";
            inputStream = new AntlrInputStream(txt);
            lexer       = new BogieLangLexer(inputStream);
            lexer.AddErrorListener(new ParserErrorHandler <int>());
            commonTokenStream = new CommonTokenStream(lexer);
            parser            = new BogieLangParser(commonTokenStream);
            parser.AddErrorListener(new ParserErrorHandler <object>());
            functionCallContext = parser.functionCall();
            visitor             = new BogieLangBaseVisitor <object>();
            visitor.Visit(functionCallContext);
            functionCall = FunctionCall.Compile(functionCallContext);
            Assert.True(functionCall.Identifier == "funcCall");
            Assert.True(functionCall.Arguments[0].Literal.Real == 10.0);
            Assert.True(functionCall.Arguments[1].FunctionCall.Identifier == "funcCall2");
        }
Esempio n. 6
0
        public void FunctionReturnTests()
        {
            string           txt         = "return abc";
            AntlrInputStream inputStream = new AntlrInputStream(txt);
            BogieLangLexer   lexer       = new BogieLangLexer(inputStream);

            lexer.AddErrorListener(new ParserErrorHandler <int>());
            CommonTokenStream commonTokenStream = new CommonTokenStream(lexer);
            BogieLangParser   parser            = new BogieLangParser(commonTokenStream);

            parser.AddErrorListener(new ParserErrorHandler <object>());
            BogieLangParser.FunctionReturnContext FunctionReturnContext = parser.functionReturn();
            BogieLangBaseVisitor <object>         visitor = new BogieLangBaseVisitor <object>();

            visitor.Visit(FunctionReturnContext);
            Assert.True(parser.NumberOfSyntaxErrors == 0);


            txt         = "return 10.0";
            inputStream = new AntlrInputStream(txt);
            lexer       = new BogieLangLexer(inputStream);
            lexer.AddErrorListener(new ParserErrorHandler <int>());
            commonTokenStream = new CommonTokenStream(lexer);
            parser            = new BogieLangParser(commonTokenStream);
            parser.AddErrorListener(new ParserErrorHandler <object>());
            FunctionReturnContext = parser.functionReturn();
            visitor = new BogieLangBaseVisitor <object>();
            visitor.Visit(FunctionReturnContext);
            Assert.True(parser.NumberOfSyntaxErrors == 0);

            txt         = " \t     \nreturn \t     \nabc \t     \n";
            inputStream = new AntlrInputStream(txt);
            lexer       = new BogieLangLexer(inputStream);
            lexer.AddErrorListener(new ParserErrorHandler <int>());
            commonTokenStream = new CommonTokenStream(lexer);
            parser            = new BogieLangParser(commonTokenStream);
            parser.AddErrorListener(new ParserErrorHandler <object>());
            FunctionReturnContext = parser.functionReturn();
            visitor = new BogieLangBaseVisitor <object>();
            visitor.Visit(FunctionReturnContext);
            Assert.True(parser.NumberOfSyntaxErrors == 0);
        }
Esempio n. 7
0
        public void LiteralTests()
        {
            string            txt               = "1";
            AntlrInputStream  inputStream       = new AntlrInputStream(txt);
            BogieLangLexer    lexer             = new BogieLangLexer(inputStream);
            CommonTokenStream commonTokenStream = new CommonTokenStream(lexer);
            BogieLangParser   parser            = new BogieLangParser(commonTokenStream);

            BogieLangParser.LiteralContext literalContext = parser.literal();
            BogieLangBaseVisitor <object>  visitor        = new BogieLangBaseVisitor <object>();

            visitor.Visit(literalContext);
            Literal literal = Literal.Compile(literalContext);

            Assert.True(literal.Execute() is int);
            Assert.True((int)literal.Execute() == 1);


            txt         = "1.0";
            inputStream = new AntlrInputStream(txt);
            lexer       = new BogieLangLexer(inputStream);
            lexer.AddErrorListener(new ParserErrorHandler <int>());
            commonTokenStream = new CommonTokenStream(lexer);
            parser            = new BogieLangParser(commonTokenStream);
            parser.AddErrorListener(new ParserErrorHandler <object>());
            literalContext = parser.literal();
            visitor        = new BogieLangBaseVisitor <object>();
            visitor.Visit(literalContext);
            literal = Literal.Compile(literalContext);
            Assert.True(literal.Execute() is double);
            Assert.True((double)literal.Execute() == 1.0);


            txt         = "false";
            inputStream = new AntlrInputStream(txt);
            lexer       = new BogieLangLexer(inputStream);
            lexer.AddErrorListener(new ParserErrorHandler <int>());
            commonTokenStream = new CommonTokenStream(lexer);
            parser            = new BogieLangParser(commonTokenStream);
            parser.AddErrorListener(new ParserErrorHandler <object>());
            literalContext = parser.literal();
            visitor        = new BogieLangBaseVisitor <object>();
            visitor.Visit(literalContext);
            Assert.True(parser.NumberOfSyntaxErrors == 0);
            literal = Literal.Compile(literalContext);
            Assert.True(literal.Execute() is bool);
            Assert.True((bool)literal.Execute() == false);


            txt         = "\"asd8 99asd\"";
            inputStream = new AntlrInputStream(txt);
            lexer       = new BogieLangLexer(inputStream);
            lexer.AddErrorListener(new ParserErrorHandler <int>());
            commonTokenStream = new CommonTokenStream(lexer);
            parser            = new BogieLangParser(commonTokenStream);
            parser.AddErrorListener(new ParserErrorHandler <object>());
            literalContext = parser.literal();
            visitor        = new BogieLangBaseVisitor <object>();
            visitor.Visit(literalContext);
            Assert.True(parser.NumberOfSyntaxErrors == 0);
            literal = Literal.Compile(literalContext);
            Assert.True(literal.Execute() is string);
            Assert.True((string)literal.Execute() == "asd8 99asd");
        }
Esempio n. 8
0
        public void BodyTests()
        {
            string           txt         = "int b=true";
            AntlrInputStream inputStream = new AntlrInputStream(txt);
            BogieLangLexer   lexer       = new BogieLangLexer(inputStream);

            lexer.AddErrorListener(new ParserErrorHandler <int>());
            CommonTokenStream commonTokenStream = new CommonTokenStream(lexer);
            BogieLangParser   parser            = new BogieLangParser(commonTokenStream);

            parser.AddErrorListener(new ParserErrorHandler <object>());
            BogieLangParser.BodyContext   BodyContext = parser.body();
            BogieLangBaseVisitor <object> visitor     = new BogieLangBaseVisitor <object>();

            visitor.Visit(BodyContext);
            Assert.True(parser.NumberOfSyntaxErrors == 0);


            txt         = "abc=123";
            inputStream = new AntlrInputStream(txt);
            lexer       = new BogieLangLexer(inputStream);
            lexer.AddErrorListener(new ParserErrorHandler <int>());
            commonTokenStream = new CommonTokenStream(lexer);
            parser            = new BogieLangParser(commonTokenStream);
            parser.AddErrorListener(new ParserErrorHandler <object>());
            BodyContext = parser.body();
            visitor     = new BogieLangBaseVisitor <object>();
            visitor.Visit(BodyContext);
            Assert.True(parser.NumberOfSyntaxErrors == 0);


            txt         = "func()";
            inputStream = new AntlrInputStream(txt);
            lexer       = new BogieLangLexer(inputStream);
            lexer.AddErrorListener(new ParserErrorHandler <int>());
            commonTokenStream = new CommonTokenStream(lexer);
            parser            = new BogieLangParser(commonTokenStream);
            parser.AddErrorListener(new ParserErrorHandler <object>());
            BodyContext = parser.body();
            visitor     = new BogieLangBaseVisitor <object>();
            visitor.Visit(BodyContext);
            Assert.True(parser.NumberOfSyntaxErrors == 0);


            txt         = "return 0";
            inputStream = new AntlrInputStream(txt);
            lexer       = new BogieLangLexer(inputStream);
            lexer.AddErrorListener(new ParserErrorHandler <int>());
            commonTokenStream = new CommonTokenStream(lexer);
            parser            = new BogieLangParser(commonTokenStream);
            parser.AddErrorListener(new ParserErrorHandler <object>());
            BodyContext = parser.body();
            visitor     = new BogieLangBaseVisitor <object>();
            visitor.Visit(BodyContext);
            Assert.True(parser.NumberOfSyntaxErrors == 0);


            txt         = "if(1){int b}";
            inputStream = new AntlrInputStream(txt);
            lexer       = new BogieLangLexer(inputStream);
            lexer.AddErrorListener(new ParserErrorHandler <int>());
            commonTokenStream = new CommonTokenStream(lexer);
            parser            = new BogieLangParser(commonTokenStream);
            parser.AddErrorListener(new ParserErrorHandler <object>());
            BodyContext = parser.body();
            visitor     = new BogieLangBaseVisitor <object>();
            visitor.Visit(BodyContext);
            Assert.True(parser.NumberOfSyntaxErrors == 0);


            txt         = "while(1){int b}";
            inputStream = new AntlrInputStream(txt);
            lexer       = new BogieLangLexer(inputStream);
            lexer.AddErrorListener(new ParserErrorHandler <int>());
            commonTokenStream = new CommonTokenStream(lexer);
            parser            = new BogieLangParser(commonTokenStream);
            parser.AddErrorListener(new ParserErrorHandler <object>());
            BodyContext = parser.body();
            visitor     = new BogieLangBaseVisitor <object>();
            visitor.Visit(BodyContext);
            Assert.True(parser.NumberOfSyntaxErrors == 0);
        }
Esempio n. 9
0
        public void FunctionCallTests()
        {
            string           txt         = "funcCall()";
            AntlrInputStream inputStream = new AntlrInputStream(txt);
            BogieLangLexer   lexer       = new BogieLangLexer(inputStream);

            lexer.AddErrorListener(new ParserErrorHandler <int>());
            CommonTokenStream commonTokenStream = new CommonTokenStream(lexer);
            BogieLangParser   parser            = new BogieLangParser(commonTokenStream);

            parser.AddErrorListener(new ParserErrorHandler <object>());
            BogieLangParser.FunctionCallContext functionCallContext = parser.functionCall();
            BogieLangBaseVisitor <object>       visitor             = new BogieLangBaseVisitor <object>();

            visitor.Visit(functionCallContext);
            Assert.True(parser.NumberOfSyntaxErrors == 0);


            txt         = "funcCall(\"arg\")";
            inputStream = new AntlrInputStream(txt);
            lexer       = new BogieLangLexer(inputStream);
            lexer.AddErrorListener(new ParserErrorHandler <int>());
            commonTokenStream = new CommonTokenStream(lexer);
            parser            = new BogieLangParser(commonTokenStream);
            parser.AddErrorListener(new ParserErrorHandler <object>());
            functionCallContext = parser.functionCall();
            visitor             = new BogieLangBaseVisitor <object>();
            visitor.Visit(functionCallContext);
            Assert.True(parser.NumberOfSyntaxErrors == 0);


            txt         = "funcCall(10.0,funcCall2())";
            inputStream = new AntlrInputStream(txt);
            lexer       = new BogieLangLexer(inputStream);
            lexer.AddErrorListener(new ParserErrorHandler <int>());
            commonTokenStream = new CommonTokenStream(lexer);
            parser            = new BogieLangParser(commonTokenStream);
            parser.AddErrorListener(new ParserErrorHandler <object>());
            functionCallContext = parser.functionCall();
            visitor             = new BogieLangBaseVisitor <object>();
            visitor.Visit(functionCallContext);
            Assert.True(parser.NumberOfSyntaxErrors == 0);


            txt         = "funcCall(10.0,funcCall2())";
            inputStream = new AntlrInputStream(txt);
            lexer       = new BogieLangLexer(inputStream);
            lexer.AddErrorListener(new ParserErrorHandler <int>());
            commonTokenStream = new CommonTokenStream(lexer);
            parser            = new BogieLangParser(commonTokenStream);
            parser.AddErrorListener(new ParserErrorHandler <object>());
            functionCallContext = parser.functionCall();
            visitor             = new BogieLangBaseVisitor <object>();
            visitor.Visit(functionCallContext);
            Assert.True(parser.NumberOfSyntaxErrors == 0);


            txt         = " funcCall\t(10.0\n,\rfuncCall2() \n\r\t)";
            inputStream = new AntlrInputStream(txt);
            lexer       = new BogieLangLexer(inputStream);
            lexer.AddErrorListener(new ParserErrorHandler <int>());
            commonTokenStream = new CommonTokenStream(lexer);
            parser            = new BogieLangParser(commonTokenStream);
            parser.AddErrorListener(new ParserErrorHandler <object>());
            functionCallContext = parser.functionCall();
            visitor             = new BogieLangBaseVisitor <object>();
            visitor.Visit(functionCallContext);
            Assert.True(parser.NumberOfSyntaxErrors == 0);
        }