Correct way to derive parse trees, for a given input, to show ambiguity.
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.
Read code on parser, as wanted to see how it can be modified to build a syntax tree out of the below code in C-language:
Code:
int main()
{
int i = 0, j = -1, k = 2;
if(i!=0)
i--;
else{
repeat
{
i++;
} until (i<10);
}
j = i++;
k = j--;
print("%d", i,j,k);
}
The code has .c, .h files for hand-written phases of the compiler.
Need PARSE.C, PARSE.H, SCAN.C, SCAN.H, GLOBALS.H, GLOBALS.C, UTIL.H, MAIN.C files.
There is no main(), in the TINY language, as a start symbol.
Also, want to add printf function , and function processing capability too.
That means a lot, as SCAN.C, SCAN.H, GLOBALS.H, need be modified too.
Please guide, as is it a worthwhile exercise; as the TINY language, as it is now, is quite dull.
Also, request inputs on how is the implementation possible, that accomodates such changes.
Saw code at: https://github.com/gcc-mirror/gcc/bl.../c/c-parser.cc, but that hasn't anywhere the main() function handling, or of the printf().
Read code on parser, as wanted to see how it can be modified to build a syntax tree out of the below code in C-language:
Code:
int main()
{
int i = 0, j = -1, k = 2;
if(i!=0)
i--;
else{
repeat
{
i++;
} until (i<10);
}
j = i++;
k = j--;
print("%d", i,j,k);
}
The code has .c, .h files for hand-written phases of the compiler.
Need PARSE.C, PARSE.H, SCAN.C, SCAN.H, GLOBALS.H, GLOBALS.C, UTIL.H, MAIN.C files.
There is no main(), in the TINY language, as a start symbol.
Also, want to add printf function , and function processing capability too.
That means a lot, as SCAN.C, SCAN.H, GLOBALS.H, need be modified too.
Please guide, as is it a worthwhile exercise; as the TINY language, as it is now, is quite dull.
The above question and code snippet have no obvious context and make no sense as posted.
What TINY language, exactly? As it is now, without more information the TINY language you refer to is quite unknown to anyone but yourself.
Quote:
Originally Posted by ajiten
Also, request inputs on how is the implementation possible, that accomodates such changes.
Saw code at: https://github.com/gcc-mirror/gcc/bl.../c/c-parser.cc, but that hasn't anywhere the main() function handling, or of the printf().
Again, what changes are you asking about? What have you tried and what part do you need help with?
Posting a link and asking others to plan or implement vague or unspecified changes to code found there is not the best way to use this forum.
Please review the Site FAQ for guidance in asking well formed questions. Especially visit the link from that page, How to Ask Questions the Smart Way for discussion of things to consider when asking others for help.
The above question and code snippet have no obvious context and make no sense as posted.
What TINY language, exactly? As it is now, without more information the TINY language you refer to is quite unknown to anyone but yourself.
Again, what changes are you asking about? What have you tried and what part do you need help with?
Posting a link and asking others to plan or implement vague or unspecified changes to code found there is not the best way to use this forum.
Please review the Site FAQ for guidance in asking well formed questions. Especially visit the link from that page, How to Ask Questions the Smart Way for discussion of things to consider when asking others for help.
Sorry, if still after modifications, my post is not following the guidelines, but then this is the best I could, as of now; else might be this response would need many days/weeks before posting. But, then might still need inputs in-between. So, it felt better to post this response, with the current knowledge, to get inputs.
Regarding the changes needed, need the parser to accept the given program fragment, i.e. main(), printf(), & other features, as compared to the basic features given by the code.
Hence, thought the gcc code at: https://github.com/gcc-mirror/gcc/bl.../c/c-parser.cc, might show some idea; though it would be a very big and elaborate code. But that hasn't anywhere the main() function handling, or of the printf().
Instead of referring to the gcc code, for getting an idea for the needed changes; have started to see from the code at: https://holub.com/compiler/, due to the Holub's book being built around the code for building a C-compiler. In fact, the book by Holub is freely available too, by the author at: https://holub.com/compiler/.
Hence, thought the gcc code at: https://github.com/gcc-mirror/gcc/bl.../c/c-parser.cc, might show some idea; though it would be a very big and elaborate code. But that hasn't anywhere the main() function handling, or of the printf().
The parser is not going to handle main, printf etc differently from any other function. So look at c_parser_declaration_or_fndef.
`printf` is part of `glibc` not `gcc`
`main` on the other hand has no interesting/special features; what is interesting is the hidden code that calls `main`
`printf` is part of `glibc` not `gcc`
`main` on the other hand has no interesting/special features; what is interesting is the hidden code that calls `main`
It would be highly beneficial for the class, if some progression was suggested, that starts from the Louden's book code; & then leads to Holub's book code; to finally goto gcc code.
Am lacking vision, & ability, for such a progression.
Cannot add more, as the reasons are that, have not ran either of the two books' codes.
Presently, am looking into two files (apart from the needed header files, & the main.cfile): scan.c, parser.c, in the Louden's book. But, even that is boggling enough. And, any attempt at trimming the code is not helping much.
Will run by today probably, if all is well.
In absence of a path, at best a fragmented understanding would be there, even in me; as the progression can tell a lot of things, as what was lacking in Louden's book code, that lead to Holub's book code.
Similarly, what was lacking in Holub's book code, that lead to gcc code.
Wanted to run code, till parser, i.e. the scan.h, parser.h, scan.c, parser.c, util.c, util.h, main.c, global.h.
Have confusion as the code at the start of main.c is
Code:
/* set NO_PARSE to TRUE to get a scanner-only compiler */
#define NO_PARSE FALSE
/* set NO_ANALYZE to TRUE to get a parser-only compiler */
#define NO_ANALYZE FALSE
/* set NO_CODE to TRUE to get a compiler that does not
* generate code
*/
#define NO_CODE FALSE
#include "util.h"
#if NO_PARSE
#include "scan.h" // confused as what that means, as scan.h should be included in all cases, as scanning is the first task.
#else
#include "parse.h"
#if !NO_ANALYZE
#include "analyze.h"
#if !NO_CODE
#include "cgen.h"
#endif
#endif
#endif
Also, wanted to use Eclipse on windows, with Cygwin already there, but there is permanently occurring error, with no help seemingly available on googling.
The error is: Cannot invoke "org.eclipse.cdt.core.build.ICBuildConfiguration.getBuildOutput()" because "buildConfig" is null
The reason for using Eclipse IDE, was in view of the multiple files, hence to be able to see through the linkages.
Have an earlier set of code files, that ran fine on DevC++; but now that also gives the error:
Compiler: Default compiler
Building Makefile: "C:\Dev-Cpp\projects\console\code\Makefile.win"
Executing make...
make.exe -f "C:\Dev-Cpp\projects\console\code\Makefile.win" all
g++.exe -c ../../../../Users/User/Documents/1/5/code/ackpending.c -o ../../../../Users/User/Documents/1/5/code/ackpending.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include"
The code files were concerned with a smallish network simulator, and had makefile, and many other files; and was run easily earlier.
Felt no need to share that code, but if you want can share. But, worried as why nothing, even those s/w running earlier, are not running now; and give the same error.
make.exe: *** [main.o] Error -1073741819
[...]
Have an earlier set of code files, that ran fine on DevC++; but now that also gives the error:
-1073741819 is 0xC0000005 which is the error code on Windows for access violation (aka segfault on Unix type systems). Probably this is happening due to a dll that got updated or moved. I would try reinstalling the compiler.
-1073741819 is 0xC0000005 which is the error code on Windows for access violation (aka segfault on Unix type systems). Probably this is happening due to a dll that got updated or moved. I would try reinstalling the compiler.
I got error on Eclipse too, as in my second last post.
So, request inputs if the reason for Eclipse failing compilation, is the same, or different.
Due to mention above of my earlier running code on a smallish network simulator, have put the below question here, that arose due to compiling the code of the same at onlinegdb.com, on compiling the main().
The main issue is multiple (which I feel is double declaration) of the code variables.
The shared link of the project, at onlinegdb.com is: https://onlinegdb.com/zMpQO50jG
This is though a diversion, but still want it to be addressed, as the code ran well earlier.
Also, want to add that have left hopes for running code (even the smallish network simulator) on DevC++, might be try some other IDE; but as of now, very little time left as have to somehow progress on compilers' code.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.