Our server costs ~$56 per month to run. Please consider donating or becoming a Patron to help keep the site running. Help us gain new members by following us on Twitter and liking our page on Facebook!
Current time: August 2, 2025, 11:21 am

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Complicated AST manipulation looks ugly in C++. How to refactor it?
#17
RE: Complicated AST manipulation looks ugly in C++. How to refactor it?
(January 27, 2022 at 2:16 pm)Jehanne Wrote:
(January 27, 2022 at 8:36 am)FlatAssembler Wrote: C is not good at doing high-level stuff. C++ is good at both high-level and low-level stuff.

Isn't that the whole point of a compiler, to translate computer code into machine code?

No, that is what the assembler is doing. An assembler is translating computer code (assembly code) into machine code. A compiler is translating computer code into assembly code. A compiler does not have to deal with machine code at all, that is the assembler's job. By the way, I have also written an assembler, as a part of PicoBlaze Simulator in JavaScript.

(January 27, 2022 at 5:29 pm)HappySkeptic Wrote:
(January 27, 2022 at 2:16 pm)Jehanne Wrote: Isn't that the whole point of a compiler, to translate computer code into machine code?  I would ditch the C++ and just use C, modeling your new language on an existing one.  C#, after all, "borrowed" heavily from Java.

Anyone writing complex code in C is crazy or a masochist.  C++ at least has the standard template library (even if it is a pain to learn).

Using C++ allows Flat to potentially compile his compiler into any platform, including webassembly.  Yes, that can be done with other languages, but it isn't easy with garbage-collected languages.

Why would C++ Standard Template Library be pain to learn? I used it on programming competitions back when I was 13 years old.

Yeah, my compiler can basically run anywhere there is a C++11 compiler, including FreeDOS. But it cannot really be used on FreeDOS because, well, the assembler it is targetting, `wat2wasm` from WebAssembly Binary Toolkit, cannot be run on FreeDOS. Or at least I have not managed to run it there. It would definitely need to be cross-compiled somehow since CMAKE, the build system WebAssembly Binary Toolkit is using, does not run on FreeDOS either.

(January 27, 2022 at 5:58 pm)Angrboda Wrote:
(January 27, 2022 at 5:29 pm)HappySkeptic Wrote: Anyone writing complex code in C is crazy or a masochist.  C++ at least has the standard template library (even if it is a pain to learn).

Using C++ allows Flat to potentially compile his compiler into any platform, including webassembly.  Yes, that can be done with other languages, but it isn't easy with garbage-collected languages.

It's a matter of trade-offs.  Hand-optimizing C is a lot more effective than trying to optimize object-based code.  Time is money with compliers.

With modern computers, development time is far more expensive than the time the program takes to run.
Reply



Messages In This Thread
RE: Complicated AST manipulation looks ugly in C++. How to refactor it? - by FlatAssembler - January 29, 2022 at 1:26 am



Users browsing this thread: 2 Guest(s)