Have you ever written a compiler?

This is a discussion on Have you ever written a compiler? within the A Brief History of Cprogramming.com forums, part of the Community Boards category; I'm working on a really 'neat' project right now that involves the development of a basic opcode interpreter. It is ...

  1. #16
    Registered User
    Join Date
    Mar 2003
    Posts
    580
    I'm working on a really 'neat' project right now that involves the development of a basic opcode interpreter. It is similar to assembly in that it only interprets (and executes) a single instruction at a time. However, each 'instruction' does more than just move a number around in registers, or push and pop things in and out of memory. The only limit to the complexity is that the instruction cannot use more than a 3D vector, a scalar, and a byte (that's sort of the definition of the size of an instruction). If it uses any more than that, it gets broken down into multiple instructions.

    The cool thing about that is you can write your own programs in a text file by stringing together these basic instructions, and the opcode interpreter reads it in and basically 'compiles' a program (well, interprets it).

    This is an AI program that uses genetic algorithms to sort of evolve specimens over time such that they can execute certain types of behaviors efficiently (although they don't learn new behavior...the pinnacle of artificial intelligence research).
    See you in 13

  2. #17
    Linguistic Engineer... doubleanti's Avatar
    Join Date
    Aug 2001
    Location
    CA
    Posts
    2,459
    >BTW: The text book that we have is Compiler Construction Principles and Practice by Kenneth C. Louden

    I'm going take a rather tasty intro course on it in a short week or so, I await it but thank you for such a tip as there is no required textbook, though a recommended one. It would be nice if I could get all my lexical questions answered, top of the list: why? =)
    hasafraggin shizigishin oppashigger...

  3. #18
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,265
    I wrote an assembler before (using ASM) for a motorola 68000. I wrote a compiler for a fake language back in school. We had to write our own lex analyizer and recursive descent parser. Didn't take it all the way to machine code, although that would have been the easiest part. The BNF for the fake language only took about half a page, so I could only imagine what it would be like to write a parser, analyzer, and code generator for a language like C.

  4. #19
    Registered User
    Join Date
    Mar 2003
    Posts
    580
    Yeah, I hear ya. People that write everything required to compile C / C++ code (including everything you mentioned) are gods, nuff said.
    See you in 13

  5. #20
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    ...couldn't figure out the operators....
    What's to figure out? For Intel they are either hardcoded into the instruction or the operators are used to create a displacement and set the R/M byte to something meaningful.

  6. #21
    Just a Member ammar's Avatar
    Join Date
    Jun 2002
    Posts
    953
    Quote Originally Posted by doubleanti
    >BTW: The text book that we have is Compiler Construction Principles and Practice by Kenneth C. Louden

    I'm going take a rather tasty intro course on it in a short week or so, I await it but thank you for such a tip as there is no required textbook, though a recommended one. It would be nice if I could get all my lexical questions answered, top of the list: why? =)
    It's a nice textbook indeed, and it comes with a compiler of a "toy" language called TINY ( 4000+ line of code )which is based on Pascal... and it goes towards making a compiler of a language called C- ( C minus ) which is simmilar to C but simpler, but at the same time more complex than TINY. It discusses many methods for each phase of the compiler.

    And thank you all for your input.
    none...

  7. #22
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    What's to figure out?
    Whoa... operators was a crappy word choice... Operands would make more sense

    I had a very old book technical book on using DOS's deeper features, and it had several chapter on assembly, and an apendix listing, among other things, the binary equivalents of each instruction. So that made it easy. I just tokenized the whole thing and ran each token through a switch/case loop, and if strcmp equaled zero, then the appropriate char was read on to the file. The problem came when I was trying to figure out what to do with the : at the end of labels, commas between operands, and whether I should reverse byte order from what was in the book. I had tonnes of questions and couldn't find any tutorials on the subject. I posted a couple of threads but eventually lost interest. That's why I said I'd probably go back to it sometime, but not soon - I'm really engrossed in my server.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C Compiler and stuff
    By pal1ndr0me in forum C Programming
    Replies: 10
    Last Post: 07-21-2006, 12:07 PM
  2. I can't get this new compiler to work.
    By Loduwijk in forum C++ Programming
    Replies: 7
    Last Post: 03-29-2006, 06:42 AM
  3. how to call a compiler?
    By castlelight in forum C Programming
    Replies: 3
    Last Post: 11-22-2005, 11:28 AM
  4. Help With finding a compiler
    By macman in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 04-15-2005, 09:15 AM
  5. C Compiler
    By SAMSEIED in forum C Programming
    Replies: 5
    Last Post: 06-06-2002, 06:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21