LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-30-2017, 12:14 PM   #1
des_a
Senior Member
 
Registered: Sep 2006
Posts: 1,422
Blog Entries: 43

Rep: Reputation: 36
PNFASM: Expects Extra String


Quote:
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...
Here is the thread to deal with this problem.
 
Old 03-30-2017, 12:18 PM   #2
des_a
Senior Member
 
Registered: Sep 2006
Posts: 1,422

Original Poster
Blog Entries: 43

Rep: Reputation: 36
Here is my code so far:
Attached Files
File Type: txt pnfasm.lpp.txt (31.5 KB, 8 views)
File Type: txt pnfasm.ypp.txt (49.4 KB, 8 views)
 
Old 03-30-2017, 12:20 PM   #3
des_a
Senior Member
 
Registered: Sep 2006
Posts: 1,422

Original Poster
Blog Entries: 43

Rep: Reputation: 36
This extra string it requires in #define, is not just ugly and unnessassary, it produces code that won't work without manually removing the string.
 
Old 03-30-2017, 02:02 PM   #4
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,269
Blog Entries: 24

Rep: Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196
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 see this page in the Site FAQ for help in posting your questions. In particular, the link at bottom of that page, How to Ask Questions the Smart Way.

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.
 
Old 03-30-2017, 02:48 PM   #5
des_a
Senior Member
 
Registered: Sep 2006
Posts: 1,422

Original Poster
Blog Entries: 43

Rep: Reputation: 36
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.
 
Old 03-30-2017, 03:34 PM   #6
des_a
Senior Member
 
Registered: Sep 2006
Posts: 1,422

Original Poster
Blog Entries: 43

Rep: Reputation: 36
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.
Attached Files
File Type: txt pnfasm.lpp.txt (31.6 KB, 7 views)
File Type: txt pnfasm.ypp.txt (50.5 KB, 10 views)
 
Old 03-30-2017, 03:40 PM   #7
des_a
Senior Member
 
Registered: Sep 2006
Posts: 1,422

Original Poster
Blog Entries: 43

Rep: Reputation: 36
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.
 
Old 03-30-2017, 03:47 PM   #8
des_a
Senior Member
 
Registered: Sep 2006
Posts: 1,422

Original Poster
Blog Entries: 43

Rep: Reputation: 36
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.
 
Old 03-30-2017, 03:52 PM   #9
des_a
Senior Member
 
Registered: Sep 2006
Posts: 1,422

Original Poster
Blog Entries: 43

Rep: Reputation: 36
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.
 
Old 03-30-2017, 03:53 PM   #10
des_a
Senior Member
 
Registered: Sep 2006
Posts: 1,422

Original Poster
Blog Entries: 43

Rep: Reputation: 36
Hopefully that is enough information. I will try to post better initial posts in the future, but it can be tricky for me...
 
Old 03-30-2017, 05:06 PM   #11
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,269
Blog Entries: 24

Rep: Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196
Quote:
Originally Posted by des_a View Post
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.
 
Old 03-30-2017, 05:10 PM   #12
des_a
Senior Member
 
Registered: Sep 2006
Posts: 1,422

Original Poster
Blog Entries: 43

Rep: Reputation: 36
Should I put it on hold until I study compilers in its fullest?
 
Old 03-30-2017, 05:12 PM   #13
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,269
Blog Entries: 24

Rep: Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196
Quote:
Originally Posted by des_a View Post
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
 
Old 03-30-2017, 05:16 PM   #14
des_a
Senior Member
 
Registered: Sep 2006
Posts: 1,422

Original Poster
Blog Entries: 43

Rep: Reputation: 36
OK. Its a parser error by bisons code. Ill get back to you more later. Have to go to work now.
 
Old 03-30-2017, 07:32 PM   #15
des_a
Senior Member
 
Registered: Sep 2006
Posts: 1,422

Original Poster
Blog Entries: 43

Rep: Reputation: 36
Here is the trace.
Attached Files
File Type: txt trace.txt (4.7 KB, 5 views)
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Extra extra! How to use the press to promote open source LXer Syndicated Linux News 0 11-12-2014 06:41 AM
[SOLVED] Warning: mktime() expects parameter 4 to be long, string given in /home/a5663365/publ nothing07 Programming 4 06-16-2012 02:01 PM
No one expects... the Irish Inquisition! sycamorex General 9 07-25-2009 03:49 AM
Mplayer expects me to pay for codecs. wesley.bruwer Linux - Software 2 12-12-2008 08:03 AM
LXer: Fedora's Extra Packages for Enterprise Linux the Extra Mile LXer Syndicated Linux News 0 06-20-2008 10:10 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:34 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration