Académique Documents
Professionnel Documents
Culture Documents
12 de septiembre de 2016
2 Ejercicios
The idea of exhaustive search parsing for a string is to generate all strings of
length no greater than |w |, and see if w is among them.
The idea of exhaustive search parsing for a string is to generate all strings of
length no greater than |w |, and see if w is among them.
The restrictions that are placed on the grammar will allow us to generate any
string w L in at most 2 |w | 1 derivation steps.
The idea of exhaustive search parsing for a string is to generate all strings of
length no greater than |w |, and see if w is among them.
The restrictions that are placed on the grammar will allow us to generate any
string w L in at most 2 |w | 1 derivation steps.
Ejemplo:
Sea la GLC dada por
G = (V , , R, S) = ({S}, {a, b}, R, S)
donde R : S aSS/b
Al derivar la sentencia aababbb, se obtiene:
S aSS
1 leftmost derivation
Jos Antonio Rodrguez Melquiades Lenguajes Formales y Autmatas 12 de septiembre de 2016 5 / 49
Derivacin mas a la izquierda1
Ejemplo:
Sea la GLC dada por
G = (V , , R, S) = ({S}, {a, b}, R, S)
donde R : S aSS/b
Al derivar la sentencia aababbb, se obtiene:
S aSS
aaSSS
1 leftmost derivation
Jos Antonio Rodrguez Melquiades Lenguajes Formales y Autmatas 12 de septiembre de 2016 5 / 49
Derivacin mas a la izquierda1
Ejemplo:
Sea la GLC dada por
G = (V , , R, S) = ({S}, {a, b}, R, S)
donde R : S aSS/b
Al derivar la sentencia aababbb, se obtiene:
S aSS
aaSSS
aabSS
1 leftmost derivation
Jos Antonio Rodrguez Melquiades Lenguajes Formales y Autmatas 12 de septiembre de 2016 5 / 49
Derivacin mas a la izquierda1
Ejemplo:
Sea la GLC dada por
G = (V , , R, S) = ({S}, {a, b}, R, S)
donde R : S aSS/b
Al derivar la sentencia aababbb, se obtiene:
S aSS
aaSSS
aabSS
aabaSSS
1 leftmost derivation
Jos Antonio Rodrguez Melquiades Lenguajes Formales y Autmatas 12 de septiembre de 2016 5 / 49
Derivacin mas a la izquierda1
Ejemplo:
Sea la GLC dada por
G = (V , , R, S) = ({S}, {a, b}, R, S)
donde R : S aSS/b
Al derivar la sentencia aababbb, se obtiene:
S aSS
aaSSS
aabSS
aabaSSS
aababSS
1 leftmost derivation
Jos Antonio Rodrguez Melquiades Lenguajes Formales y Autmatas 12 de septiembre de 2016 5 / 49
Derivacin mas a la izquierda1
Ejemplo:
Sea la GLC dada por
G = (V , , R, S) = ({S}, {a, b}, R, S)
donde R : S aSS/b
Al derivar la sentencia aababbb, se obtiene:
S aSS
aaSSS
aabSS
aabaSSS
aababSS
aababbS
1 leftmost derivation
Jos Antonio Rodrguez Melquiades Lenguajes Formales y Autmatas 12 de septiembre de 2016 5 / 49
Derivacin mas a la izquierda1
Ejemplo:
Sea la GLC dada por
G = (V , , R, S) = ({S}, {a, b}, R, S)
donde R : S aSS/b
Al derivar la sentencia aababbb, se obtiene:
S aSS
aaSSS
aabSS
aabaSSS
aababSS
aababbS
aababbb
1 leftmost derivation
Jos Antonio Rodrguez Melquiades Lenguajes Formales y Autmatas 12 de septiembre de 2016 5 / 49
Ejemplo:
donde R : S aB/bA
A aS/bAA/a
B bS/aBB/b
Al derivar la sentencia aaabbabbba, se obtiene:
En efecto
S aB aaBB
aaaBBB aaabBB
aaabbB aaabbaBB
aaabbabB aaabbabbS
aaabbabbbA aaabbabbba
Ejemplo:
donde R : S aSS/b
Al derivar la sentencia aababbb, se obtiene:
S aSS
2 rightmost derivation
Jos Antonio Rodrguez Melquiades Lenguajes Formales y Autmatas 12 de septiembre de 2016 7 / 49
Derivacin mas a la derecha2
Ejemplo:
donde R : S aSS/b
Al derivar la sentencia aababbb, se obtiene:
S aSS
aSb
2 rightmost derivation
Jos Antonio Rodrguez Melquiades Lenguajes Formales y Autmatas 12 de septiembre de 2016 7 / 49
Derivacin mas a la derecha2
Ejemplo:
donde R : S aSS/b
Al derivar la sentencia aababbb, se obtiene:
S aSS
aSb
aaSSb
2 rightmost derivation
Jos Antonio Rodrguez Melquiades Lenguajes Formales y Autmatas 12 de septiembre de 2016 7 / 49
Derivacin mas a la derecha2
Ejemplo:
donde R : S aSS/b
Al derivar la sentencia aababbb, se obtiene:
S aSS
aSb
aaSSb
aaSaSSb
2 rightmost derivation
Jos Antonio Rodrguez Melquiades Lenguajes Formales y Autmatas 12 de septiembre de 2016 7 / 49
Derivacin mas a la derecha2
Ejemplo:
donde R : S aSS/b
Al derivar la sentencia aababbb, se obtiene:
S aSS
aSb
aaSSb
aaSaSSb
aaSaSbb
2 rightmost derivation
Jos Antonio Rodrguez Melquiades Lenguajes Formales y Autmatas 12 de septiembre de 2016 7 / 49
Derivacin mas a la derecha2
Ejemplo:
donde R : S aSS/b
Al derivar la sentencia aababbb, se obtiene:
S aSS
aSb
aaSSb
aaSaSSb
aaSaSbb
aaSabbb
2 rightmost derivation
Jos Antonio Rodrguez Melquiades Lenguajes Formales y Autmatas 12 de septiembre de 2016 7 / 49
Derivacin mas a la derecha2
Ejemplo:
donde R : S aSS/b
Al derivar la sentencia aababbb, se obtiene:
S aSS
aSb
aaSSb
aaSaSSb
aaSaSbb
aaSabbb
aababbb
2 rightmost derivation
Jos Antonio Rodrguez Melquiades Lenguajes Formales y Autmatas 12 de septiembre de 2016 7 / 49
Ejemplo:
donde R : S aB/bA
A aS/bAA/a
B bS/aBB/b
Al derivar la sentencia aaabbabbba, se obtiene:
En efecto
S aB aaBB
donde R : S aB/bA
A aS/bAA/a
B bS/aBB/b
Al derivar la sentencia aaabbabbba, se obtiene:
En efecto
S aB aaBB
aaBbS aaBbbA
donde R : S aB/bA
A aS/bAA/a
B bS/aBB/b
Al derivar la sentencia aaabbabbba, se obtiene:
En efecto
S aB aaBB
aaBbS aaBbbA
aaBbba aaaBBbba
donde R : S aB/bA
A aS/bAA/a
B bS/aBB/b
Al derivar la sentencia aaabbabbba, se obtiene:
En efecto
S aB aaBB
aaBbS aaBbbA
aaBbba aaaBBbba
aaaBbbba aaabSbbba
donde R : S aB/bA
A aS/bAA/a
B bS/aBB/b
Al derivar la sentencia aaabbabbba, se obtiene:
En efecto
S aB aaBB
aaBbS aaBbbA
aaBbba aaaBBbba
aaaBbbba aaabSbbba
aaabbAbbba aaabbabbba
Muchas veces la estructura del AD se usa para asociar el significado para las
sentencias de un lenguaje; de forma similar a como se hace en el anlisis
sintctico de las sentencias del lenguaje castellano donde se identifica sujeto,
verbo, predicado, etc.
Muchas veces la estructura del AD se usa para asociar el significado para las
sentencias de un lenguaje; de forma similar a como se hace en el anlisis
sintctico de las sentencias del lenguaje castellano donde se identifica sujeto,
verbo, predicado, etc.
Si una sentencia puede ser dividida en mas de una forma durante el anlisis,
entonces puede tener diversos significados. Por eso se le llama ambigua, es
decir que una sentencia se genera por mas de una sucesin distinta de
derivaciones.
Muchas veces la estructura del AD se usa para asociar el significado para las
sentencias de un lenguaje; de forma similar a como se hace en el anlisis
sintctico de las sentencias del lenguaje castellano donde se identifica sujeto,
verbo, predicado, etc.
Si una sentencia puede ser dividida en mas de una forma durante el anlisis,
entonces puede tener diversos significados. Por eso se le llama ambigua, es
decir que una sentencia se genera por mas de una sucesin distinta de
derivaciones.
Una GLC es no ambigua, si para una sentencia existe una nica sucesin de
derivaciones mas a la izquierda y una nica derivacin mas a la derecha que
la generan.
Formalmente:
Una GLC es llamada ambigua cuando existe mas de un AD para alguna sentencia
que ella genera.
donde R : E T + E /T
F (E )/a
T F T /F
Es decir:
Una GLC es ambigua, si y solamenten si existe mas de una dmi para alguna
sentencia que ella genera.
Es decir:
Una GLC es ambigua, si y solamenten si existe mas de una dmi para alguna
sentencia que ella genera.
Una GLC es ambigua, si y solamenten si existe mas de una dmd para alguna
sentencia que ella genera.
donde R : S SbS/a
Al derivar la palabra abababa, se determina que G es ambigua ?
En efecto
...
The syntax is correct if the string es derivable from the start symbol using the
rules of the grammar. Algorithms must be designed to generate derivations
for strings in the language of the grammar. When an input string is not in the
languages, these procedures should discover that no derivations exists. A
procedure that performs this function is called a parsing algorithm or parser.
The syntax is correct if the string es derivable from the start symbol using the
rules of the grammar. Algorithms must be designed to generate derivations
for strings in the language of the grammar. When an input string is not in the
languages, these procedures should discover that no derivations exists. A
procedure that performs this function is called a parsing algorithm or parser.
The parsing algorithms use the terminal prefix of the derived string to identify
deadends. A deadend is a string that the parser can determine does not
occurr in a derivation of the input string.
The parsing algorithms use the terminal prefix of the derived string to identify
deadends. A deadend is a string that the parser can determine does not
occurr in a derivation of the input string.
The parsing algorithms use the terminal prefix of the derived string to identify
deadends. A deadend is a string that the parser can determine does not
occurr in a derivation of the input string.
(b) REMOVE(Q) returns the item at the front and deletes it from the queue.
(c) EMPTY(Q) is a boolean function that returns true if the queue is empty,
false otherwise.
(b) REMOVE(Q) returns the item at the front and deletes it from the queue.
(c) EMPTY(Q) is a boolean function that returns true if the queue is empty,
false otherwise.
The process of generating the successors of a node and adding them to the
search tree is called expanding the node. Utilizing the queue, nodes are
expanded level by level, resulting in the breadthfirst construction of T.
A parser must not only be able to generate derivations for strings in the language;
it must also determine when strings are not in the language. The bottom branch
of the search tree can potentially grow forever.
(a) PUSH([u, i] , S) places the stack item [u, i] on the top of the stack S.
(b) POP(S) returns the top item and deletes it from the stack.
(c) EMPTY (S) is a boolean function that returns true if the stack is empty,
false otherwise.
(a) PUSH([u, i] , S) places the stack item [u, i] on the top of the stack S.
(b) POP(S) returns the top item and deletes it from the stack.
(c) EMPTY (S) is a boolean function that returns true if the stack is empty,
false otherwise.
(a) PUSH([u, i] , S) places the stack item [u, i] on the top of the stack S.
(b) POP(S) returns the top item and deletes it from the stack.
(c) EMPTY (S) is a boolean function that returns true if the stack is empty,
false otherwise.
(a) PUSH([u, i] , S) places the stack item [u, i] on the top of the stack S.
(b) POP(S) returns the top item and deletes it from the stack.
(c) EMPTY (S) is a boolean function that returns true if the stack is empty,
false otherwise.
When this choice results in a deadend, the next T rule is applied. Using the
prefix matching condition, the parser eventually determines that the rule A T
applied to (A) cannot lead to a derivation of (b + b). At this point the search
returns to the node (A) and constructs derivations utilizing the A rule A A + T .
By beginning the search with the input string p, the only derivations that are
produced by a bottomup parser are those that can generate p. This serves
to focus the search and limit the size of the search tree generated by the
parser.
By beginning the search with the input string p, the only derivations that are
produced by a bottomup parser are those that can generate p. This serves
to focus the search and limit the size of the search tree generated by the
parser.
Example:
The reductions are generated by the shift and compare technique described
for the breadthfirst algorithm.
The reductions are generated by the shift and compare technique described
for the breadthfirst algorithm.
The order in which the reductions are processed is determined by the number
of shifts required to produce the match and the ordering of the rules.
The reductions are generated by the shift and compare technique described
for the breadthfirst algorithm.
The order in which the reductions are processed is determined by the number
of shifts required to produce the match and the ordering of the rules.
The reductions are generated by the shift and compare technique described
for the breadthfirst algorithm.
The order in which the reductions are processed is determined by the number
of shifts required to produce the match and the ordering of the rules.
2 Ejercicios
donde R : S aS/Sb/ab/SS
(1.1) Dar una expresin regular para L(G ).
(1.2) Construir dos derivaciones mas a la izquierda para la palabra aabb.
(1.3) Construir AD para la pregunta (1,2).
donde R : S ASB/ab/SS
A aA/
B bB/
(2.1) Dar una expresin regular para L(G ).
(2.2) Construir derivaciones mas a la izquierda y a la derecha para la palabra aaabb.
(2.3) Muestre que G es ambigua.
donde R : S aSb/aAb
A cAd/B
B aBb/
(3.1) Dar una definicin terica del L(G ).
(3.2) Muestre que G es ambigua.