Beispiel #1
0
        public void ValidateBinaryParsing()
        {
            string [] code = new [] {
                "      B'1010101111'",
                "      b\"111\"",
                "      B'121'"
            };
            FortranOptions opts = new FortranOptions();
            MessageCollection messages = new MessageCollection(opts);
            Lexer ls = new Lexer(code, opts, messages);

            SimpleToken token = ls.GetToken();
            Assert.IsTrue(token.ID == TokenID.INTEGER);
            IntegerToken intToken = (IntegerToken)token;
            Assert.AreEqual(intToken.Value, 687);

            Assert.IsTrue(ls.GetToken().ID == TokenID.EOL);

            token = ls.GetToken();
            Assert.IsTrue(token.ID == TokenID.INTEGER);
            intToken = (IntegerToken)token;
            Assert.AreEqual(intToken.Value, 7);

            Assert.IsTrue(ls.GetToken().ID == TokenID.EOL);

            ls.GetToken();
            Assert.IsTrue(messages.ErrorCount > 0);
            Assert.IsTrue(messages[0].Line == 3);
            Assert.IsTrue(messages[0].Code == MessageCode.BADNUMBERFORMAT);
        }
Beispiel #2
0
        public void ValidateBackslashStringParsing()
        {
            string [] code = new [] {
                "      \"Ab\\tCDEf\\n\""
            };
            FortranOptions opts = new FortranOptions();
            MessageCollection messages = new MessageCollection(opts);
            Lexer ls = new Lexer(code, opts, messages);
            SimpleToken token = ls.GetToken();
            Assert.IsTrue(token.ID == TokenID.STRING);

            StringToken stringToken = (StringToken)token;
            Assert.AreEqual(stringToken.String, "Ab\tCDEf\n");

            // Turn on the option to treat backslash character as
            // a backslash and not a special character.
            opts.Backslash = true;
            ls = new Lexer(code, opts, messages);
            token = ls.GetToken();
            Assert.IsTrue(token.ID == TokenID.STRING);

            stringToken = (StringToken)token;
            Assert.AreEqual(stringToken.String, "Ab\\tCDEf\\n");
        }
Beispiel #3
0
        public void ValidateTabDelimiter()
        {
            string [] code = new [] {
                "100\tINTEGER A",
                "\tREAL B"
            };
            FortranOptions opts = new FortranOptions();
            MessageCollection messages = new MessageCollection(opts);
            Lexer ls = new Lexer(code, opts, messages);
            Assert.IsTrue(ls.GetKeyword().ID == TokenID.KINTEGER);
            Assert.IsTrue(ls.HasLabel);
            Assert.IsTrue(ls.Label == "100");

            SimpleToken token = ls.GetToken();
            Assert.IsTrue(token.ID == TokenID.IDENT);

            IdentifierToken identToken = (IdentifierToken)token;
            Assert.AreEqual(identToken.Name, "A");

            Assert.IsTrue(ls.GetToken().ID == TokenID.EOL);
            Assert.IsTrue(ls.GetKeyword().ID == TokenID.KREAL);

            token = ls.GetToken();
            Assert.IsTrue(token.ID == TokenID.IDENT);

            identToken = (IdentifierToken)token;
            Assert.AreEqual(identToken.Name, "B");
        }
Beispiel #4
0
        public void ValidateRealParsing()
        {
            string [] code = new [] {
                "      123.0976AA",
                "      123.0976E-2",
                "      .5"
            };
            FortranOptions opts = new FortranOptions();
            MessageCollection messages = new MessageCollection(opts);
            Lexer ls = new Lexer(code, opts, messages);

            SimpleToken token = ls.GetToken();
            Assert.IsTrue(token.ID == TokenID.REAL);
            RealToken realToken = (RealToken)token;
            Assert.IsTrue(System.Math.Abs(realToken.Value - 123.0976f) < float.Epsilon, "Expected 123.0976 but saw " + realToken.Value);

            Assert.IsTrue(ls.GetToken().ID == TokenID.IDENT);
            Assert.IsTrue(ls.GetToken().ID == TokenID.EOL);

            token = ls.GetToken();
            Assert.IsTrue(token.ID == TokenID.REAL);
            realToken = (RealToken)token;
            Assert.IsTrue(System.Math.Abs(realToken.Value - 123.0976E-2f) < float.Epsilon, "Expected 123.0976E-2 but saw " + realToken.Value);

            Assert.IsTrue(ls.GetToken().ID == TokenID.EOL);

            token = ls.GetToken();
            Assert.IsTrue(token.ID == TokenID.REAL);
            realToken = (RealToken)token;
            Assert.IsTrue(System.Math.Abs(realToken.Value - 0.5f) < float.Epsilon, "Expected 0.5 but saw " + realToken.Value);
        }
Beispiel #5
0
        public void ValidateStringParsing()
        {
            string [] code = new [] {
                "      PRINT \"AbCDEf\""
            };
            FortranOptions opts = new FortranOptions();
            MessageCollection messages = new MessageCollection(opts);
            Lexer ls = new Lexer(code, opts, messages);
            Assert.IsTrue(ls.GetKeyword().ID == TokenID.KPRINT);

            SimpleToken token = ls.GetToken();
            Assert.IsTrue(token.ID == TokenID.STRING);

            StringToken stringToken = (StringToken)token;
            Assert.AreEqual(stringToken.String, "AbCDEf");
        }
Beispiel #6
0
        public void ValidateIntegerParsing()
        {
            string [] code = new [] {
                "      1230976AA"
            };
            FortranOptions opts = new FortranOptions();
            MessageCollection messages = new MessageCollection(opts);
            Lexer ls = new Lexer(code, opts, messages);
            SimpleToken token = ls.GetToken();
            Assert.IsTrue(token.ID == TokenID.INTEGER);

            IntegerToken intToken = (IntegerToken)token;
            Assert.AreEqual(intToken.Value, 1230976);
        }
Beispiel #7
0
        public void ValidateOctalParsing()
        {
            string [] code = new [] {
                "      O'745'",
                "      O\"340\"",
                "      O'892'"
            };
            FortranOptions opts = new FortranOptions();
            MessageCollection messages = new MessageCollection(opts);
            Lexer ls = new Lexer(code, opts, messages);

            SimpleToken token = ls.GetToken();
            Assert.IsTrue(token.ID == TokenID.INTEGER);
            IntegerToken intToken = (IntegerToken)token;
            Assert.AreEqual(intToken.Value, 485);

            Assert.IsTrue(ls.GetToken().ID == TokenID.EOL);

            token = ls.GetToken();
            Assert.IsTrue(token.ID == TokenID.INTEGER);
            intToken = (IntegerToken)token;
            Assert.AreEqual(intToken.Value, 224);

            Assert.IsTrue(ls.GetToken().ID == TokenID.EOL);

            ls.GetToken();
            Assert.IsTrue(messages.ErrorCount > 0);
            Assert.IsTrue(messages[0].Line == 3);
            Assert.IsTrue(messages[0].Code == MessageCode.BADNUMBERFORMAT);
        }
Beispiel #8
0
        public void ValidateHexParsing()
        {
            string [] code = new [] {
                "      $CC4DE",
                "      Z'CC4DE'",
                "      Z\"CC4DE\"",
                "      $AGG"
            };
            FortranOptions opts = new FortranOptions();
            MessageCollection messages = new MessageCollection(opts);
            Lexer ls = new Lexer(code, opts, messages);

            SimpleToken token = ls.GetToken();
            Assert.IsTrue(token.ID == TokenID.INTEGER);
            IntegerToken intToken = (IntegerToken)token;
            Assert.AreEqual(intToken.Value, 0xCC4DE);

            Assert.IsTrue(ls.GetToken().ID == TokenID.EOL);

            token = ls.GetToken();
            Assert.IsTrue(token.ID == TokenID.INTEGER);
            intToken = (IntegerToken)token;
            Assert.AreEqual(intToken.Value, 0xCC4DE);

            Assert.IsTrue(ls.GetToken().ID == TokenID.EOL);

            token = ls.GetToken();
            Assert.IsTrue(token.ID == TokenID.INTEGER);
            intToken = (IntegerToken)token;
            Assert.AreEqual(intToken.Value, 0xCC4DE);

            Assert.IsTrue(ls.GetToken().ID == TokenID.EOL);

            token = ls.GetToken();
            Assert.IsTrue(token.ID == TokenID.INTEGER);
            intToken = (IntegerToken)token;
            Assert.AreEqual(intToken.Value, 0xA);

            Assert.IsTrue(ls.GetToken().ID == TokenID.IDENT);
        }
Beispiel #9
0
 public void ValidateHasLabel()
 {
     string [] code = new [] {
         "100   INTEGER A",
         "      STOP"
     };
     FortranOptions opts = new FortranOptions();
     MessageCollection messages = new MessageCollection(opts);
     Lexer ls = new Lexer(code, opts, messages);
     Assert.IsTrue(ls.GetKeyword().ID == TokenID.KINTEGER);
     Assert.IsTrue(ls.HasLabel);
     Assert.IsTrue(ls.Label == "100");
     Assert.IsTrue(ls.GetToken().ID == TokenID.IDENT);
     Assert.IsTrue(messages.ErrorCount == 0);
 }
Beispiel #10
0
        public void ValidateF77ExtContinuationCharacter()
        {
            string [] code = new [] {
                "100   INTEGER STA&",
                "      TION"
            };
            FortranOptions opts = new FortranOptions();
            MessageCollection messages = new MessageCollection(opts);
            Lexer ls = new Lexer(code, opts, messages);
            Assert.IsTrue(ls.GetKeyword().ID == TokenID.KINTEGER);

            SimpleToken token = ls.GetToken();
            Assert.IsTrue(token.ID == TokenID.IDENT);

            IdentifierToken identToken = (IdentifierToken)token;
            Assert.AreEqual(identToken.Name, "STATION");
        }
Beispiel #11
0
        public void ValidateDoublePrecisionParsing()
        {
            string [] code = new [] {
                "      123.0976D4AA",
                "      123.0976D-2"
            };
            FortranOptions opts = new FortranOptions();
            MessageCollection messages = new MessageCollection(opts);
            Lexer ls = new Lexer(code, opts, messages);

            SimpleToken token = ls.GetToken();
            Assert.IsTrue(token.ID == TokenID.DOUBLE);
            DoubleToken realToken = (DoubleToken)token;
            Assert.IsTrue(Helper.DoubleCompare(realToken.Value, 123.0976E4), "Expected 123.0976E4 but saw " + realToken.Value);

            Assert.IsTrue(ls.GetToken().ID == TokenID.IDENT);
            Assert.IsTrue(ls.GetToken().ID == TokenID.EOL);

            token = ls.GetToken();
            Assert.IsTrue(token.ID == TokenID.DOUBLE);
            realToken = (DoubleToken)token;
            Assert.IsTrue(Helper.DoubleCompare(realToken.Value, 123.0976E-2), "Expected 123.0976E-2 but saw " + realToken.Value);
        }
Beispiel #12
0
        public void ValidateDebug()
        {
            string [] code = new [] {
                "      INTEGER A",
                "D     REAL B",
                "      INTEGER C"
            };
            FortranOptions opts = new FortranOptions();
            MessageCollection messages = new MessageCollection(opts);
            Lexer ls = new Lexer(code, opts, messages);
            Assert.IsTrue(ls.GetKeyword().ID == TokenID.KINTEGER);
            Assert.IsTrue(ls.GetToken().ID == TokenID.IDENT);
            Assert.IsTrue(ls.GetToken().ID == TokenID.EOL);
            Assert.IsTrue(ls.GetKeyword().ID == TokenID.KINTEGER);

            // Now it should pick up 'D' lines.
            opts.GenerateDebug = true;
            ls = new Lexer(code, opts, messages);
            Assert.IsTrue(ls.GetKeyword().ID == TokenID.KINTEGER);
            Assert.IsTrue(ls.GetToken().ID == TokenID.IDENT);
            Assert.IsTrue(ls.GetToken().ID == TokenID.EOL);
            Assert.IsTrue(ls.GetKeyword().ID == TokenID.KREAL);
        }