Professional Documents
Culture Documents
Constructing Grammars
Mathematical Expressions
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 ) ) )