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.
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.
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.
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.