The kind of macros that I might want to include in my pseudocode "language" are different from those in C/C++. Macros in C just do text replacement when the file is preprocessed. This is not incredibly helpful with code because one macro cannot be referenced from another; it's not very extensible.
I would want to use syntactic macros, which can transform the language itself. These are used primarily in the Lisp family, but can also be found in Scala and other languages. Apparently the reason macros work so well in Lisp-style languages is because Lisp's source code is very similar to Lisp data? Everything in Lisp is data made up of atoms... so a macro replacement is just another atom in the data? (at least according to this source, which is the best explanation I've found, but still kind of confusing)
PROS:
- The user can redefine anything
- The "language" would be highly scalable and extensible
CONS:
- Not really what I had in mind for this project. If the user has to define macros to extend the language then it's not just a simple converter from pseudocode to another language
- I don't fully understand macros, so how could I implement them? (this shouldn't really be a con since I don't know how to implement any of my choices at this point)
CONCLUSION:
- Macros sound cool, but I don't think they're the right tool for the job
No comments:
Post a Comment