u0644u063au0627u062a...

This preview shows page 1 - 4 out of 10 pages.

King Khalid University College of Computer Science Computer Science Program Tutorial Manual Subject name Concept of PL Subject Code 278CSM-3 1 | P a g e Concept of programming languages tutorial Text book: Concept of Programming Languages (Robert W. Sebesta) Week1: 1. Write BNF descriptions for the following: a. A Java class definition header statement b. A Java method call statement c. A C switch statement d. A C union definition e. C float literals 2. Rewrite the following BNF to give + precedence over * and force + to be right associative. <assign> → <id> = <expr> <id> → A | B | C <expr> → <expr> + <term> | <term> <term> → <term> * <factor> | <factor> <factor> → ( <expr> ) | <id> Week2: 3. Rewrite the following BNF to add the ++ and -- unary operators of Java. <assign> → <id> = <expr> <id> → A | B | C <expr> → <expr> + <term> | <term> <term> → <term> * <factor> | <factor> <factor> → ( <expr> ) | <id> 4. Write a BNF description of the Boolean expressions of Java, including the three operators &&, ||, and ! and the relational expressions. Week3: 5. Using the following grammar, show a parse tree and a leftmost derivation for each of the following statements: <assign> → <id> = <expr> <id> → A | B | C <expr> → <id> + <expr>
King Khalid University College of Computer Science Computer Science Program Tutorial Manual Subject name Concept of PL Subject Code 278CSM-3 | <id> * <expr> | ( <expr> ) | <id> a. A = A * (B + (C * A)) b. B = C * (A * C + B) c. A = A * (B + (C)) 6. Using the grammar in Example 3.4, show a parse tree and a leftmost derivation for each of the following statements: a. A = ( A + B ) * C b. A = B + C + A c. A = A * (B + C) d. A = B * (C * (A + B)) Week 4: 7. Prove that the following grammar is ambiguous: <S> → <A> <A> → <A> + <A> | <id> <id> → a | b | c 8. Describe, in English, the language defined by the following grammar: <S> → <A> <B> <C> <A> → a <A> | a <B> → b <B> | b <C> → c <C> | c Week5: 9. Consider the following grammar: <S> → <A> a <B> b <A> → <A> b | b <B> → a <B> | a Which of the following sentences are in the language generated by this grammar?
2 | P a g e 10. Convert the the following BNF to EBNF. <program> → begin <stmt_list> end <stmt_list> → <stmt> | <stmt> ; <stmt_list> <stmt> → <var> = <expression> <var> → A | B | C
King Khalid University College of Computer Science Computer Science Program Tutorial Manual Subject name Concept of PL Subject Code 278CSM-3 3 |

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture