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.
In my interpreter, PNF, I have now made it so that although it works as before, if the file name is a certain other extension, it will preprocess the file before it runs, and then it will run that preprocessed version. This is the start of allowing a concept similar to G++ libraries, and Windows Dynamic Link Libraries. This can also be used to download only what is needed, if it were a web application. I'm working on specifications of how that will work, but I don't know yet how it will work, and if it will require changes or not. I eventually want HTML, to support a new parameter for the APPLET tag, "language =". It could say, "Java" (or bytecode maybe), or it could say, "PNF". If it said "PNF", it would run my language, which is inherently more powerful than Java. The preprocessing feature will be the basis of downloading only what is needed, like Java already does.
There is no library for my language yet, but there might be a standard library I will write. This is the basics of making that work okay. That's why I needed a preprocessor. I could have built it into my other languages, but then I'd have to duplicate lots of code, which is a bad thing.
After making the change to PNF, I required a change to PNFASM. I required some directives to pass on to the lower level some preprocessing directives. Then I can work on the way to preprocess PNFASM itself. I'm having some trouble with it, but that's for another thread. Please stay tuned. I hope it is a simple problem though...
Your previous thread was essentially a continuation of a conversation from several months ago in which I had offered specific advice. As such, I more or less continued with it based on that prior context.
If you are going to begin another related thread, let's start with a clean slate which includes the full context of this specific issue to make the information complete and more useful, and to encourage participation of others.
I am not sure what your question here is. You say that this won't work without manually removing some string, but it is really unclear what that means. What won't work, and how does it fail? What string? What is the overall context and point of the question?
Please provide a clear and repeatable example of the problem you are having, including the input, the result with any error messages, and a description of the expected behavior, so we can understand better what the issue is. If knowledge of your PNF language is necessary to understand it, then you must provide that.
Finally, looking quickly at the posted code I see that all my comments and suggestions from previous threads concerning better use of Flex, Bison and grammar would still apply, so there is no point in repeating those, yet again. I refer you to those previous threads for my own best advice as to where to start.
Well, good point. I'll start by seeing if I can improve the code, and then repost it. No point in putting extra information here until I finish that, but it was kind of a good follow up to post this even if it somehow solves it, but I doubt it will.
There. The main thing I learned from that previous discussion, of value to my "immediate" code, is that yytext shouldn't be used in the parser. I fixed that now. I changed references to yytext, mostly to $3. Here is my code again after applying everything I learned that is helpful for here for now.
PNFASM stands for "Portable Numbers Format Assembler". It is just an assembler for PNF, which is the actual "binary" language. This makes what I see as an easier language to use than most, easier again. PNF is easy for it's TYPE of language, not actually something the average programmer would jump to using.
Because of the simple job of changing text, this "could" be done by the preprocessor I just created, but it's much better to do it with another actual program than with libraries full of code. Then we get more power later on, like for now.
The code that I am working on now, is variants from the regular syntax, and is used to pass instructions onto the assembler on how to actually assemble the file correctly.
Okay. Now for some concrete examples of tests I am trying to get to work.
hello.pasm
Code:
#PBIN#
'! This is a comment.
%define "0" "1"
VERSION TVOID 0V
PRINTLN TSTRING "Hello World!"
QUIT TVOID 0
END TVOID 0V
This is a simple Hello World program. The new directives are what to pay attention to. "#PBIN#", is a directive that tells the assembler to generate a file that will need further preprocessing before it's run by the interpreter. "'!", signals a comment to be passed onto the preprocessor.
Code:
%define "0" "1"
That is a directive that will tell the assembler to assemble in a preprocessing directive, which should assemble to:
Code:
#define "0" "1"
That preprocessing directive, in turn will tell the preprocessor to change all instances of "0", to "1". That will actually make the resulting file interpret with errors, but for the test, that's what I wanted, just to see if the code I'm working on works or not. It may technically even be a dangerous thing to ask for, but for my test, that's okay. I'm willing to take the risk, to see if it works or not.
With this code, that should be correct, it doesn't actually work right for some reason. It wants me to say:
Code:
%define "0" "1" "[some string]"
...Which will assemble to:
Code:
#define "0 "1"
"[some string]"[the rest of the file]
It passes the string onto the code as a literal string. The string shouldn't even be required in the first place. I don't see anywhere where I asked it for that string, but I've tried doing a deep cleaning and recompiling, and I get the same result. It's possible that the compiler has a cache somewhere that got corrupted, and my code is actually correct. But it may not be too.
There. The main thing I learned from that previous discussion, of value to my "immediate" code, is that yytext shouldn't be used in the parser. I fixed that now. I changed references to yytext, mostly to $3. Here is my code again after applying everything I learned that is helpful for here for now.
If that was the main thing that you learned from previous threads, then you have still missed my often stated point that your immediate code implementation is the actual root of the various problems - you are attempting to do everything in your action code and making little or no use of the lexer, parser and grammar. Your problem in this thread, on first look, appears to be yet another manifestation of not having a functional lexer, parser and grammar.
Fixing your "immediate" code does not fix that problem, and never will.
The misuse of yytext was an important but incidental point. And in that case it took a repeated explanation before you actually considered it and acted on it.
I and others here are very willing to help, but you must consider and try to understand the suggestions on offer to benefit from them.
With this code, that should be correct, it doesn't actually work right for some reason. It wants me to say:
Code:
%define "0" "1" "[some string]"
...Which will assemble to:
Code:
#define "0 "1"
"[some string]"[the rest of the file]
It passes the string onto the code as a literal string. The string shouldn't even be required in the first place. I don't see anywhere where I asked it for that string, but I've tried doing a deep cleaning and recompiling, and I get the same result. It's possible that the compiler has a cache somewhere that got corrupted, and my code is actually correct. But it may not be too.
What error are you getting that tells you to add the extra string? Is it a bison "syntax error" or something thrown from your own action code?
I see that you are building with the Bison -t option to enable debugging traces, have you looked at the trace to see how the input is being handled?
You can have it generate the trace by setting an integer yydebug variable to non-zero value in the prologue code or in your main() function and recompiling. It should produce a long but reasonable set of messages for the single line input above.
Please paste the trace here and confirm that it uses the above flex and bison code. That will tell us what the grammar is doing.
Last edited by astrogeek; 03-30-2017 at 05:13 PM.
Reason: typos
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.