Escrito por estudiantes que aprobaron Inmediatamente disponible después del pago Leer en línea o como PDF ¿Documento equivocado? Cámbialo gratis 4,6 TrustPilot
logo-home
Resumen

Samenvatting van het vak Talen en Compilers

Puntuación
5,0
(1)
Vendido
6
Páginas
26
Subido en
26-05-2021
Escrito en
2020/2021

Samenvatting van het vak 'Talen en Compilers' aan de Universiteit Utrecht, gebaseerd op de hoorcolleges en lecture notes van de docent.

Institución
Grado

Vista previa del contenido

Languages, compilers and (context-free) grammars

What is a compiler and a parser?
A compiler translates one language into another (which is possibly the same), roughly:


Get hold of the structure of the input program attach semantics to a sequence of symbols check whether a program
makes sense optimize generate good machine code.


A parser takes a string of characters and tries to recognize a structure in the form of a tree.




Alphabet, languages and words
An alphabet is a (finite) set of symbols that can be used to form sentences, e.g.



The set of all Latin letters


Given such a set, we can consider (finite) sequences of elements of that set (in which the empty sequence is often written
as ). The set of sequences of a given set is written as and defined as:


the empty sequence is in .
if and , then is in .


(We typically use letters from the beginning of the (Latin) alphabet to represent single symbols, and letters from the end of
the alphabet to represent sequences.)


A word is a sequence of symbols from the alphabet. A language is a set of "correct" sentences of words. Thus, a language
is a subset of .




Grammars
Languages can be defined using inductive definitions, represented formally by making use of deduction rules.



Rule Meaning


If … and are true, then is true


is true (= axiom)



Grammars are a shorthand way to define a language inductively, by means of rewrite rules called productions (instead of
deduction rules). A grammar consists of multiple productions (e.g. in the grammar of palindromes).


Symbols from the alphabet are also called terminals in a grammar.

, The grammar makes use use of auxiliary symbols called nonterminals, that are not part of the alphabet and hence
cannot be part of the final word/sentence. (e.g. in the example production above.)

Starting from a nonterminal, we can rewrite successively until we reach a string of terminals. Such a sequence
is called a derivation.
A nonterminal could be a start symbol, often denoted as . (Context-free grammars have only one start
symbol.)


Note that not all languages can be generated/described by a grammar. On the other hand, multiple grammars may describe
the same language in which case these grammars are equivalent.



Context-free grammars
Grammars where the left hand side of a production always consists of a single nonterminal are called context-free
grammars. Languages that can be described by context-free grammar are called context-free languages.


A context-free grammar is a four-tuple , where:


is a finite set of terminal symbols.
is a finite set of nonterminal symbols.
is a finite set of production rules, each of form , where is a nonterminal and is a sequence of terminals
and nonterminals.
is the start symbol, .


Because context-free languages are relatively easy to deal with algorithmically, most programming languages are context-
free languages.



BNF (Backus Naur Form) and EBNF
Instead of writing every production on a single line, we may rewrite any number of rewrite rules for one nonterminal using a
shorthand notation called BNF, by using the symbol. e.g.:




can be combined to: .


Extended BNF (EBNF) is introduced to help abbreviate a number of standard constructions that usually occur often in the
syntax of a programming language:


and/or , means one or zero occurrences of nonterminal (i.e. optional).
, means one or more occurrences of nonterminal .
and/or , means zero or more occurrences of nonterminal .


These notations can be used for languages, grammars, nonterminals and sequences of terminal and nonterminal symbols.

, The language of a grammar
The language of a grammar , usually denoted , is defined as




Parse trees and ambiguity
We can visualize a derivation as a parse tree (a.k.a. abstract syntax tree (AST)). For example, for the grammar




the following derivation has the following parse tree:




The set of all equivalent derivations can be represented by selecting a so-called canonical element. A good candidate for
this element is the leftmost derivation. In a leftmost derivation, the leftmost nonterminal is rewritten in each step. (This is
not the case in the example above.)

Escuela, estudio y materia

Institución
Estudio
Grado

Información del documento

Subido en
26 de mayo de 2021
Número de páginas
26
Escrito en
2020/2021
Tipo
RESUMEN

Temas

5,72 €
Accede al documento completo:

¿Documento equivocado? Cámbialo gratis Dentro de los 14 días posteriores a la compra y antes de descargarlo, puedes elegir otro documento. Puedes gastar el importe de nuevo.
Escrito por estudiantes que aprobaron
Inmediatamente disponible después del pago
Leer en línea o como PDF


Documento también disponible en un lote

Reseñas de compradores verificados

Se muestran los comentarios
2 año hace

5,0

1 reseñas

5
1
4
0
3
0
2
0
1
0
Reseñas confiables sobre Stuvia

Todas las reseñas las realizan usuarios reales de Stuvia después de compras verificadas.

Conoce al vendedor

Seller avatar
Los indicadores de reputación están sujetos a la cantidad de artículos vendidos por una tarifa y las reseñas que ha recibido por esos documentos. Hay tres niveles: Bronce, Plata y Oro. Cuanto mayor reputación, más podrás confiar en la calidad del trabajo del vendedor.
pactasuntservanda Universiteit Utrecht
Seguir Necesitas iniciar sesión para seguir a otros usuarios o asignaturas
Vendido
157
Miembro desde
8 año
Número de seguidores
137
Documentos
0
Última venta
1 semana hace

3,3

36 reseñas

5
7
4
9
3
11
2
4
1
5

Recientemente visto por ti

Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes