SlideShare une entreprise Scribd logo
1  sur  4
Michael MielesCaballero
S7l
Compiladores 24/01/2015
Lenguaje estructurado en forma sintáctica Ascendente
Ejemplo
Entrada: Id.*.Id.+.Id
Gramática:
Expresión::=Expresión.*.Término|Expresión.+.Término|Término
Término::= Id | Número
Derivación:
Expresión Expresión.+.Término
Expresión.*.Término.+.Término
Término.*.Término.+.Término
Id.*.Término.+.Término
Definición:Pivote
Secuenciamáslargade símbolosenlaparte másizquierdade laentradaque se puedeencontrar
enla parte derechade una producción ytal que todoslossímbolosa su derechasonterminales
Ejemplo:
Si entrada es:Expresión.*.Término.+.Id
el pivote es:Expresión.*.Término
Algoritmo
1.Empezarcon la cadenade entrada
2. Intentarllegarhastael axioma,encontrandoel pivote yreduciéndolo
con la produccióncorrespondiente
Expresión.*.Término.+.IdExpresión.+.Id
Expresión.+.Término Expresión
begin
if car= i then begin scan;
if car = asig then scan else error;
B
end
elseif car= if then begin scan;
B;
if car= then scan else error;
S;
end
elseif car=write then begin scan;
B
end
else error
end;
ProcedureB;
Begin
if car= i then begin scan;
if car in [igual,noigual] then scan else
error;
if car = i then scan else error;
end
elseif car = in [true,false] then
scan
else
error
end;
Michael MielesCaballero
S7l
Compiladores 24/01/2015
Lenguaje estructurado en forma Léxica
Análisisléxico: Implementación deun AL
– Ejemplo:IdentificadorId::=letra(letra|digito)*
Pseudocódigo:
c :=GetChar();
if IsLetter(c) then
identificador:= “”
repeat
identificador:= identificador+ c
c :=GetChar()
until not(IsLetter(c) orIsDigit(c))
Retract()
token:=(Id,InstallName(identificador))
Accept()
Return(token)
else
fail()
– Quéocurre con x1,temp,102?? Compiladoreseintérpretes10 Análisis léxico:Implementación
de un AL – Ejemplo:constanteentera entero::=digito+
Pseudocódigo:
c :=GetChar();
if IsDigit(c) then
valor:= convertir( c)
c :=GetChar()
while IsDigit(c ) do
valor:= valor*10+ convertir(c)
c :=GetChar()
endWile
Retract()
token:=(entero,valor)
Accept()
Return(token)
else
fail()
Michael MielesCaballero
S7l
Compiladores 24/01/2015
Lenguaje estructurado en forma Semántica
Funcion E (VAR Arbol: Arbol)
(
E::= Identificador := E’)
c:= GetToken;
If c=´Identificador´ Then
nodo:= CreaHoja(´Identificador´, token.puntero(c));
c:=GetToken;
If c=´:=´ Then
Arbol:= CreaNodo(´:=´, nodo, NIL);
E´(nodo.dcha(Arbol))
else
Fail; error
else
Fail; error
char Semantico::operar(char tipo1, char tipo2, char operador)
{
cout<<"ttSemantico: "<<tipo1<<" "<<operador<<"
"<<tipo2<<endl;
if (tipo1 == 'I' && tipo2 == 'I')
if (operador == '/')
return 'F';
else
return 'I';
if (tipo1 == 'C' && tipo2 == 'C')
return 'C';
if (tipo1 == 'F' && tipo2 == 'F')
if (operador == '%')
return 'I';
else
return 'F';
if ( (tipo1 == 'C' && tipo2 != 'C') || (tipo2 == 'C' &&
tipo1 != 'C')) {
cout<<"Error semántico: Tipos incompatibles:
"<<tipo1<<" "<<tipo2<<" "<<operador;
}
if (tipo1 == 'I' && tipo2 == 'F') {
switch (operador) {
Michael MielesCaballero
S7l
Compiladores 24/01/2015
case '=':
cout<<"Error semántico: Tipos incompatibles:
"<<tipo1<<" "<<tipo2<<" "<<operador;
case '^':
return 'F';
default:
return 'F';
}
}
if (tipo1 == 'F' && tipo2 == 'I') {
return 'F';
}
cout<<"Error semántico: Tipos incompatibles: "<<tipo1<<"
"<<tipo2<<" "<<operador;
}

Contenu connexe

En vedette

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

En vedette (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Lenguaje estructurado en forma sintáctica ascendente

  • 1. Michael MielesCaballero S7l Compiladores 24/01/2015 Lenguaje estructurado en forma sintáctica Ascendente Ejemplo Entrada: Id.*.Id.+.Id Gramática: Expresión::=Expresión.*.Término|Expresión.+.Término|Término Término::= Id | Número Derivación: Expresión Expresión.+.Término Expresión.*.Término.+.Término Término.*.Término.+.Término Id.*.Término.+.Término Definición:Pivote Secuenciamáslargade símbolosenlaparte másizquierdade laentradaque se puedeencontrar enla parte derechade una producción ytal que todoslossímbolosa su derechasonterminales Ejemplo: Si entrada es:Expresión.*.Término.+.Id el pivote es:Expresión.*.Término Algoritmo 1.Empezarcon la cadenade entrada 2. Intentarllegarhastael axioma,encontrandoel pivote yreduciéndolo con la produccióncorrespondiente Expresión.*.Término.+.IdExpresión.+.Id Expresión.+.Término Expresión begin if car= i then begin scan; if car = asig then scan else error; B end elseif car= if then begin scan; B; if car= then scan else error; S; end elseif car=write then begin scan; B end else error end; ProcedureB; Begin if car= i then begin scan; if car in [igual,noigual] then scan else error; if car = i then scan else error; end elseif car = in [true,false] then scan else error end;
  • 2. Michael MielesCaballero S7l Compiladores 24/01/2015 Lenguaje estructurado en forma Léxica Análisisléxico: Implementación deun AL – Ejemplo:IdentificadorId::=letra(letra|digito)* Pseudocódigo: c :=GetChar(); if IsLetter(c) then identificador:= “” repeat identificador:= identificador+ c c :=GetChar() until not(IsLetter(c) orIsDigit(c)) Retract() token:=(Id,InstallName(identificador)) Accept() Return(token) else fail() – Quéocurre con x1,temp,102?? Compiladoreseintérpretes10 Análisis léxico:Implementación de un AL – Ejemplo:constanteentera entero::=digito+ Pseudocódigo: c :=GetChar(); if IsDigit(c) then valor:= convertir( c) c :=GetChar() while IsDigit(c ) do valor:= valor*10+ convertir(c) c :=GetChar() endWile Retract() token:=(entero,valor) Accept() Return(token) else fail()
  • 3. Michael MielesCaballero S7l Compiladores 24/01/2015 Lenguaje estructurado en forma Semántica Funcion E (VAR Arbol: Arbol) ( E::= Identificador := E’) c:= GetToken; If c=´Identificador´ Then nodo:= CreaHoja(´Identificador´, token.puntero(c)); c:=GetToken; If c=´:=´ Then Arbol:= CreaNodo(´:=´, nodo, NIL); E´(nodo.dcha(Arbol)) else Fail; error else Fail; error char Semantico::operar(char tipo1, char tipo2, char operador) { cout<<"ttSemantico: "<<tipo1<<" "<<operador<<" "<<tipo2<<endl; if (tipo1 == 'I' && tipo2 == 'I') if (operador == '/') return 'F'; else return 'I'; if (tipo1 == 'C' && tipo2 == 'C') return 'C'; if (tipo1 == 'F' && tipo2 == 'F') if (operador == '%') return 'I'; else return 'F'; if ( (tipo1 == 'C' && tipo2 != 'C') || (tipo2 == 'C' && tipo1 != 'C')) { cout<<"Error semántico: Tipos incompatibles: "<<tipo1<<" "<<tipo2<<" "<<operador; } if (tipo1 == 'I' && tipo2 == 'F') { switch (operador) {
  • 4. Michael MielesCaballero S7l Compiladores 24/01/2015 case '=': cout<<"Error semántico: Tipos incompatibles: "<<tipo1<<" "<<tipo2<<" "<<operador; case '^': return 'F'; default: return 'F'; } } if (tipo1 == 'F' && tipo2 == 'I') { return 'F'; } cout<<"Error semántico: Tipos incompatibles: "<<tipo1<<" "<<tipo2<<" "<<operador; }