parsing - Can a table-based LL parser handle repetition without right-recursion? -


I understand how an LL recurring root parser can handle the rules of this form:

  A = B *;  

With a simple loop that checks whether looping is to continue, depending on whether the letterhead matches the terminal in the first set of token B. However, I am curious about table based LL Parser: How can the rules of this form work? As far as I know, the only way to handle repetition in one way in this way is through correct-reaction, but in that case the partners are disturbed where a right-associative parse tree is not desired. is.

Because I am currently trying to write an LL (1) table-based parser generator and I am not sure how to deal with such a case without changing the intending parse tree size Be controlled.

> Grammar

Let's expand your ENNF grammar into simple BNF and assume that b

< Div class = "text" is a terminal and & lt; E & gt; is an empty string:

  A -> X-X - & gt; Bx x - & gt; & Lt; E & gt; B - & gt; B  

This grammar generates the string of the term b of any length.

To create a table of LL (1) table

, we will need to set the first and set ().

The first set

The first (α) is the string of the terminals starting with the symbols of any string grammar α < / Code>.

  Prior (A): B, & lt; E & gt; First (X): B, & lt; E & gt; Follow the first (B): b  

set

Follow (a) is a set of terminals that appear immediately Can follow (x): $ follow (b): b $ h2> table

Now we build tables based on set Can, end of the $ input marker.

  + --- + --------- + ---------- + | | B $ | + --- + --------- + ---------- + | A. A - & gt; X | A - & gt; X | | X | X - & gt; Bx X - & gt; & Lt; E & gt; | | B B - & gt; B | + --- + --------- + ---------- +  

Parser action always depends on the top of the pars stack and < / P>

  1. Terminal at the top of the purse stack:
    1. matches the input symbol: pop stack, advance for next input symbol
    2. parse error
    3. Non-terminal above the purse stack:
      1. Pars table is produced in: Apply output to stack
      2. Cell is empty: parse error
      3. < / Ol>
      4. $ Purses the head of the stack In the input:
        1. $ Input symbol: Accept the input
        2. $ is not an input symbol: parse error

      sample parse

      Let us analyze input BB initial mark and closing marker in the initial parse stack A $ .

        + ------- + ------- + - ---------- + | Stack Input | Action | + ------- + ------- + ----------- + | A $ | BB $ | A - & gt; X | | X $ | BB $ | X - & gt; Bx | B x $. BB $ | B - & gt; B | B x $. BB $ | Consumption b. X $ | B $ | X - & gt; Bx | B x $. B $ | B - & gt; B | B x $. B $ | Consumption b. X $ | $ | X - & gt; & Lt; E & gt; | | $ | $ | Accept | + ------- + ------- + ----------- +  

      Conclusion

      of you Form can be parsed without the rules

      A = B * problems, the resultant concrete purse tree for input BB will be:

      < P> parse tree


Comments

Popular posts from this blog

winforms - C# Form - Property Change -

java - Messages from .properties file do not display UTF-8 characters -

javascript - amcharts makechart not working -