Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C++ (http://www.programmingforums.org/forum15.html)
-   -   Need Help Writing A College Project! (http://www.programmingforums.org/showthread.php?t=748)

ra21vi Oct 5th, 2004 4:56 PM

hi,
I am doing a college project i just initiated to help students. Actually I want to write Grapher, a program w hich takes mathematical expression, polynomial, trigonometric, complex and real, and then plots its graph on screen, 640x480.
I need help to write down the parser and lexical analyser for the input provided by the user:
y=sin(x)+tan(x)+3*x; x:10->20
states that find the values and graph for the expression with value ranging from 10 to 20 for x;
In the program, i m only struck into writing efficient parser and lex. analy.
What i m implementing right now is:
Program Grammer:
STATEMENT operator STATEMENT
exp operator STATEMENT
STATEMENT operator exp
STATEMENT = exp operator exp
And I m using a lot of tree and stack implementation. Real clumsy, that the program shows many errors and consumes time running simple sin[x]+x
You can please help me giving any ideas, as i m really newbie in parsing and and writing parsers and lexical analyser.
If possible, please include program source code as well.
My email address(if you would like to send me the mail, ra21vi@rediffmail.com

ghostils Oct 8th, 2004 9:04 PM

Do you know Perl? Because if you do, embedding perl in a C/C++ program is trivial. You could prolly whip up a simple parser that tokenizes the strings into a much more C/C++ friendly data structure, and you could write the lexer natively.

Either that or it will be time for you to sit down with LEX/YACC and configure those tools to generate the C code for your Parser/Lexer portions of code.

I would not recomend writing the parser and tokenizer code in C by hand, its a headache, and very involved for even the simplest of grammers.

Personally I would go the perl route since I'm familiar with that language. But if you have to learn either or both, lex/yacc is probably the better solution to your problem, as those tools are specifically designed to make parsers/lexers and used to build compilers.


-ghost[iLs]


All times are GMT -5. The time now is 8:56 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC