LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 08-03-2020, 01:50 AM   #1
des_a
Member
 
Registered: Sep 2006
Posts: 853
Blog Entries: 32

Rep: Reputation: 20
PNF: Even Though I Passed true to Function, Always Puts false


I am creating a suite of languages. Right now, my interpreter, PNF, is not working.

There is a concept of "functions" in my language, which are roughly like a C++ function, and not quite the same as a subroutine in my language.

The problem I am having right now, is that even though I pass true to a function, it passes false. This is a type BOOLEAN, or TBOOLEAN.

This is GPL software. I'm posting this, because I learned that it might be okay to post it:

https://www.linuxquestions.org/quest...74#post6151874

I learned about GitHub here: https://www.linuxquestions.org/quest...01#post6151501

The repository is here: http://github.com/smileynet000/PNF

I know that the problem is somewhere in the file pnf.hpp. I suspect that it changes when I'm calling the function.

This set of tools is my best experience (real world), for developing compilers and interpreters. I have been working on it since I was 15, and with some small help, I believe that I can get it to have all the features of C.

First big goal, a milestone to achieving my actual goal, not really a goal, but milestone: Have all the same features as C, essentially.

I am getting better at debugging, and hopefully, better at posting on linuxquestions.org. Thanks!

Sample test file:
Code:
funcdef 0V a(0V);
funcdef 0V b(var a: number);
funcdef 0V c(var b: string, var c: number);
funcdef 0V d(var d: string, var e: number, var f: number);
funcdef 0V e(0V);
funcdef 0V f(0V);
funcdef 0V g(var g: string);
funcdef 0V h(0V);
funcdef 0V i(var h: boolean);
funcdef 0V j(0V);
funcdef var: number k(0V);
funcdef var: boolean l(0V);
funcdef var: number, var: boolean m(0V);
funcdef 0V n(var a: boolean, var b: number);
funcdef 0V o(var a: number);


function 0V a(0V)
{
 println "a()";
 fret;
};

function 0V b(var a: number)
{
 println "b()";
 load aload 77;
 fparameter 0V b(var a: number) a number number;
 print '"';
 fparameter 0V b(var a: number) a number;
 print;
 println '"';
 fret;
};

function 0V c(var b: string, var c: number)
{
 println "c()";
 fret;
};

function 0V d(var d: string, var e: number, var f: number)
{
 println "d()";
 fret;
};

function 0V e(0V)
{
 println "e()";
 fret;
};

function 0V f(0V)
{
 println "f()";
 fret;
};

function 0V g(var g: string)
{
 println "g()";
 fret;
};

function 0V h(0V)
{
 println "h()";
 funccall 0V a(0V);
 fret;
};

function 0V i(var h: boolean)
{
 println "i()";
 fparameter 0V i(var h: boolean) h boolean;
 println;
 fret;
};

function 0V j(0V)
{
 println "j()";
 funccall 0V h(0V);
 fret;
};

function var: number k(0V)
{
 println "k()";
 load function var: number k(0V) rvalue 0 : 76;
 fret;
};

function var: boolean l(0V)
{
 println "l()";
 load function var: boolean l(0V) rvalue 0 : true;
 fret;
};

function var: number, var: boolean m(0V)
{
 println "m()";
 load function var: number, var: boolean m(0V) rvalue 0 : 75;
 load function var: number, var: boolean m(0V) rvalue 1 : true;
 fret;
};

function 0V n(var a: boolean, var b: number)
{
 println "n()";

 print "Values: ";
 fparameter 0V n(var a: boolean, var b: number) a boolean;
 print;
 print " ";
 fparameter 0V n(var a: boolean, var b: number) b number;
 println;
 fret;
};

function 0V o(var a: number)
{
 println "o()";

 print "Value: ";
 fparameter 0V o(var a: number) a number;
 println;
 fret;
};


funccall 0V a(0V);
funccall 0V b(22);
funccall 0V c("true", 77);
funccall 0V d("hello", 76, 79);
funccall 0V e(0V);
funccall 0V f(0V);
funccall 0V g("not a toy.");
funccall 0V h(0V);
funccall 0V i(true);
funccall 0V j(0V);

println "";
funccall var: number k(0V);
load rvalue 0;
print "The value returned was: ";
println;

println "";
funccall var: boolean l(0V);
load rvalue 0;
print "The value returned was: ";
println;

println "";
funccall var: number, var: boolean m(0V);
load rvalue 0;
print "The first return value was: ";
println;
load rvalue 1;
print "The second return value was: ";
println;

println "";
funccall 0V n(true, 99);

println "";
funccall 0V o(62);

end 0;
 
Old 08-03-2020, 02:08 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 15,097

Rep: Reputation: 4972Reputation: 4972Reputation: 4972Reputation: 4972Reputation: 4972Reputation: 4972Reputation: 4972Reputation: 4972Reputation: 4972Reputation: 4972Reputation: 4972
do you mean this: https://github.com/smileynet000/PNF/...-LINUX/pnf.hpp ?
That is almost 10 thousand lines long.
I would suggest you to add debug lines (similar to error messages).

Also would be nice to demonstrate this issue (probably).
 
Old 08-03-2020, 02:31 AM   #3
des_a
Member
 
Registered: Sep 2006
Posts: 853

Original Poster
Blog Entries: 32

Rep: Reputation: 20
The Linux version is behind for now. I mean in the source/WINDOWS directory.

This file: https://github.com/smileynet000/PNF/...INDOWS/pnf.hpp
 
Old 08-03-2020, 02:49 AM   #4
des_a
Member
 
Registered: Sep 2006
Posts: 853

Original Poster
Blog Entries: 32

Rep: Reputation: 20
When the interpreter, pnf, is run on the above file, it produces this output:

Code:
a()
b()
"77"
c()
d()
e()
f()
g()
h()
a()
i()
v2: false
false
j()
h()
a()

k()
The value returned was: 76

l()
The value returned was: true

m()
The first return value was: 75
The second return value was: true

n()
Values: v2: false
false 99

o()
Value: 62
It "should" produce this output:

Code:
a()
b()
"77"
c()
d()
e()
f()
g()
h()
a()
i()
v2: true
true
j()
h()
a()

k()
The value returned was: 76

l()
The value returned was: true

m()
The first return value was: 75
The second return value was: true

n()
Values: v2: true
true 99

o()
Value: 62
 
Old 08-03-2020, 02:52 AM   #5
des_a
Member
 
Registered: Sep 2006
Posts: 853

Original Poster
Blog Entries: 32

Rep: Reputation: 20
Don't know exactly where the bug is, but probably in PARAMF or PARAMF2 instructions. Those are jump to case labels prefixed with "I", in PNF::execute(). I don't know exactly what and where the bug is though...
 
Old 08-03-2020, 02:53 AM   #6
des_a
Member
 
Registered: Sep 2006
Posts: 853

Original Poster
Blog Entries: 32

Rep: Reputation: 20
The PNF file is already generated in the bin/WINODWS directory, so you don't need to build it for the test.
 
Old 08-03-2020, 02:54 AM   #7
des_a
Member
 
Registered: Sep 2006
Posts: 853

Original Poster
Blog Entries: 32

Rep: Reputation: 20
After it passes this test, it passes the function tests and I can move on.
 
Old 08-03-2020, 02:58 PM   #8
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_12{.0|.1}
Posts: 5,434
Blog Entries: 11

Rep: Reputation: 3398Reputation: 3398Reputation: 3398Reputation: 3398Reputation: 3398Reputation: 3398Reputation: 3398Reputation: 3398Reputation: 3398Reputation: 3398Reputation: 3398
@des_a - There is no question in your post which could realistically be answered by anyone else.

Repeatedly restating that you are creating a suite of languages which may someday include features which are only imagined at this time is irrelevant, as is your knowledge of github and the intended license. You have been asked in the past to not post threads which become endless discussions of your PNF language which lead nowhere and can have no answer, and this thread has every indication of being yet another of those. If this thread develops in that way it will be closed.

Please review the Site FAQ for guidance in posting your questions and general forum usage. Especially, read the link in that page, How To Ask Questions The Smart Way.

Reduce your test case code to a minimal, repeatable example which includes everything necessary for others to understand what you are asking without reliance on knowledge of your PNF language itself and without asking others to build your interpreter or run a precompiled binary, or to sift through your repo for clues to understand your question.

If it is an interpreter error then add debugging code to your interpreter which will allow you to understand what is happening. If after doing that you still cannot understand what is happening then you will at least have isolated the code to a small example along with runtime variable values which may be evaluated independently of your PNF syntax. At that point you will be prepared to post a clear question which others may be able to answer. Please make that effort.
 
2 members found this post helpful.
Old 08-03-2020, 05:29 PM   #9
Geist
Member
 
Registered: Jul 2013
Distribution: Slackware 14 / current
Posts: 435

Rep: Reputation: Disabled
Step through it with a debugger?
Edit:
A casual glance, a very casual glance cause this header file is huge, makes me wonder about your usage of "new", etc.

Go run your thing through valgrind, too. Just in case.
Also, I'm suspecting some sort of copy constructor failure, but again, this ain't fun to look through.
AlsoČ, seeing how you don't seem to bother with curlies very much when it comes to if's, it's not impossible that you messed up somewhere because of it.

Don't save in the wrong places, especially when you're still developing it. You can optimize later.

Last edited by Geist; 08-03-2020 at 05:36 PM.
 
Old 08-04-2020, 02:15 AM   #10
des_a
Member
 
Registered: Sep 2006
Posts: 853

Original Poster
Blog Entries: 32

Rep: Reputation: 20
Quote:
Step through it with a debugger?
Oops! I'd forgotten to use the debugger! This is the first real world use I've used the debugger for. The rest has been accedemic.

Quote:
AlsoČ, seeing how you don't seem to bother with curlies very much when it comes to if's, it's not impossible that you messed up somewhere because of it.
I've adopted a style from a book. If the body of the if or else is one line, I omit the curly braces. Messed up by mistake on my alignment of my switch statement, but still works there...
 
Old 08-04-2020, 02:18 AM   #11
des_a
Member
 
Registered: Sep 2006
Posts: 853

Original Poster
Blog Entries: 32

Rep: Reputation: 20
I ended up solving the problem.

The problem was I was asking to set the index to the Boolean value of the %accumulator. I needed to set it to number. Why? What I am trying to do with that instruction, is to get the function number from the %accumulator. This should be a number value. I was therefore, asking for the wrong function in just that part of the code. I guess it still matches another function...
 
Old 08-04-2020, 02:19 AM   #12
des_a
Member
 
Registered: Sep 2006
Posts: 853

Original Poster
Blog Entries: 32

Rep: Reputation: 20
Quote:
Reduce your test case code to a minimal, repeatable example which includes everything necessary for others to understand what you are asking without reliance on knowledge of your PNF language itself and without asking others to build your interpreter or run a precompiled binary, or to sift through your repo for clues to understand your question.
I was asking for help on a bug, which I described.
 
Old 08-04-2020, 02:21 AM   #13
des_a
Member
 
Registered: Sep 2006
Posts: 853

Original Poster
Blog Entries: 32

Rep: Reputation: 20
Quote:
If it is an interpreter error then add debugging code to your interpreter which will allow you to understand what is happening. If after doing that you still cannot understand what is happening then you will at least have isolated the code to a small example along with runtime variable values which may be evaluated independently of your PNF syntax. At that point you will be prepared to post a clear question which others may be able to answer. Please make that effort.
I believe you are talking about the WRITE technique. I use and remember to use that, all the time. There was extra put there for that. I just forgot to use the debugger.
 
Old 08-04-2020, 02:22 AM   #14
des_a
Member
 
Registered: Sep 2006
Posts: 853

Original Poster
Blog Entries: 32

Rep: Reputation: 20
Quote:
Please review the Site FAQ for guidance in posting your questions and general forum usage. Especially, read the link in that page, How To Ask Questions The Smart Way.
I will read that before posting another bug, if I do need to.
 
Old 08-04-2020, 03:13 AM   #15
Geist
Member
 
Registered: Jul 2013
Distribution: Slackware 14 / current
Posts: 435

Rep: Reputation: Disabled
Congrats on getting to the root of the problem.

That said, I still recommend valgrind. Very, very useful tool.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
I cannot seem to download files. Terminal always says file not found even though it exists meedo7 Slackware 9 05-12-2020 05:37 PM
Using C API; first query passed passed by program to MySQL is successful, second quer weibullguy Programming 2 06-12-2007 10:45 PM
comparison is always true/false jubaitca Programming 20 11-05-2006 06:55 PM
Kernel Panic on Pocket Linux, no init even though one was passed williamtbranch Linux - General 3 10-26-2004 01:30 PM

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

All times are GMT -5. The time now is 02:14 AM.

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