Thread: Converting MINI-BASIC in MASM over to C++?

  1. #331
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I've just pushed some more "splitting into separate files" changes.
    The minibasic class itself was quite large, and I split out the compiler component into its own files - the compiler.cpp is nearly 700 lines in itself.

    [I had to hack about a few other places as well, and I'm not quite happy about the "DEBUGGING" function, but I wanted something that works - I will hopefully fix it up better tomorrow].

    And I've just uploaded a new version of the .exe.

    --
    Mats
    Last edited by matsp; 05-11-2009 at 05:38 PM.
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  2. #332
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Excellent. I'll check it out as soon as I have a chance.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #333
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Very nice work, matsp. It's a significant improvement.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  4. #334
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    639
    Since it's dissertation hand in day at my old uni, I thought I'd relive last year and have a go at another parsing project. So this is my attempt, along with my old friends flex and bison I've put together an interpreter. It's not an all in one including the editor like yours is, but for giggles I made it into a com object, and to fully immerse myself in last year, buildable from the WDK/DDK build environments. It will execute mbi files from the command line if you change the build type to exe and uncomment the define at the bottom of main/main.cpp.

    It seems to work with pitman and the one from Paul's site, but parenthesised expressions in a parenthesised function call like Window((X+9), (R-8)) for example might trip it up. It's an easy workaround so in best MS tradition, it's classified as won't fix.

    Lastly, instead of the umpteen thousand word slog, I did something far more fun and chronicled this thread, inspired by medieval themes.

    mini-basic - Google Code

  5. #335
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    matsp, I've noticed a couple of bugs in the latest version. For instance, if you run PITMAN and type 'R' to redo a level the redrawing of the options is off. Also, if you try to run REIGN a compile error is generated. Unfortunately, I'll be out of town for a couple of days, so I won't have time to take a closer look at the code until the end of the week.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  6. #336
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Ok, I'll see what I can do...

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #337
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Ok, so clearly out implementation is broken:
    Code:
    Hello0
    World
    Hello0
    World
    Ready.
    > list
    10 FOR I = 1 TO 10
    20 PRINT "Hello";
    30 PRINT "World"
    40 NEXT I
    Ready.
    >
    This is what it looks like in original minibasic:
    Code:
    Hello World
    Hello World
    Hello World
    Hello World
    Ready.
    >list
       10 FOR I = 0 TO 10
       20 PRINT "Hello";
       30 PRINT " World"
       40 NEXT I
    Ready.
    >
    Clearly, the ending semicolon is not honoured as "do not produce a newline".

    I will go to be now, but I will try to debug it on the train tomorrow.

    [By the way, I'm convinced there is no difference between the current and the previous implementation, so I'm pushing some minor code-cleanups - mainly in the clear-screen, avoiding using a vector to store the clear-character, and using FillConsoleXXX functions instead...]

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  8. #338
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I have identified the problem - but as I am at work at present, I can't submit the code (need to set up proxy settings - I may do that later on).

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #339
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Fix (all four lines + a bit of "add braces around one-line conditionals) is now in place. New code is not compiled into an executable.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  10. #340
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    More messing about with the parsing. Using table to parse keywords, rather than using long if/else chain. Ended up using HORRIBLE syntax for class-member-function-pointers (I had most of the code ready by the time I got home, it took me until now to get the right syntax).

    New executable for Paul (or anyone else) to try out as well.

    Edit: Submitted another minor update that cleans up the new code a tiny bit.

    And this is the line that took 5 hours to write:
    Code:
    			(((*this)).*((tab[i].emf)))();

    --
    Mats
    Last edited by matsp; 05-13-2009 at 05:42 PM.
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  11. #341
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    O_o

    This is why I hate working with other people!
    They just don't listen!

    Seriously though, you could have saved yourself some time if you'd read my notes. (Even if the relevant source is no longer used.)

    Soma

    link: matsp / minibasic / changeset / da336054aec1 &mdash; bitbucket.org
    instructions: search the page for (ZSV)

  12. #342
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by phantomotap View Post
    O_o

    This is why I hate working with other people!
    They just don't listen!

    Seriously though, you could have saved yourself some time if you'd read my notes. (Even if the relevant source is no longer used.)

    Soma

    link: matsp / minibasic / changeset / da336054aec1 &mdash; bitbucket.org
    instructions: search the page for (ZSV)
    Actually, that is the bit that I eventually copied to make this work - but not being used to member function pointers, I didn't quite get the bit about (*this) that you need to give the compiler what object to work on.

    I know you said that it was difficult to get it to work, but I didn't realize quite what it was that was difficult, if you see what I mean. I was searching for solutions on the web, but of course the ones I found only use member function pointers from the class within itself.

    I'm sorry I upset you...

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  13. #343
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    O_o

    I guess I should have added a "wink"... or something.

    I do hate working with people who don't listen, but that was hyperbole.

    "I didn't quite get the bit about (*this) that you need to give the compiler what object to work on."

    You shouldn't have to use that syntax. This:

    Code:
    (this->*tab[i].emf)();
    is correct. It just doesn't work on some compilers for whatever magic reasons. (The extra parentheses around the `->*' subexpression are mandated by the standard.) If you only care about GCC and MSVC (not sure about older versions) you can go ahead and change it.

    "I found only use member function pointers from the class within itself."

    I'm not sure what you mean here.

    Soma

  14. #344
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    The quoted bit you don't understand was meant to say that when I searched for a member function pointer example (the C++ FAQ for example), I got something like:
    Code:
    class X
    {
         public:
            void (X::*func)();
    
            void f()  { cout << "Hello, World" << endl; } 
    }
    
    
    X x;
    x.func = &f;
    (x.*func)();
    (I just wrote that from memory, it may not be accurate)
    The key ingredient is that it's not calling a member function of X from within the instance x via a data structure OTHER than the class itself. Which requires the complex this-> or *this syntax. And that was the bit I didn't understand - and the error message from the compiler is completely and utterly meaningless [I also managed to get a "internal compiler error" by adding a line with () instead of braces in a struct initializer, which didn't exactly help the process of working...]

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  15. #345
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I just did a bit more refactoring of the code, splitting the interpreter code into it's own files.


    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Converting textBox1->Text into a basic string.
    By azjherben in forum C++ Programming
    Replies: 5
    Last Post: 06-07-2009, 08:27 PM
  2. [ANN] New script engine (Basic sintax)
    By MKTMK in forum C++ Programming
    Replies: 1
    Last Post: 11-01-2005, 10:28 AM
  3. what are your thoughts on visual basic?
    By orion- in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 09-22-2005, 04:28 AM
  4. VC++ 6 & MASM (eek)
    By cboard_member in forum C++ Programming
    Replies: 2
    Last Post: 07-16-2005, 10:00 AM