## [xcodeitalia] Re: Parser 0.2

• From: Gaspard JANKOWIAK <gasp.janko@xxxxxxxxx>
• To: xcodeitalia@xxxxxxxxxxxxx
• Date: Mon, 17 Mar 2008 20:19:19 +0100

```        Wow, it's nice that you've been able to do something with NSScanner,
```
because I couldn't. It's painful to tell "scan for this, scan for that". I'm afraid that we won't get something which is kind of resilient without some Language theory, because what we are doing (as I've been told), is quite close to compiling.
```
```
My idea for now is to try to build up a binary tree for evaluation. If you don't see what
```I mean, let's take ((x^2+2)*Pi).
The aim is :

[*]
/   \
/       \
/         \
[+]         [Pi]
/ \
/   \
[^]   [2]
/   \
/      \
[x]      [2]

Then evaluation is easy. You just have to do an infix walk of the tree.

```
To do that first I need to strip the expression for parenthesis ((x^2+2)*Pi)=>(x^2+2)*Pi
```then walk the string and count the pars in i : ( is +1   ) is -1.
```
Then when i=0, we look for the least priority operator, then split the string at this point, making the operator a node, and apply recursively the process until we reach the end.
```
```
I haven't been able to code that right now, and I'm trying to find some other way of doing things.
```
See ya,

Gaspard.```