| fafner (221) | |
|
Jackson Marie, I don't know if this is what you're looking for, but there's a really good tutorial on a recursive-descent/operator-precedence parser for a working functional language here: http://llvm.org/docs/tutorial/ EDIT: You can disregard the llvm-stuff and just use the lexer/parser part, like I have done for several toy languages :) | |
|
Last edited on
|
|
| Jackson Marie (450) | |
|
Wow wow wow TheIdeasMan!!! I like this stack feature!!! I'll try this XDXD TheIdeasMan@!! That's it, the stack problem has been solved, only parsing process (Reading and parsing a file and do everything if possible) Now I realized that programming are only calculations and calculations, and no anything else... ) Great!!! Oh... I like this!!! Now, I'm totally ready XDXD !!! Making an interpreter is very easy, but it.. takes time... Certainly, it's always.. true. Stack? Yes. It's the most important primary thing 100%!!! I throw an object, then other machines will wait for it... And catch!!! The gigantic world, the huge world, the large world, the very big world, the big world, the medium world, the small world, the very small world, the tiny world... I'll come back soon. Hope the idea... will come true someday.... =*@TheIdeasMan!!!! | |
|
Last edited on
|
|
| helios (10126) | |||
|
Uh... TheIdeasMan's suggestion is exactly what I said two pages back: http://www.cplusplus.com/forum/lounge/85713/3/#msg464893 Both the Assembly I suggested earlier and RPN evaluation are based on a stack machine execution model. For example, the RPN string "1 2 + 3 *" translates to
| |||
|
|
|||
| TheIdeasMan (1562) | ||
|
@helios Of course, maybe there has been so much BS (by the OP) since then .... Simple ideas seem lost on the OP, she is still dead keen on the Starship Enterprise, anything simpler seems to be ignored, along with generic planning advice. As well, it is difficult to offer solutions (like your code), because she doesn't understand C++, and cannot even write C properly. Comments by the OP like this: The OP wrote:
Presumably that is an interpretation of exceptions and a try - catch block, something I mentioned as an alternative to goto. See what I mean? It's almost like she is delusional, and if I was going to be Dr. Phil, I would say she lacks self esteem and is seeking attention. I still think the best thing would be to ignore her unless she posts some credible code of something easier like what I proposed as a starting example. | ||
|
|
||
| L B (3325) | |
| @TheIdeasWoman I'm confused - perhaps I missed the part where the OP said they were female? | |
|
|
|
| TheIdeasMan (1562) | |
|
@L B HAHA Some friendly advice (In Jest of course): Anyone who thinks I am a woman (or refers to me as such) should come down here to find out in person. Upon arriving they will see it is not a good idea to eff with me. :D Ages ago she said her given name was Marie, there haven't been any objections to female references. However this whole thing (all JM's posts) could still be a very elaborate troll - so JM could be anyone. | |
|
|
|
| chrisname (5896) | |
|
@L B The OP's user profile says so. Even so, since English lacks singular gender-neutral pronouns, it's just as reasonable to call a person of unknown gender "she" as it is to call them "he". | |
|
|
|
| TheIdeasMan (1562) | |||
|
Here's some more evidence the OP doesn't understand C++: This version of helios' code uses a stack:
Line 6 is a real give away ....... It is also an example of how the OP ignores advice from experienced members. Here is the OP's reply to a mention of using a stack:
@JM are you sick of all this yet? Let's see your RPN calculator using a stack. If we do see it, then I might upgrade my opinion of you a smidgin. | |||
|
|
|||
| Jackson Marie (450) | |
|
I think I should make a tree stack structure... But I have no idea. Please help... | |
|
|
|
| helios (10126) | ||
|
Well, I was bored. http://pastebin.com/ehNr36XY Examples: Computing polar coordinates of vector (7,13) (prints theta then r) 7 13 dup 2 ^ 3 rot dup 2 ^ 3 rot + sqrt 3 rot 3 rot atan2 $ pop $ pop Sum all integers between 1 and 10: 0 1 begin dup 3 rot + swap 1 + dup 10 swap - 1 if end leave pop $ pop Numerically approximate by the trapezoid rule the definite integral of sin() between 0 and pi with a step of 1/128: 0 0 1 128 / begin dup 3 rot dup 3 rot + sin swap dup sin 3 rot + 3 rot dup 3 rot * 2 / 4 rot + 3 rot 3 rot dup 3 rot + dup 3 rot swap pi swap - 1 if end leave pop pop $ pop The problem with 0-operand instruction sets is that keeping track of intermediate results is a bitch. Hence all the 3 rot sequences.
| ||
|
Last edited on
|
||
| Jackson Marie (450) | ||
|
Ok the the stack machine is almost done. @helios, I see your code example, and I'm making a similar style which gives anyone an easy look, And editing and adding additional function features (fancy stuff..) now is very easy!!! I've included basic variable calculations (add, subtract, multiply, divide, equal, negative, modulus,...) And I'm going to add some bitwise operator detectors... A variable target pointer can be used if needed. But I got a trouble : Multiplication (x) and (:) are always performed first, then addition and subtraction... An example :
x = the final value of the expression 5 + 2 * 8 I'm going to write : x += 5 += 2 *= 8 But it's odd because it's totally wrong. It's very hard problem and when I have to handle a main expression that contains many small expressions with their variables and values, and calculation modes... But, I'm afraid of posting some code example demonstration here because... I think... But, I'm looking forward to any suggestion and opinion about any better new algorithm solution and wonderful method... | ||
|
|
||
| chrisname (5896) | |
|
@helios What operation is $? | |
|
|
|
| helios (10126) | |
| Peek and print the top. | |
|
|
|
| Script Coder (348) | ||
Am I the only one who sees through the | ||
|
|
||
| L B (3325) | |
| Tim wouldn't threaten anyone! | |
|
|
|
| Grey Wolf (3172) | |
|
♪ ♫ "TheIdeasMan and Jackson Marie in a red-black tree, F-i-g-ht-i-n-g" ♪ ♫ | |
|
|
|
| TheIdeasMan (1562) | |||||
L B is right, I mean what I say when I say "In Jest of course" , my comment was more of a comical warning, coming from the comical gender replacement. Edit: L B and I just had a big ole discussion in one of his threads - a lot of ideas exchanged, so I think we get along just fine. @Grey Wolf
I see it more as education - the more stubborn the student - the harsher the education methods. Edit: I hope you can back me up in what I am saying as you have in the past, because I see you as being one of the sensible realistic people. @JM
Don't worry, if you post the code then at least it will show that you have had a go - which would be commendable. If you started with helios' code then that is a good start. As long as you keep with the methodology. Also there would be no realistic advice that can be given unless we can see what you have done. If I can see that you have had a fair go at the problem, then I might offer some gentle suggestions. The reasons for giving harsh advice, would be for not listening to advice, or where the methodology is so far from reality that it is ridiculous, or you continue to write unconventional code, or you try to help others while exhibiting all these bad traits. Also, I may not need to offer any comment at all, there are plenty of others much more knowledgeable than me who might help. However, if you present some nightmare code, then that might be the cause of not getting any (or few) replies, and you might miss out on help from those best capable of helping. And, if you repeatedly don't listen to advice, then that is why you would attract ridicule, as opposed to constructive help. So let's see what you have, (we are all waiting to give some great advice) and we can all go from there. | |||||
|
Last edited on
|
|||||
| Jackson Marie (450) | |||
|
Finished!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! This is the stack structure tool. It supports basic calculation (+); (-); (x); (:); (%); (=); (--);... and (infinite expression world access)... I'm a chicken (beginner) so sorry I can't explain more... (!!!Max post length!!!) Here is the code (with example) :
I made debug (log) functions (CalDebug()) and PrintW() Any suggestion everybody? | |||
|
Last edited on
|
|||
| helios (10126) | |
|
Geez, your style seriously sucks. I had to run your code through Artistic Style to realize that some of your functions weren't global. The only way you could have missed the point of stack-based evaluation by a wider margin would be if you had tried to implement a ray-casting algorithm. Main problem: no data stack (!). From what I can gather based on how you're building your structures, you merely have a list of operations (more formally, a list of unary functions) that are applied one after the other. You're constructing a structure that looks like this: f1(f2(f3(f4(...fn(initial)...)))) This is much weaker than expressions of binary operations. For example, the expression (1 + 2) * (3 + 4) can't be represented like this. But the real screwed up part is the way you're using those structures. There's no rhyme or reason to it. It's less like an evaluation algorithm and more like a random number generator. That's really all I can say because I don't dare doing a detailed analysis of what exactly is going on for fear of losing my sanity. So, +1 point for listening to other people and using a stack, but -10 points for not really using the stack, then another -20 points for putting an aborted tree around the stack, then on top of that, -1048576 points for writing mindfuck code. | |
|
|
|
| chrisname (5896) | |
| Yeah, I was wondering, does this code actually work? Or even compile? | |
|
|
|