: Left recursion

#

定義

編集

[1]

 ,  ,... ,  ,...

直接左再帰

編集




 


       A




 



function Expr() {
    Expr();  match('+');  Term();
}


間接左再帰

編集




 
 


  

   


 
 
 
 


  

トップダウン構文解析での左再帰対応

編集

LALR2006Frost  Hafiz [2]2007FrostHafizCallaghan [3] Haskell  PADL'08 [4]X-SAIGA

左再帰の除去

編集

直接左再帰の除去

編集

 Robert C. Moore  "Removing Left Recursion from Context-Free Grammars" [5]LL(1)



 

:

A

  ( )

  A

A

 



 

 "tail"  "rest" _tail_rest

間接左再帰の除去

編集

  -  A   

  , ...   

for i = 1 to n {


for j = 1 to i  1 {


   

 

   

 

  

}
}

注意点

編集

#




 
 
 





 
 
 
 
 


'a + a + a' 
                           Expr
                         /      \
                       Expr  + Term
                     /  |  \        \
                   Expr + Term    Factor
                    |       |        |
                  Term    Factor    Int
                    |        |
                  Factor    Int
                    |
                   Int  

 (a + a) + a  '+' 


                            Expr ---
                           /        \
                         Term      Expr' --
                          |       /  |     \ 
                        Factor   +  Term   Expr' ------
                          |          |      |  \       \
                         Int       Factor   +  Term   Expr'
                                     |           |      |
                                    Int        Factor    
                                                 |
                                                Int

 a + (a + a) '+' 

(: )


 
 
 
 
 






semantic actions[6]

BNF * 使[7]

[]

LALR使
yaccBison operator declarations  %left  %right  %nonassoc  <expr> = <expr> 'op' <expr> ambiguous

脚注

編集
  1. ^ Notes on Formal Language Theory and Parsing, James Power, Department of Computer Science National University of Ireland, Maynooth Maynooth, Co. Kildare, Ireland.JPR02
  2. ^ Frost, R. and Hafiz, R. (2006) " A New Top-Down Parsing Algorithm to Accommodate Ambiguity and Left Recursion in Polynomial Time." ACM SIGPLAN Notices, Volume 41 Issue 5, Pages: 46 - 54.
  3. ^ Frost, R., Hafiz, R. and Callaghan, P. (2007) " Modular and Efficient Top-Down Parsing for Ambiguous Left-Recursive Grammars ." 10th International Workshop on Parsing Technologies (IWPT), ACL-SIGPARSE , Pages: 109 - 120, June 2007, Prague.
  4. ^ Frost, R., Hafiz, R. and Callaghan, P. (2008) " Parser Combinators for Ambiguous Left-Recursive Grammars." 10th International Symposium on Practical Aspects of Declarative Languages (PADL), ACM-SIGPLAN , Volume 4902/2008, Pages: 167-181, January 2008, San Francisco.
  5. ^ Removing Left Recursion from Context-Free Grammars
  6. ^ サンプル https://gist.github.com/anonymous/11277124 を参照
  7. ^ サンプル https://gist.github.com/anonymous/11277136 を参照

外部リンク

編集