Strange behavior with Visual Studio

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shockna1
    New Member
    • Apr 2010
    • 30

    Strange behavior with Visual Studio

    Long story short I am writing a compiler, and for some reason I am getting some vary strange errors which make no sense at all. I'm almost sure it has nothing to do with my code. I do have quite a few plugins is it possible that that is the cause?

    Ok so I guess I should explain some of the errors I'm getting so to start off here is my main method.

    Code:
    private static void Main(string[] args)
    {
        string file = "test.txt";
        StreamReader sr = new StreamReader(File.Open(file, FileMode.Open));
        Parser p = new Parser(new Lexer(file, sr));
        FrontEnd.AST.MProgram mp = p.Parse();
    
        try
        {
            if (mp != null)
            {
                mp.Dump();
            }
            else
            {
                Console.WriteLine("\nNULL");
            }
        }
        catch (Exception e)
        {
            Console.WriteLine("\nNRE");
        }
    
        Console.ReadKey();
    }
    Ok so there is no trouble parsing the input file. The problem is when I call the Dump method from the AST node it throws a NullReferenceEx ception that does not trace back to any code other than in main. It also says that the value of mp is null which cannot be true because the call to Dump is still successful so it must be thrown after the call. So I decided to test if it was null and if it was not null call Dump. To my surprise the result of the test was that mp was not null and somehow both the code in the if and else statement was called. Also to make things even stranger it no longer threw a NullReferenceEx ception. It kind of reminds me of how light has the properties of both a wave and a particle if you have any idea what I'm talking about.

    Any help would be appreciated.
  • shockna1
    New Member
    • Apr 2010
    • 30

    #2
    I figured it out I forgot to change a return statement.

    Comment

    Working...