LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 08-11-2023, 06:38 AM   #16
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,880
Blog Entries: 1

Rep: Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871

Are you referring to the Bar-Hillel lemma? Using it to prove that common languages aren't regular?
Here are some samples:
Code:
a[0], a[a[0]], ... ad infinitum
1, (1), ((1)), ...
{return}, {{return}}, {{{return}}}, ...
 
Old 08-12-2023, 06:15 PM   #17
ajiten
Member
 
Registered: Jun 2023
Posts: 377

Original Poster
Rep: Reputation: 4
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().

Last edited by ajiten; 08-12-2023 at 07:27 PM.
 
Old 08-12-2023, 08:13 PM   #18
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: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206
Quote:
Originally Posted by ajiten View Post
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 View Post
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.

Last edited by astrogeek; 08-13-2023 at 12:22 AM.
 
Old 08-13-2023, 03:37 AM   #19
ajiten
Member
 
Registered: Jun 2023
Posts: 377

Original Poster
Rep: Reputation: 4
Quote:
Originally Posted by astrogeek View Post
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.

Very sorry to forget to have given the link to the code. It is provided in a zip format at: http://www.cs.sjsu.edu/faculty/louden/cmptext/

Want to run till parser only.

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/.

Last edited by ajiten; 08-13-2023 at 03:53 AM.
 
Old 08-13-2023, 08:24 AM   #20
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,786

Rep: Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083
Quote:
Originally Posted by ajiten View Post
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.
 
1 members found this post helpful.
Old 08-13-2023, 02:25 PM   #21
ajiten
Member
 
Registered: Jun 2023
Posts: 377

Original Poster
Rep: Reputation: 4
Quote:
Originally Posted by ntubski View Post
The parser is not going to handle main, printf etc differently from any other function. So look at c_parser_declaration_or_fndef.
Is it fine to directly go to the gcc, for getting the implementation details of main, printf function; and to see the holub book code for beginner level, is not good, at least for a beginner level, given the Louden book code is too primitive?
Have, IIT-B site at: https://www.cse.iitb.ac.in/grc/slides/, and inner folder at: https://www.cse.iitb.ac.in/grc/slides/pldi14tut-gcc/, with relevant pdf file at: https://www.cse.iitb.ac.in/grc/slide...ntrol-flow.pdf.

Last edited by ajiten; 08-13-2023 at 02:44 PM.
 
Old 08-13-2023, 02:33 PM   #22
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,880
Blog Entries: 1

Rep: Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871
`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`
 
Old 08-13-2023, 03:23 PM   #23
ajiten
Member
 
Registered: Jun 2023
Posts: 377

Original Poster
Rep: Reputation: 4
Quote:
Originally Posted by NevemTeve View Post
`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`
Please elaborate, as how the given link under gcc, i.e. https://github.com/gcc-mirror/gcc/bl...arser.cc#L2077, calls the main().
Regarding, printf function, under glib, would request again some similar link.

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.

Last edited by ajiten; 08-13-2023 at 03:41 PM.
 
Old 08-13-2023, 05:22 PM   #24
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,786

Rep: Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083
Quote:
Originally Posted by ajiten View Post
Please elaborate, as how the given link under gcc, i.e. https://github.com/gcc-mirror/gcc/bl...arser.cc#L2077, calls the main().
Regarding, printf function, under glib, would request again some similar link.
That sounds quite confused, gcc is not calling main or any functions inside the program that it is compiling. It's not an interpreter.

You can find the call to main in glibc:
https://sourceware.org/git/?p=glibc....rt_call_main.h
 
1 members found this post helpful.
Old 08-14-2023, 02:48 PM   #25
ajiten
Member
 
Registered: Jun 2023
Posts: 377

Original Poster
Rep: Reputation: 4
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.
Attached Thumbnails
Click image for larger version

Name:	Screenshot (992).png
Views:	8
Size:	230.6 KB
ID:	41482   Click image for larger version

Name:	Screenshot (993).png
Views:	6
Size:	215.8 KB
ID:	41483  

Last edited by ajiten; 08-14-2023 at 02:52 PM.
 
Old 08-15-2023, 07:33 AM   #26
ajiten
Member
 
Registered: Jun 2023
Posts: 377

Original Poster
Rep: Reputation: 4
Tried on DevC++, but met with the same fate, as the error as given in 'Compile Log' is :

g++.exe -c main.cpp -o main.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"
make.exe: *** [main.o] Error -1073741819
Execution terminated


============================

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"

make.exe: *** [../../../../Users/User/Documents/1/5/code/ackpending.o] Error -1073741819

Execution terminated



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.
Attached Thumbnails
Click image for larger version

Name:	Screenshot (1000).png
Views:	6
Size:	137.7 KB
ID:	41484  

Last edited by ajiten; 08-15-2023 at 07:47 AM.
 
Old 08-15-2023, 08:00 AM   #27
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,786

Rep: Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083
Quote:
Originally Posted by ajiten View Post
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.
 
Old 08-15-2023, 08:35 AM   #28
ajiten
Member
 
Registered: Jun 2023
Posts: 377

Original Poster
Rep: Reputation: 4
Quote:
Originally Posted by ntubski View Post
-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.
 
Old 08-15-2023, 09:59 AM   #29
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,880
Blog Entries: 1

Rep: Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871
Off: for programming, you could use WSL+Ubuntu+mcedit+gcc+make
 
Old 08-15-2023, 10:23 AM   #30
ajiten
Member
 
Registered: Jun 2023
Posts: 377

Original Poster
Rep: Reputation: 4
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.

Last edited by ajiten; 08-15-2023 at 10:32 AM.
 
  


Reply

Tags
compiler



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
Unable to understand why the given Lex program fails to recognize the given input string. ajiten Programming 11 07-11-2023 12:28 AM
LXer: Trees, B-Trees, B+Trees and H-Trees LXer Syndicated Linux News 0 07-15-2013 02:11 PM
How to Boot Linux/ Linux like OS from Pen derive kumars.nitin123 Linux - General 2 11-05-2009 11:00 PM
Unable to derive IRQ merchtemeagle Linux - Hardware 2 06-21-2007 08:14 PM
mount derive in lfs aneel Linux From Scratch 2 11-24-2005 12:23 AM

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

All times are GMT -5. The time now is 12:08 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