| Slippery Rock University | Dr. Deborah Whitfield | Go Browns! |
|
|
| The bug | Admiral Grace M. Hopper |
Syntax
Language Recognizer &Language Generators
Formal description of Language
<if_stmt> -> if <logic-exp> then <stmt>
<if_stmt> -> if <logic-exp> then <stmt> else <stmt>
OR
<if_stmt> -> if <logic-exp> then <stmt>
| if <logic-exp> then <stmt> else <stmt>
<ident_list> -> IDENT
| IDENT , <ident_list>
<program> => begin <stmt_list> end
<stmt_list> => <stmt>
| <stmt> ; <stmt_list>
<stmt> => <var> = <expresion>
<var> => A | B | C
<expression> => <var> + <var>
| <var> - <var>
| <var>
But can't derive A+B+C
Maybe modify grammar so that <exp> ->
<exp> + <exp>
<expression> => <var> + <expression>
| <var> * <expression>
| ( <expression> )
| <var>
A = B * ( A + C )
<expression> => <expression> + <term>
| <term>
<term> => <term> * <factor>
| <factor>
<factor> => ( <expression> )
| <var>
Left Recursive
Right Recursive
<factor> => <expression> ** <factor>
| <expression>
<expression> => ( <expression> )
| <var>
<stmt> => <if_stmt>
<if_stmt> => <logic_exp> then <stmt>
| if < logic_exp> then <stmt> else <stmt>
<stmt> => matched> | <unmatched>
<matched> => if < logic_exp> then <matched> else <matched>
| any non-if stmt
<unmatched> => if <logic_exp> then <stmt>
| if < logic_exp> then <matched> else <unmatched>
<x> => A B C | AB
becomes
<x> => A B [C]
<id_list> => id | id , <id_list>
becomes
<id_list> => id {,
<id_list>
<X> => <Y> , <Z> | <Y> ; <Z>
becomes
<X> => <Y> ( , | ; ) <Z>