![]() |
| [[ Home | Forums | 3D Engines Database | Wiki | Articles/Tutorials | Game Dev Jobs | IRC Chat Network | Contact Us ]] |
|
|
#1 |
|
Valued Member
Join Date: Dec 2007
Posts: 107
|
This is a code i wrote when i had inspiration from a recent topic about designing languages.
Its a math parser, i am working for adding support for math function and maybe in the future more advanced like integration and differentiation but this goes outside my main game development interest :P I would love to know how and if you are using in your pojects, there shouldn't be any bugs , i spent much time working on error detection but something may always slip from hands. Code:
|
|
|
|
|
|
#2 |
|
DevMaster Staff
Join Date: Sep 2005
Location: The Netherlands
Posts: 1,442
|
Nice, a recursive descent parser. It could be simpler though, by using Dijkstra's Shunting Yard algorithm.
Btw, it's parantheses, not paranthesys ![]()
___________________________________________
C++ addict - Currently working on: the 3D engine for Tomb Raider: Underworld and Deus Ex 3. Last edited by .oisyn : 10-16-2009 at 02:53 AM. |
|
|
|
|
|
#3 |
|
Valued Member
Join Date: Dec 2007
Posts: 107
|
Sorry english is not my native language
|
|
|
|
|
|
#4 |
|
Valued Member
Join Date: Aug 2004
Location: Brasil
Posts: 192
|
Oh interesting, I wrote an expression parser only a month ago. I implemented the Reverse Polish Notation algorithm, though. It was used on a proprietary bytecode language for a specific system I'm involved (I got to develop the custom language...).
|
|
|
|
|
|
#5 |
|
Valued Member
Join Date: Dec 2007
Posts: 107
|
...i was expecting harsh comments...
|
|
|
|
|
|
#6 | |
|
Senior Member
Join Date: Dec 2007
Location: charleston, west virginia
Posts: 994
|
oh wow, this could actually be very useful for something like an in-game console. Nice work.
Quote:
___________________________________________
(\__/) (='.'=) This is Bunny. Copy and paste bunny into (")_(") your signature to help him gain world domination. |
|
|
|
|
|
|
#7 |
|
Valued Member
Join Date: Dec 2007
Posts: 107
|
i forget that i am not anymore in gamedev comunity :P
|
|
|
|
|
|
#8 | |
|
Senior Member
Join Date: Dec 2007
Location: charleston, west virginia
Posts: 994
|
Quote:
Do a good job there = flamed
___________________________________________
(\__/) (='.'=) This is Bunny. Copy and paste bunny into (")_(") your signature to help him gain world domination. |
|
|
|
|
|
|
#9 |
|
Senior Member
Join Date: Mar 2006
Location: perth
Posts: 884
|
This is also good if you want to use interpreted ai in your game, with real arithmetic calculations interpreted on the fly...
___________________________________________
Do you say-> "C plus plus" or "C increment." |
|
|
|
|
|
#10 |
|
Senior Member
Join Date: Aug 2004
Location: Thornhill, TO
Posts: 850
|
Cool stuff, I thought about doing something like this a while back (though more like using someone else's library ;)
For benchmarking purposes, here are my results: Core 2 Duo 1.8GHz, optimized release build VS 2008 100000 Tests. Parsing : 2 + 3 - 2 * (3 + 2) * 4 = -35 Test 1: 250 milliseconds. Result = -35 Test 2: 266 milliseconds. Result = -35 Test 3: 265 milliseconds. Result = -35 Test 4: 250 milliseconds. Result = -35 Test 5: 250 milliseconds. Result = -35 Parsing : ((1 + (2 / 3)) * 0.5) + 0.1666666 = 1 Test 1: 312 milliseconds. Result = 1 Test 2: 313 milliseconds. Result = 1 Test 3: 297 milliseconds. Result = 1 Test 4: 297 milliseconds. Result = 1 Test 5: 313 milliseconds. Result = 1
___________________________________________
http://www.nutty.ca - Being a nut has its advantages. |
|
|
|
|
|
#11 |
|
Valued Member
Join Date: Dec 2007
Posts: 107
|
It could be speeded up a little putting the term function inside the expr function, but it would be a nightmare for readability.
|
|
|
|
|
|
#12 |
|
Senior Member
Join Date: Aug 2004
Location: Thornhill, TO
Posts: 850
|
Readability and performance usually don't see eye to eye
But I think these results are not bad considering the flexibility here, which is more important.
___________________________________________
http://www.nutty.ca - Being a nut has its advantages. |
|
|
|
|
|
#13 | |
|
Senior Member
Join Date: Aug 2005
Posts: 332
|
Quote:
If you really want to see a nightmare for readability, try adding a manual follow-set based error recovery to your expression parser. I had to do this for an university assignment once. It was not nice. Good work with the parser, though ![]() Guess this is a piece of code one can reuse over and over again. Cheers, - Wernaeh
___________________________________________
Some call me mathematician, some just call me computer guy. Yet, I prefer the term professional weirdo :) |
|
|
|
|
|
|
#14 | ||||
|
Member
Join Date: Nov 2008
Location: Germany
Posts: 32
|
Quote:
Uhm, if I look at http://www.gamedev.net/community/for...rictTo=Replies, then three years later http://www.gamedev.net/community/for...rictTo=Replies under ban evasion, then I wonder what good stuff that would be in that case. Anyways, Vincenzo, so far that's good work. Let me analyze your code syntactically/cosmetically only for now: Code:
Code:
Code:
Code:
Code:
Code:
Code:
Code:
Code:
Code:
Code:
Quote:
Better use text.c_str(): Quote:
The internal representation of std::string that you are dissecting does not have a \0 (null character). Code:
edit: I forgot about your list of #includes: Code:
edit: Another issue: Code:
Quote:
___________________________________________
[~/www/ — picogen.org]
Last edited by phresnel : 10-22-2009 at 09:26 AM. |
||||
|
|
|
|
|
#15 | |
|
Senior Member
Join Date: Jan 2003
Posts: 868
|
Quote:
Thanks for the great introduction to the C++ standard, freely available to all interested, but I hope you are aware of the difference between prototyping something fast and getting a stable, clear code to the market for cash that adheres to the specs and would justify the countless hours of reading the standard. Moreover there are tools for that... I actually can't believe you waste as much time writing here than he probably needed to develop the code, which is not that bad at all. Never used includes? Who cares... Last edited by Mihail121 : 10-22-2009 at 10:12 AM. |
|
|
|
|
|
|
#16 | ||||
|
Member
Join Date: Nov 2008
Location: Germany
Posts: 32
|
Quote:
I posted a more-than-1-line-critique for a buggy program, and tried to give some hints to make it less bug-full and well-formed. I think it actually helps the OP, because he stated that he thinks that Quote:
Quote:
Anyways: What you say is "learn unportable c++ that yields undefined behaviour and trust 3rd parties to fix that for you" Quote:
See also starstutters second post which might be interesting.
___________________________________________
[~/www/ — picogen.org]
|
||||
|
|
|
|
|
#17 | ||
|
Senior Member
Join Date: Jan 2003
Posts: 868
|
Quote:
Not flamming you for anything, it's evident you are proficient with the specification, it's completely fine to provide help, it's fine to reveal bugs, it's just that my personal belief that the point of the post is to show a quick parser and nothing more. But I'm just being ignorant, most honestly your post was fully ok, sorry. Let's not start an off-topic war. P.S. Quote:
No, that's not what I've said, contact me on ICQ\Skype and I'll explain it in German ![]() |
||
|
|
|
|
|
#18 | ||
|
Member
Join Date: Nov 2008
Location: Germany
Posts: 32
|
Quote:
If my first post was a tad too offensive in some point, then I am sorry, that was not my intention. But yes, I am guilty of prosecuting not to write unportable code, and probably go into too much detail sometimes. On the other hand, I also highly welcome other peoples critique on me or my stuff, e.g. once I release picogen 0.3, I'd be happy if people point out bugs or otherwise bad/dumb code that I did not recognize. Because once written, the probability is pretty high that I'll never fix some subtleties that really needed to be. Quote:
![]()
___________________________________________
[~/www/ — picogen.org]
|
||
|
|
|
|
|
#19 |
|
Valued Member
Join Date: Dec 2007
Posts: 107
|
Thanks for your dissection, i will work to fix those 'bugs'
why posting a 3 years old rants from gamedev ? how did you know my name ? why is using namespace std , dirty ????? Last edited by v71 : 10-22-2009 at 12:52 PM. |
|
|
|
|
|
#20 | |||||
|
DevMaster Staff
Join Date: Sep 2005
Location: The Netherlands
Posts: 1,442
|
Quote:
Quote:
Quote:
Quote:
Quote:
___________________________________________
C++ addict - Currently working on: the 3D engine for Tomb Raider: Underworld and Deus Ex 3. Last edited by .oisyn : 10-22-2009 at 01:08 PM. |
|||||
|
|
|
|
|
#21 | ||||||
|
Member
Join Date: Nov 2008
Location: Germany
Posts: 32
|
Quote:
a) (the "mild" form) it might not compile at all b) (the "evil" form) intended behaviour and actual behaviour might largely vary. Think of #define macros, function overloads, template partial and explicit specializations, et al. Where is the portability when a) or b) strike? Quote:
In my opinion, blanket using statements should never exceed function scope. Scope should (imho) be as big as needed, but not bigger. Quote:
revision 0: foo.hh: Code:
Code:
revision 2048: foo.hh: Code:
Example consequence (note: bar.cc was never changed anymore!): Code:
Quote:
Code:
Code:
I am not sure whether I shall now dive into all my source code files and pull in unrelated #include files just to have NULL defined, or just follow the well established and less redundant convention of using a builtin literal that also happens to be portable. Quote:
Anyways, it is good practice to use the C++ counterparts of the C library where available. E.g., math.h defines cos and cosf, whereas cmath only defines the function name cos with three function overloads, thus reducing redundancy, improving readability of template code, helping to avoid the subtle issues when accidentally using 64bit floating point where only 32bit floating point is intended. There are some more less than irrelevant differences. cassert and assert.h are the same, but why make an exception to the rule for only the assert macro?
___________________________________________
[~/www/ — picogen.org]
|
||||||
|
|
|
|
|
#22 | |||||
|
DevMaster Staff
Join Date: Sep 2005
Location: The Netherlands
Posts: 1,442
|
Quote:
Quote:
Quote:
and obviously I meant "the" std namespace ![]() Quote:
Quote:
![]()
___________________________________________
C++ addict - Currently working on: the 3D engine for Tomb Raider: Underworld and Deus Ex 3. Last edited by .oisyn : 10-22-2009 at 03:17 PM. |
|||||
|
|
|
|
|
#23 |
|
Senior Member
Join Date: Aug 2004
Location: Thornhill, TO
Posts: 850
|
Man, you guys need to get out more
![]()
___________________________________________
http://www.nutty.ca - Being a nut has its advantages. |
|
|
|
|
|
#24 | |||||
|
Member
Join Date: Nov 2008
Location: Germany
Posts: 32
|
Quote:
Oops, okay. My intention was more to tell about #including unknown code, rather than to complain about what was MSVC once. Bad wording from my side. Quote:
Quote:
Quote:
). Okay, personal opinion.Quote:
joke aside, actually I have a significant other, enjoy pubs, and from time to time go for a walk: http://phresnel.deviantart.com/
___________________________________________
[~/www/ — picogen.org]
|
|||||
|
|
|
|
|
#25 | |
|
DevMaster Staff
Join Date: Sep 2005
Location: The Netherlands
Posts: 1,442
|
Quote:
![]() ![]()
___________________________________________
C++ addict - Currently working on: the 3D engine for Tomb Raider: Underworld and Deus Ex 3. |
|
|
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
|