04-26-2008, 04:33 AM

04-26-2008, 01:48 PM

Hi Ralph,

The parser is the main routine you in this challenge and is also called a parse engine.

Have a look at this link which will explain you some more on how a parser works:

http://forums.devshed.com/other-programm...12483.html

I hope that will help!

Cheers,

Frontrunner

The parser is the main routine you in this challenge and is also called a parse engine.

Have a look at this link which will explain you some more on how a parser works:

http://forums.devshed.com/other-programm...12483.html

I hope that will help!

Cheers,

Frontrunner

04-29-2008, 08:30 AM

Thank you, Frontrunner, for your link.Â I now have a fair idea of what a parser is.

04-29-2008, 10:57 AM

I tried this from QB > C. i made it do this:

the only error is that it searches from left to right so for:

Â Â (5^5)^5

it returns:

Â Â (pow( 5, 5) )pow( ,5)

but for something like this:

Â Â 5^5

it returns:

Â Â pow(5,5)

it should look from the inside brackets to the outside brackets but i don't know how to do that.

Â Â LPGÂ Â

Â Â Â

- put spaces between expressions and operators

- find the ^

- search left until it finds a space. if it sees a ) forget spaces until it comes to a (

- put "pow(" in

- do the same going right but add ")"

- put spaces in again

the only error is that it searches from left to right so for:

Â Â (5^5)^5

it returns:

Â Â (pow( 5, 5) )pow( ,5)

but for something like this:

Â Â 5^5

it returns:

Â Â pow(5,5)

it should look from the inside brackets to the outside brackets but i don't know how to do that.

Â Â LPGÂ Â

Â Â Â

04-29-2008, 07:49 PM

You are very welcome Ralph, I am glad it helped!

Hi LPG,

If I may give you a tip ?

Use an array to split the whole input string in to tokens.

This makes it easier to keep track of symbols like brackets etc. and once you know where to place the pow statement you can simply change the array.

So (5^5)^5 could look like this:

Token$(1) = "("

Token$(2) = "5"

Token$(3) = "^"

Token$(4) = "5"

Token$(5) = ")"

Token$(6) = "^"

Token$(7) = "5"

To become pow((pow(5,5)),5)

Token$(1) = "pow" + Token$(1)

Token$(2) = "(pow(" + Token$(2)

Token$(3) = ","

Token$(4) = "5"

Token$(5) = ")" + Token$(5)

Token$(6) = ","

Token$(7) = Token$(7) + ")"

Note that all tokens which are ^ simply become a comma.

The trick is to take track of the brackets!

I hope that helps.

And then one more tricky example when it comes to unary operators

If -8 - -5 = 1 - -2 ^ 2 Then

Becomes

If -8 - -5= 1- -pow(2,2) Then

Cheers,

Frontrunner

Hi LPG,

If I may give you a tip ?

Use an array to split the whole input string in to tokens.

This makes it easier to keep track of symbols like brackets etc. and once you know where to place the pow statement you can simply change the array.

So (5^5)^5 could look like this:

Token$(1) = "("

Token$(2) = "5"

Token$(3) = "^"

Token$(4) = "5"

Token$(5) = ")"

Token$(6) = "^"

Token$(7) = "5"

To become pow((pow(5,5)),5)

Token$(1) = "pow" + Token$(1)

Token$(2) = "(pow(" + Token$(2)

Token$(3) = ","

Token$(4) = "5"

Token$(5) = ")" + Token$(5)

Token$(6) = ","

Token$(7) = Token$(7) + ")"

Note that all tokens which are ^ simply become a comma.

The trick is to take track of the brackets!

I hope that helps.

And then one more tricky example when it comes to unary operators

If -8 - -5 = 1 - -2 ^ 2 Then

Becomes

If -8 - -5= 1- -pow(2,2) Then

Cheers,

Frontrunner

04-30-2008, 02:53 AM

Interesting post there Frontrunner, I've not had much time last few days to work on my entry but was stuck at the brackets stage still too anyway, will hopefully get some time to finish it soon.

04-30-2008, 03:06 AM

Hi Wildcard,

I hope it will help you to tackle the brackets.

Have a nice day.

Frontrunner

I hope it will help you to tackle the brackets.

Have a nice day.

Frontrunner

04-30-2008, 09:06 AM

Thanks Frontrunner

04-30-2008, 02:27 PM

No problem, I hope it helped!

Have a sunny dayÂ ;D

Frontrunner

Have a sunny dayÂ ;D

Frontrunner

05-03-2008, 07:16 PM

I am not sure how many of you are working on this challenge but I came along this website which might be interesting for those who use FreeBasic and want to solve this challenge.

http://www.runicsoft.com/fparser.php

Cheers,

Frontrunner

http://www.runicsoft.com/fparser.php

Cheers,

Frontrunner