we have a grammar as follow:
<Main Program> ::= 'begin:' <Statements>
<Statements> ::= <Statement> <Statements>
| <Statement>
<Statement> ::= <Function Calls> ';'
| <Assignments> ';'
| <IfThen>
| <SelectCase>
| <For>
| <While>
| ';'
When user want to run the script, we create the REDUCTION object first, then
using this final object, we iterate items in it. The code is:
Private Function ExecuteScript(reduksi as Reduction) as Object
For i = 0 To reduksi.TokenCount - 1
RulePerformed = False
Select Case reduksi.Tokens(i).Kind
Case SymbolTypeNonterminal
Select Case reduksi.ParentRule.TableIndex
Case
Rule_Otherfunction_Calculateovertimesalary_Lparan_Comma_Comma_Rparan
tempval_v(1) =
ExecuteScript(reduksi.Tokens(2).Data) ' <=== This is the PROBLEM,
recursive function !
.
.
.
case ...
.
.
.
End Select
End Select
Next
End Function
The problem is, as the script grow larger and larger, the parse tree will be
deeper. The deeper the parse tree,
the deeper our recursive function will be, and STACK OVERFLOW occured.
Example: hundred of simple statement like this:
a := 1:b := 2;c := 3....
will cause the parse tree deeper and deeper.
Now, my question, is there any way to write a grammar to overcome this
problem?
Parse tree for statement "a:=1" should be in the same level as "b:=2" etc...
Currently, statement "b:=2" is put as a child node under "a:=1" (recall our
grammar design),
so when the script grow larger, the tree become so deep to be handled.
Please advise.
Thank You.
[Non-text portions of this message have been removed]