ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
My problems with code generation seem to be caused by the optional else clause. The desire is to have this function as it does in C++, but if I can't make that work, maybe there is a better way to do it. I could omit the optional else, but it still has to have a construct for being able to write code such as the if-else ladder. I seem to be having trouble, because the code for the if-else ladder is complicated.
I could try using labels like that. TSTRING is the type for the instruction and is needed. I "could" make an even higher level language, but that is mostly an assembly type language, and remove it in that and do some modifications to the language, but it is needed in the actual runnable language, and therefore carries over to the assembly language. T stands for type, and STRING, is a string type. The LBL instruction takes either TVOID or TSTRING. TSTRING specifies a string type label, where you could jump to it with the string name, and TVOID simply specifies a label number type jump, where you do NOT have a name. Therefore with that kind of jump, you must use a label number. You can, use a label number to jump to a string type label, but you do not have to. Since I already had label number jumps, implementing it in this way made the language more powerful, rather than just allowing a string type jump. It also allowed backward compatibility for the code I'd already written, though it isn't much.
The reason by the way, that the lower levels need the TSTRING, and cannot be assuming it in certain cases, is because it makes the syntax simpler to understand to always have an instruction, a type, and an operand. Earlier languages which were steps to this version of the language (which is a fully working language, though maybe not fully developed), had sometimes just part of it. But I decided it's clearer to always have a type, even if the type ends up being TVOID (void value). In higher levels above the assembly language, it is okay to just have a string or a value, and let the computer figure out in the lower level which value to assign it, as long as it's also specified in a way in which the user will understand it too. But for the assembly language, and the lowest level language (PNF), it is not okay. Would it make it that much easier if I created such a high level language and compiled this language to that?
That's what I meant. I know it could be done, but it would make the lower levels harder to understand. If I needed to do that, I would want a higher level language and compile to that instead.
Also, at the lowest level, 0 could be either a void value, false, the number 0, a null character, or a null string. It'd be tricky to tell which is meant. At the assembly level, where we use words instead of numbers, I could've had the assembler figure it out, but that would break it's ability to generate ANY code. Should I make a higher level that makes assembly nicer, and compile to that?
VERSION TVOID 0V
; Begin if :1
ALOAD TBOOLEAN false
CGOTOL TSTRING "iftrue_1"
GOTOL TSTRING "iffalse_or_end_1"
LBL TSTRING "iftrue_1"
VOID TVOID 0V
; End if code :1
GOTOL TSTRING "end_1"
; End if or else code :1
GOTOL TSTRING "end_1"
VOID TVOID 0V
LBL TSTRING "end_1"
; End if :1
END TVOID 0V
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.