简体   繁体   中英

what is the LL(1) grammar for it statement?

I want to convert LALR(1) grammar to LL(1) grammar especially if statement.

I had used LALR(1) grammar for if statement

IF_Stmt -> Matched|Unmatched.
Matched -> if ( Expr_IF ) Matched else Matched | Other.
Unmatched -> if ( Expr_IF ) Matched
             |if ( Expr_IF ) Matched else Unmatched.

Here, I had realized that i have to remove Left factoring.

After that i couldn't solve epsilon production problem...

What is the LL(1) grammar for if-statement ?

IF_Stmt -> if ( Expr_IF ) Stmt Optional_Else_Stmt
Optional_Else_Stmt -> (empty-string)
                      |else Stmt.
Stmt -> if ( Expr ) Matched Optional_Else_Tail
      | Other

Matched -> if ( Expr ) Matched else Matched
         | Other

Optional_Else_Tail -> else Stmt
                    | ""

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM