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 03-25-2010, 03:17 PM   #91
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443

Original Poster
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723

Quote:
Originally Posted by smeezekitty View Post
GCC is written with L&Y.
AFAIK GCC's parser is written by hand (correct me if I'm wrong).
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 03-25-2010, 03:19 PM   #92
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Rep: Reputation: 231Reputation: 231Reputation: 231
Download GCC source and you will see there is .l and .y files.
 
Old 03-25-2010, 03:21 PM   #93
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443

Original Poster
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
I guess I will download GCC's source and see. I might learn something from it, too.
 
Old 03-25-2010, 03:38 PM   #94
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Rep: Reputation: 231Reputation: 231Reputation: 231
Attached.
Attached Files
File Type: txt gcc_4_yacc.y.txt (88.8 KB, 35 views)
 
Old 03-25-2010, 04:02 PM   #95
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by MTK358 View Post
Still,

what is so bad about Lex and YACC?

OK, so they use tokens, but as long as you can easily pass their semantic value, who really cares? And even so, that's not my main problem, which is the AST (which exists no matter what parser you use).
The bad thing about lex and yacc is that they make me think unnaturally using entities beyond the necessary.

Another bad things is that they hide from me the relationship between language constructs and callbacks.

The AST is not a problem when you construct it.

Last edited by Sergei Steshenko; 03-25-2010 at 04:03 PM.
 
Old 03-25-2010, 04:08 PM   #96
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443

Original Poster
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Quote:
Originally Posted by Sergei Steshenko View Post
The AST is not a problem when you construct it.
Even with Lex/YACC, you still construct the AST.

I tried writing my own parser, and not only did you have to deal with the AST the same amound as with Lex/YACC, you still have to worry about dealing with precedence, etc.
 
Old 03-25-2010, 04:22 PM   #97
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by MTK358 View Post
Even with Lex/YACC, you still construct the AST.
...
you still have to worry about dealing with precedence, etc.
Yep - in Perl a hash deals with them nicely. I.e. my piece of code parsing expressions uses such a hash/table, so not a problem to add an operation with its precedence.
 
Old 03-25-2010, 04:24 PM   #98
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443

Original Poster
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
The problem is not in knowing the precedence of the operator, but implementing it.

At the very least, is there some simple explanation on the Internet of how the parsing algorithm works?
 
Old 03-25-2010, 04:47 PM   #99
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by MTK358 View Post
The problem is not in knowing the precedence of the operator, but implementing it.

At the very least, is there some simple explanation on the Internet of how the parsing algorithm works?
About implementing precedences - look for

expression parsing
.

About parsing algorithm - you are starting from a wrong end. Take a piece of paper and/or a text file and describe actions your eyes and your finger(s) perform when you formally analyze a piece of code.

FWIW, fingers are very good analogues of pointers - I am serious.

Again, describe in in plain English how you come to the conclusion that in, say,

Code:
abc = def;
fgh = 123;
xcv = ();
the first two lines/entities are correct and the third is wrong.
 
Old 03-25-2010, 04:53 PM   #100
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443

Original Poster
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Because there is no rule that includes parens except for a function call, where an inentifier is supposed to precede them.
 
Old 03-25-2010, 05:04 PM   #101
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by MTK358 View Post
Because there is no rule that includes parens except for a function call, where an inentifier is supposed to precede them.
How did you arrive to the last line in the first place ? I.e. what did you do exactly to read the last line in the first place ?

Forget about rules you are giving to a tool made by somebody else. Start from scratch.

Assume that

Code:
abc = def;
is called identifier_to_identifier_assignment and that

Code:
fgh = 123;
is called number_to_identifier_assignment - can you write a piece of code that would recognize these two constructs and print their names ?

And then how would you formulate the error message regarding

Code:
xcv = ();
?
 
0 members found this post helpful.
Old 03-25-2010, 05:29 PM   #102
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Rep: Reputation: 231Reputation: 231Reputation: 231
xcv = (); does not necessarily have to be an error, () could be assumed to be 0.
 
1 members found this post helpful.
Old 03-25-2010, 05:33 PM   #103
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by smeezekitty View Post
xcv = (); does not necessarily have to be an error, () could be assumed to be 0.
In my set of rules it's an error. Period.
 
0 members found this post helpful.
Old 03-25-2010, 07:31 PM   #104
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443

Original Poster
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
There is a reason people don't write computer code (grammars included) in English.
 
Old 03-25-2010, 07:39 PM   #105
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by MTK358 View Post
There is a reason people don't write computer code (grammars included) in English.
Unless you can explain it in plain English, you can't do it.

Unless you can explain it in English, you can't file a bug against parser/compiler.

Again, think what you are doing with your eyes and fingers in order to check the validity of the

Code:
abc = def;
fgh = 123;
xcv = ();
example.

One short explanation from a professional programmer without any complex formalities was sufficient for me to understand how parsers are implemented. The explanation was essentially in terms of eyes/fingers.

In general, we, humans, are not that stupid compared to computers. I.e. often it is just sufficient to express in code what we normally can explain in plain English as our eyes + fingers actions.
 
  


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
lex and yacc in RHEL4 birds Linux - Software 1 06-03-2009 02:56 AM
LEX and YACC with C gr33ndata Programming 4 11-18-2007 05:12 PM
Lex and Yacc on Federo 2.0 vivekian Fedora 6 05-20-2006 09:09 AM
Lex and Yacc on Mandrake 9.2.2 Anuradha Linux - Software 0 07-02-2005 03:32 AM
Lex & YACC coolfrog Programming 3 09-25-2004 07:00 AM

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

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