Skip to main content
gamedev.net
🔒 Locked

writing a "function string" parser

Started by Crispy 4 replies 150+ views
Original Post
Crispy
Crispy
Hi, I need to write a parser that will properly read and sort such strings as: "/*y=*/ sin(x)+tan(acos(log(x-1)))/atan(x)*.45462" (i figured i''d also make any whitespaces optional. basically any valid string can be expected as input. parsing this manually seems like a menial nuisance - is there some way to "group the tasks". i''m sure people have done this, and as i''ve personally never even tried writing a text parser, i''d appreciate some help. thanks in advance, Crispy
"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared
Fruny
Fruny
Flex and Bison
or
Spirit


[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Crispy
Crispy
Thanks! I think I''ll go with Spirit (not using Java).

Crispy
"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared
keethrus
keethrus
not sure if you''d be interested, but for a computer programming class we wrote a function that took a basic math statement string like "3 + 5 * 35 - ( 7 + 3 )" and would spit out the answer, in this case: 168. the string parser wasnt that complicated, and could be added upon to support floating numbers or trig functions.

if you want the source or the pseudocode, just ask.

- jeremiah
Crispy
Crispy
quote:
Original post by keethrus
if you want the source or the pseudocode, just ask.



I wouldn''t mind educating myself if it''s well written

Crispy

"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.