You are on page 1of 2

Tarea 2 Grammars

Constructing Grammars

4) Find a grammar for each language


a) {am bn∨m, n ∈ N }
R S → AB where A → Λ∨Aa∧B → Λ∨bB
b) {am bc n∨m ,n ∈ N }
R S → AbC where A → Λ∨ Aa∧C → Λ∨cC
c) { am bn|m, n ∈ N where m>0 }
R S → AB where A → a∨aA∧B→ Λ∨bB
d) { am bn|m, n ∈ N where n> 0}
R S → AB where A → Λ∨aA∧B → b∨bB
e) { am bn|m, n ∈ N where m>0∧n>0 }
R S → AB where A → a∨aA∧B→ b∨bB
5) Find a grammar for each language
a) The even palindromes over { a , b , c } .
R S → aSa|bSb|cSc∨ Λ
b) The odd palindromes over { a , b , c } .
R S → a|b|c∨aSa|bSb|cSc
c) { a2 n∨n ∈ N } ∪ { b 2 n+1∨n ∈ N }
R S →T |U where T → Λ| aaT ∧U → b∨bbU
d) { an b c n∨n ∈ N } ∪ { b m an∨m , n ∈ N }
R S →T |U where T →b| aTc∧U → BA where B → Λ|bB∧ A → Λ|aA
e) { am bn∨m , n ∈ N where m> 0∨n> 0 }
R S → aAB| ΛBb∧ A → Λ|aA∧B → Λ∨bB

Mathematical Expressions

6) Find a Grammar for each of the following languages.


a) The set of binary numerals that represent odd natural numbers.
R 0 → B 1 where B → Λ|B 0| B 1
b) The set of binary numerals that represent even natural numbers.

1
Tarea 2 Grammars

R E → B 1∧B → Λ|B 0| B 1
c) The ser of decimal numerals that represent odd natural numbers.
R 0 → D 1|D 3| D5|D 7| D 9∧D→ Λ|D 0| D1||D 2| D 3| D 4|D 5| D 6∨D 7|D 8| D 9
7) Find a grammar for each of the following languages.
a) The set of arithmetic expressions that are constructed from decimal numerals, +, and
parentheses. Examples: 17, 2+3, (3+(4+5)), and 5+9+20.
R S → D |s+ s|( s )
b) The set of arithmetic expressions that are constructed from decimal numerals, -
(subtraction), and parentheses, with the property that each expression has only one
meaning. For example, 9-34-10 is not allowed.
R S → D∨( s +s )
8) Let the letters a, b and c be constants; let the letters x, y, and z be variables; and let the letters f
and g be functions of arity 1. We can define the ser of terms over these symbols by saying that
any constant or variable is a term and if t is a term, then so are f(t) and g(t).
a) Find a grammar for the set of terms.
R
S →U |V where U → f (t ) where t → a|b|c| x| y| z∧V → g ( t ) where t → a|b|c |x| y ∨z
b) Find a derivation for the expression f ( g( f ( x))) .

R S → f ( s ) → f ( g ( s ) ) → f ( g ( f ( s) )) → f ( g ( f ( x ) ))
9) Let the letters a, b and c be constants; let the letters x, y, and z be variables; and let the letters f
and g be functions of arity 1 and 2, respectively. We can define the ser of terms over these
symbols by saying that any constant or variable is a term and if s and t are term, then so are f(t)
and g(s,t).
a) Find a grammar for the set of terms.
R
S →U |V where U → f (t ) where t → a|b|c| x| y| z∧where V → g ( t , s ) where t → a|b| c|x| y| z∧S → a| b|c|x
b) Find a derivation for the expression f ( g( x , f (b))).

R S → f ( s ) → f ( g ( x , s) ) → f ( g ( x , f ( s ) ) ) → f ( g ( x , f ( b ) ) )

You might also like