User Control Parse
Example with Restricted Grammar
Example with Unrestricted Grammar
In the previous version of JFLAP, the user had no control over how to derive a certain string given a grammar. The user relied on a Brute Force Parse to ascertain whether the string is accepted or not by the grammar. In addition, the Brute Force Parse only showed one derivation or parse tree for the input string.
With User Control Parse, the user can now select which productions to apply and perform parsing.
We will begin by loading the grammar that we entered in the previous tutorial. You can either enter the grammar (shown below) or load the file restrictedGrammar.jff.
Then you can click on Input, followed by User Control Parse. After clicking User Control Parse, you should see a window that is very similar to Brute Force Parse window.
Now you can input a string and try to derive that string by choosing the production rules. Enter the string “aababb”. Then either click Start or press Enter key. The root node S will be drawn in the tree panel.
Now click on the rule that you want to apply. Let's apply production “S->aSSb”. Click on the production “S->aSSb” from the left pane. Notice that you can now click on Step. After clicking Step, your window should look like this :
*NOTE: Notice that at the bottom of the window there is a message, “Derived current String using S->aSSb production”. This message tells us about the last production that was applied.
Now there are two variables “S” in our leaves. If we do not specify which S we are going to apply the next S-production, the error message will pop up.
Suppose we want to apply the production “S->Bb” to the first S. We can specify which S we are going to apply the rules by clicking the leftmost variable S in the string “aSSB” at the bottom of the pane.
We can simply click on the leftmost S and click on the production rule “S->Bb”. Then click Step. Now, we have applied our desired production to the first S in our string. Your window should now look like :
Now, if we want to apply the production “B->a” to the variable “B”, we can click on this production and click Step. There is no need to specify which B to apply the production, since there is only one B in the string “aBbSb”.
You can go back to previous steps, by clicking on Previous. Click Previous, now we are back at our previous step with string “aSSb”.
Suppose we want to apply the same production to both of the S variables in “aSSb”. We can achieve this by clicking both S variables at the bottom of the panel, then select a single production rule “S->Bb”. Then click Step. In this case, the two productions are applied left to right, but only the final result is shown.
*NOTE: When you select multiple items in the bottom of the panel, you just simply need to click. There is no need for Ctrl+click. If you want to unselect the item, simply click that item again and it would be unselected.
Our new tree should look like this :
After applying the production “B->a” to both B variables, we can derive our input string. The final screen should look like one of these :
We will begin by loading the grammar that we entered in the previous tutorial. You can either enter the grammar (shown in Brutoe Force Parse – Unrestricted Grammar tutorial) or load the file unrestrictedGrammar.jff. After clicking User Control Parse, you can enter the string “aabbcc” to parse. Your window should look like this :
Now we are going to apply three productions, “S->AX”, “A->aAbc”, “A->aBbc”. Click each productions one at a time and click Step. After three steps later, your window should look like this :
Now suppose we want to apply the production “Bb->bB”. Since there is only one “Bb” present in our current string, “aaBbcbcX”, we can just click on that production and click Step. However, if there are two or more “Bb” in the string, we have to specify them by clicking desired “Bb” on the bottom panel. After clicking “Bb” at the bottom panel and applying the production “Bb->bB”. your window should look like this :
We can continue to apply more productions to attain the input string. However, those steps are quite lengthy and it is going to be not included in this tutorial (final derivations shown in Brute Force Parse – Unrestricted Grammar tutorial page).
This concludes our brief tutorial on User Control Parsing. Thanks for reading!