Thread: Creating Interpreter for TASM from C++

  1. #1
    Registered User
    Join Date
    Apr 2012
    Posts
    4

    Creating Interpreter for TASM from C++

    Hi, I'm currently working on a project for creating my own interpreter, a TASM interpreter.

    Assembly languange is so unique so i think its a bit more "fun" (i suppose) to create my own interpreter for it.

    Unfortunately, I have zero experience in creating an interpreter. So like all other people, I ended up here asking for advice, links, books, ebooks, or anything else (maybe a sample from an interpreter that you have already built) that would help me in making this project.

    Note: For now, I'm not creating the full interpreter for TASM, it will just contain some basic commands like MOV, ADD, SUB, DIV, MUL. So please dont reply with something like: "go study 4 years of computer science!", or "take lessons in some computer school!"

    Thanks, looking forward for your replies

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

    I honestly don't think four years of computer science would be enough.

    Compiler theory is a huge field. (I'll go ahead and cut you off at the pass; interpreters are built from many of the same algorithms and data structures as compilers.)

    I'm not trying to be a jerk. I just don't think that you have the knowledge to understand the books I would recommend.

    *shrug*

    Besides, the total cost of the books I'd recommend is about $700 (USD). At your level of experience, I believe, $700 (USD) will buy you a lot of resources that you'll learn from more readily. Heck, it would buy you a couple of years of subscription to some of the best resources available.

    Let me make an alternative suggestion: make an integer calculator. (expression building)
    Have you done that? Add support for floating point values. (floating point design)
    Have you done that? Add support for imaginary numbers. (structures)
    Have you done that? Add support for trigonometric functions. (callbacks)
    Have you done that? Add support for algebraic variables. (variables)
    Have you done that? Add support for solving algebraic equalities. (syntax tree mutation)
    Have you done that? Add support for user defined functions. (parsing theory)
    Have you done that? Add support for arrays of variables. (compiler design)
    Have you done that? Add support for array addressing. (machine theory)
    Have you done that? Add support for indirect addressing. (machine theory)
    Have you done that? Add support for functions to call back into compile C source. (virtual machine)
    Have you done that? Add support for the calculator state to be saved as a binary. (file format design)
    Have you done that? Add support for the calculator state to be saved as text. (parsing theory)
    Have you done that? Add support for instructions to run on the real CPU. (machine adaptation)
    Have you done that? Add syntax to mimic "TASM" syntax.

    Have you done that? Congratulations. You've made your interpreter.

    Soma

  3. #3
    Registered User
    Join Date
    Apr 2012
    Posts
    4
    thanks for your effort, but im really looking for is something like ebooks or book (just the name, because like hell i would buy them, i'll search for the scans or ebooks), or maybe an article about it

    like i said, im just making a very simple interpreter, much more like a prototype, which will only work on a very simple program that would be made simply for testing the interpreter.

  4. #4
    Registered User
    Join Date
    Apr 2012
    Posts
    4
    oh and if youre not trying to be a jerk, then you should write the name of the book that you would recommend first, then say bunch of ........ about my intelligence which i will ignore later. but thanks for the effort though

  5. #5
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    im just making a very simple interpreter
    If you pull your head from your bum you'll find that the progression I spelled out for you will in the fullness of time teach you most everything you need to know without overwhelming you with theoretical parsing.

    i'll search for the scans or ebooks
    O_o

    That was the wrong thing to say.

    Soma

  6. #6
    Registered User
    Join Date
    Apr 2012
    Posts
    4
    thanks for the craps, still waiting for some ebooks or books

  7. #7
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Well...
    Names of book regarding compiler design will be this much useful to you right now.

    Creating Interpreter for TASM from C++-resources-jpg

  8. #8
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Quote Originally Posted by phantomotap View Post
    I honestly don't think four years of computer science would be enough.
    Really ? or metaphorically ?
    I'll be joining a 3 years degree course program on Computer Science from the middle of this year and it teaches Compiler theory for the whole of the 5th semester.

  9. #9
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    [Edit]
    Are you talking about "For now, I'm not creating the full interpreter for TASM, it will just contain some basic commands like MOV, ADD, SUB, DIV, MUL." limited concept?

    Sure, you could do that without studying computer science for several years.

    I actually said that about needing more than four years because I had already thought "I just don't think that you have the knowledge to understand the books I would recommend.".

    So, the below is talking about the really fun compiler theory stuff needing more than four years of computer science to understand. You can certainly explore your way to such an interpreter without all of this stuff. Obviously, that's what I recommend, but the really fun compiler theory stuff isn't something for the faint of heart who only want to build a toy interpreter.
    [/Edit]

    ^_^

    Really. You can always "brute force" a thing, but that is an entirely different beast.

    As I said, compiler theory is a huge field. You want to know how big and complex I'm talking about? My university (4?? level class) covered three chapters (out of 18) of my $180 text book. We covered enough of the basics to write a fixed assembler for an academic "RISC" architecture.

    That didn't cover any of the parsing techniques necessary to deal with real world languages.

    Don't get me wrong, we had to do a lot of stuff. We had to write grammars for different little languages. We had to write tokenizers for arbitrary grammars specified in academic grammar specification languages. We had do lots of stuff.

    We covered basically nothing of the material needed to actual build a real interpreter. (It happened, but not at that level.)

    Dealing with transformation tables and semantic analysis of trees? We covered it; every bit of it was theory.

    You may be going to a better university than I did (I certainly hope you do.), but I doubt you'll learn enough in two years to support learning the really fun stuff. You want to know enough about formal grammars to understand real world languages like C++ in those terms? You almost certainly will not get that level of education in three years. Eh, who am I kidding? I've been studying compiler theory for nearly a decade and I still don't understand a lot of the crazier stuff.

    Of course, if you are lucky, really lucky, you'll start off learning modern theories using modern tools and grammars. I had to use *gulps* "BNF". ;_;

    Soma
    Last edited by phantomotap; 04-18-2012 at 02:08 PM.

  10. #10
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Quote Originally Posted by phantomotap View Post
    Of course, if you are lucky, really lucky, you'll start off learning modern theories using modern tools and grammars. I had to use *gulps* "BNF".
    The relevant part of the syllabus is:
    Basic concepts of compilers and interpreters. Different phases of compilation.
    Lexical analyzer concept; Design using FSM.
    Parser: Top down and Bottom up; Recursive descent; LL (1); LR (1); LALR (1); Comparison, Symbol
    tables: organization and management techniques. Runtime storage management - static
    allocation; dynamic allocation, activation records; heap allocation, recursive procedures
    Semantic Analysis - attributed translation: procedure calls. Syntax directed translation and intermediate
    codes.
    Code Optimization: Basic blocks, loop optimization, flow graph. Machine dependent optimization,
    code generation. Error handling - detection, reporting, recovery and repair.
    Compiler Writing Tools: LEX; YACC.
    Books: Principles of Compiler Design by Aho & Ullman
    I don't think it goes into much detail, but how modern would you say that is ?

  11. #11
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Quote Originally Posted by phantomotap View Post
    [Edit]
    Are you talking about "For now, I'm not creating the full interpreter for TASM, it will just contain some basic commands like MOV, ADD, SUB, DIV, MUL." limited concept?
    [/edit]
    No I wasn't... I know that it would take me, without any formal knowledge, less than an hour .
    (I did write a little lisp interpreter myself, realizing afterwards, why things are not done in the way of my design)

  12. #12
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    [Edit]
    I know that it would take me, without any formal knowledge, less than an hour .
    I figured but being me once I thought of it I had to openly consider it.
    [/Edit]

    LR (1); LALR (1)
    I stopped reading at that point to cry for a few minutes.

    LEX; YACC
    Yes, I needed another cry break.

    How modern would you say that is ?
    It isn't. It is a classic progression. That, or small variations of it, have been a standard progression for fifteen years or more.

    It is also flawed in any number of ways. The only real important flaw, and the major one, will depress you quite a lot. If you actually intend to pursue compiler theory at higher levels you will abandon a lot of what you learn here because of how difficult it is when compared with more modern tools and techniques which also just happen to be more effective for a lot of languages.

    So, unfortunately for you, you'll probably have to work fairly hard for this grade and never do anything with it. Very rarely I've used "Bison" and "Yacc" for anything, always because I needed to be compatible with something else, and nothing I learned from class could not have been discovered with a few weeks spilled out into my couch with the manuals and my laptop.

    Soma
    Last edited by phantomotap; 04-18-2012 at 02:24 PM.

  13. #13
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Quote Originally Posted by phantomotap View Post
    So, unfortunately for you, you'll probably have to work fairly hard for this grade and never do anything with it. Very rarely I've used "Bison" and "Yacc" for anything, always because I needed to be compatible with something else...
    Sad... though no use complaining.
    It probably is the norm.
    and nothing I learned from class could not have been discovered with a few weeks spilled out into my couch with the manuals and my laptop.
    I plan to do just that in the vacation before that semester (shouldn't take much time if I gather a solid knowledge of algorithms and data structures and the required math by that time) ... so I'd be able to learn some of the new stuff on my own later.

  14. #14
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    I'm currently working on a project for creating my own interpreter, a TASM interpreter.
    It's hard to recommend books for someone not interested in learning the subject in depth.
    So go ahead and give it a try on your own, if that is your wont.
    Look up flex and bison if you wish. They're kind of interesting.
    Clearly it would be fairly easy to make the limited program you've specified, especially since the specification is your own and can be up/down-graded at will.
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. TASM/turbo assambly
    By nuubik1337 in forum Tech Board
    Replies: 3
    Last Post: 12-14-2011, 03:24 PM
  2. How do I setup tasm with borland?
    By lox in forum C Programming
    Replies: 6
    Last Post: 07-11-2005, 09:44 PM
  3. TASM assembler
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 11-11-2003, 03:52 PM
  4. tasm board
    By Brian in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 12-01-2002, 03:08 PM
  5. C CGI Interpreter
    By johnc in forum C Programming
    Replies: 5
    Last Post: 07-19-2002, 12:56 PM

Tags for this Thread