LinuxQuestions.org
Help answer threads with 0 replies.
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 09-19-2016, 01:06 PM   #46
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941

When specifying your grammar, I think that it is very important that you explicitly state the precedence of all operators, and left/right bindings and so on. "Don't rely on any defaults: say it."

I also strongly suggest that you study the code that is produced. Study the source-code of the actual parsing engine as it works through the data structures that are the output of the compiled grammar. It needs to "stop being a mystery, to stop being 'a black box' in your mind," as soon as possible.

Last edited by sundialsvcs; 09-19-2016 at 01:07 PM.
 
Old 09-19-2016, 01:54 PM   #47
dedec0
Senior Member
 
Registered: May 2007
Posts: 1,372

Original Poster
Rep: Reputation: 51
Quote:
Originally Posted by sundialsvcs View Post
When specifying your grammar, I think that it is very important that you explicitly state the precedence of all operators, and left/right bindings and so on. "Don't rely on any defaults: say it."

I also strongly suggest that you :study: study :study: the code that is produced. Study the source-code of the actual parsing engine as it works through the data structures that are the output of the compiled grammar. It needs to "stop being a mystery, to stop being 'a black box' in your mind," as soon as possible.
Writing them all would be my choice, sundialsvcs. :)

Studying the generated code... seems good. I will try it sometime. For now, my aim is to get a full working flex+bison+cc compiler with some optimization for any not complicated language. I imagine that using it for more complex languages/tasks/optimizations can be smooth.
 
Old 09-19-2016, 02:44 PM   #48
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
The book itself is VERY incomplete - basically unusable.

Even the stack machine included is incomplete (it doesn't detect stack overflow/underflow for one, missing PC out of range, memory range limits too).

The book LOOKS like a draft copy, not a final copy.

1. The problems you have seen are due to poor choice of grammar. It is not necessary (though sometimes simpler) to use %left/%right anywhere - but you do have to be careful with the grammar rules.

2. The incorrect use of some terminology... It is almost like this was being translated from something done earlier, but hasn't yet been polished.

3. Missing examples - Optimization is an important section - yet it is nearly empty other than a little introductory text. Completely left out is algebraic optimization, a little constant folding (barely mentioned)...

4. code generation is mostly skipped.

5. Unspecified references for "further reading"...

You get better examples from the "Lex and Yacc" book, though they won't go into optimization (which is a rather complex subject on its own).

Last edited by jpollard; 09-19-2016 at 03:00 PM.
 
Old 09-19-2016, 02:52 PM   #49
dedec0
Senior Member
 
Registered: May 2007
Posts: 1,372

Original Poster
Rep: Reputation: 51
Quote:
Originally Posted by jpollard View Post
The book itself is VERY incomplete.

Even the stack machine included is incomplete (it doesn't detect stack overflow or underflow for one).

The book LOOKS like a draft copy, not a final copy.
I agree with you, but I probably cannot see it as clearly as you (because I am trying to learn from it).

I have done some work to produce the files I showed here, with things until chapter 4. If they are close to being a full compiler, I would like the help of people that are reading this thread. If they are not so close, please point that detail, so I do not expend more time with this idea.
 
Old 09-19-2016, 03:08 PM   #50
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
The basic problem is that you need a decent book. This is not one of them.

You might try http://gnuu.org/2009/09/18/writing-y...-toy-compiler/

I haven't gone through this - but the organization behind it do know what they are doing.
 
1 members found this post helpful.
Old 09-19-2016, 03:14 PM   #51
dedec0
Senior Member
 
Registered: May 2007
Posts: 1,372

Original Poster
Rep: Reputation: 51
Quote:
Originally Posted by jpollard View Post
The basic problem is that you need a decent book. This is not one of them.

You might try http://gnuu.org/2009/09/18/writing-y...-toy-compiler/

I haven't gone through this - but the organization behind it do know what they are doing.
Thank you! I have read its first page, the only thing that I would not choose is the use of llvm - but I will try that, anyway. llvm is something that have been close to me for sometime...

"gnuu" is a domain I have not seen before. Funny...
 
Old 09-19-2016, 07:20 PM   #52
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
These are among the various (widely-held ...) sentiments that prompt me to encourage you to "use the Source, Luke!"

I have read a great many books on compilers, and, with the possible(??) exception of Aho's book, I have yet to read a single decent one.

Therefore, I say, Get Jiggy Wit It, as soon as possible. Surf GitHub for existing projects which actually(!) use(!!) Bison. Find their grammar files, and the associated code which uses the Bison-generated parser. "This is the Real Deal, baby!"

Take the output of the Bison step and actually look at it. Study the actual source-code of the runtime engine. Rip the hood and both fenders off of the damned thing, and look at it, until you can see for yourself how it actually w-o-r-k-s.

You've spent more than enough time "reading books about swimming." Go find some actual examples. Then, after tightly securing your life-vest and your foam noodles, get into the water!

Last edited by sundialsvcs; 09-19-2016 at 07:21 PM.
 
  


Reply

Tags
bison



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
flex bison question sujandasmahapatra Programming 2 11-17-2012 08:30 AM
[Flex & Bison] How to check which state Flex is in? courteous Programming 0 06-03-2011 11:46 AM
Is there any support for bison-bridge and bison-locations in flex on windows systems? rami alkhateeb Linux - Software 0 12-29-2010 09:10 AM
flex and bison saurav.nith Linux - General 1 04-06-2010 06:38 AM
bison / flex zaman Programming 1 08-16-2005 10:19 AM

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

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