Author Topic: Can you help me?  (Read 9032 times)

Offline ngochuan1st

  • Jr. Member
  • *
  • Posts: 30
Can you help me?
« on: August 26, 2013, 10:28:38 AM »
how to write a simple c compiler with NASM or C???

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Can you help me?
« Reply #1 on: August 26, 2013, 12:20:05 PM »
Well, no. I can't. I've never done such a thing. I understand that writing a compiler is a common assignment for a Computer Science course, so there ought to be a lot of information on the subject. I recently came across a question over at Stack Overflow regarding a book called "Let's Build a Compiler" by Jack Crenshaw, which is apparently considered a good place to start. A search engine should find it.

I understand that, these days, we don't even write our own "lexer" and "parser", but use tools like "flex" and "yacc" and "antlr" and "bison" to generate C code to write these parts of a compiler. A program to write a program to write a program. It's a million miles from the kind of programming that interests me. "Recursive descent" sounds to me like something you'd wish on your worst enemy, not something I'd want to do!

Using Nasm would probably be a bad idea, since it would lock you into x86. If you should decide to use Nasm, I'll be glad to help you with details, if I can.

Best,
Frank


Offline encryptor256

  • Full Member
  • **
  • Posts: 250
  • Country: lv
  • Win64 .
    • On Youtube: encryptor256
Re: Can you help me?
« Reply #2 on: August 26, 2013, 12:50:14 PM »
I think, the hardest part of a compiler is it's "code interpreter", that would be my starting point, if i would like to build a compiler.
Encryptor256's Investigation \ Research Department.

Offline dogman

  • Jr. Member
  • *
  • Posts: 51
Re: Can you help me?
« Reply #3 on: August 27, 2013, 04:50:06 PM »
how to write a simple c compiler with NASM or C???

There is no simple compiler for any real language. Some compilers are simpler than others, but that doesn't mean you can write a simple C compiler ;)

Offline ngochuan1st

  • Jr. Member
  • *
  • Posts: 30
Re: Can you help me?
« Reply #4 on: August 28, 2013, 04:12:19 AM »
So, i can write a simple NASM compiler ? can you help me?

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Can you help me?
« Reply #5 on: August 28, 2013, 05:28:50 AM »
How simple do you want it? DEBUG? What do you consider a "Nasm compiler"? Nasm syntax, I suppose. Nasm-like keywords? Nasm-like macros? Nasm-like output formats? (at this point it's no longer "simple")

In any case, first open a file. No, wait. First obtain the filename. Open the file and read it into a buffer. Or maybe memory-map it. Get a character and see what "kind" of a character it is. Alpha? Might be part of a symbol, a keyword, or an instruction. Number? Probably not "legal" at the start of a line, but it might be - later on - in some circumstances. Punctuation? Part of a "matched pair" or a "singleton"? What have you got? Then get another character. At this point, "rules" come into play... and at that point you pretty much lose me.

How far can you get with that? We really don't know what kind of help you need!

Best,
Frank


Offline dogman

  • Jr. Member
  • *
  • Posts: 51
Re: Can you help me?
« Reply #6 on: September 02, 2013, 07:46:30 PM »
So, i can write a simple NASM compiler ? can you help me?

No, nobody can write a simple Intel x86 assembler. Intel is the most complicated ISA with the most complicated encoding of any common (and possibly all known) ISA in the world except maybe for Itanium, which is also Intel btw. Anybody see a pattern? ;)