Yes, I can explain the reasons for my choice... an hasty choice!
I have a table that contains all operators (including parentheses), for each of them is also specified the level of precedence.
The parser receives a list of all the tokens that represent the source code, which I analyze one at a time using the following rough rules:
- When I encounter an opened parenthesis I simply insert it into the syntactic tree.
- When I encounter a closed parenthesis then I "climb" the syntactic tree until its opened parenthesis, then I replace the "opened" with the "closed" one.
- The next operator will take the place of that closed parenthesis.
I do not know if I was able to explain it properly, but I can post here a portion of the source code... even if it could be more cryptic of my words!
In any case, now the system works well for the expressions that we considered. Now I'm implementing the functions call mechanism and in this case the brackets are used to define the parameters list.
regards Paolo.