SlideShare a Scribd company logo
WHILE interpreter


   How to quiclky implement a flexible
             OO interpreter
for an imperative programming language
           (with code in Java)

               Andrea Valente
                aaue.dk/~av
Outline
1. The WHILE programming language:
   •   syntax and semantics
2. Demo and structure of the interpreter
   •   classes and attributes
   •   evaluation and step-by-step execution
3. The mapping
   •   map interpreter UML back to the grammar
   •   invert it -> map grammar (and info about steps) into UML!
4. What is missing? ... a parser
The WHILE language
It is possible to model a simple imperative programming language with only:
 ●   Assignment - a := 3+2
 ●   Sequence - statement1;statement2
 ●   While loop – while a<b { statement }

(the if-then-else statement can be emulated using the while, so it is not fundamental)



Syntax

Stmt     ->   id := Expr | Stmt1;Stmt2 | while Cond Stmt

Expr     ->   id | number | Expr1 + Expr2 | …

C        ->   Expr1 < Expr2 | …
Semantics – an example
Example: a:=5; b:=0; while b<a b:=b+1


Execution is simulated using a set S, a store, that represent the memory.
Initial configuration: empty store, the whole program to execute
                            {} , a:=5; b:=0; while b<a b:=b+1


The first step is to evaluate the assignment a:=5, and add a to the store:
                            { (a,5) } , b:=0; while b<a b:=b+1
Then we evaluate the assignment b:=0
                           { (a,5) , (b,0) } , while b<a b:=b+1
To execute the while -> evaluate boolean condition using values in store:
  ●   if it is false we stop,
  ●   otherwise execute body, then try again to execute the whole while


In S={ (a,5) , (b,0) }, b<a is true, then we rewrite our program like this:
                           { (a,5) , (b,0) } , b:=b+1; while b<a b:=b+1
Now evaluate assignment b:=b+1, and in current store b is 0, so b will became 1:
                                { (a,5) , (b,1) } , while b<a b:=b+1
and we have to re-evaluate the while.
Go on until we reach this configuration:
                                { (a,5) , (b,5) } , while b<a b:=b+1
where the value of b is 5.
At this point we stop, because the condition of the while is false in the current store, so:

                                         { (a,5) , (b,5) } , ε
The program terminates, and we can read the results in the store.
Outline
1. The WHILE programming language:
   •   syntax and semantics
2. Demo and structure of the interpreter
   •   classes and attributes
   •   evaluation and step-by-step execution
3. The mapping
   •   map interpreter UML back to the grammar
   •   invert it -> map grammar (and info about steps) into UML!
4. What is missing? ... a parser
OO implementation
●   Demo
Execution
●   value eval(state)
●   ASTNode step(state)
    –   reshapes the ASTree
Outline
1. The WHILE programming language:
   •   syntax and semantics
2. Demo and structure of the interpreter
   •   classes and attributes
   •   evaluation and step-by-step execution
3. The mapping
   •   map interpreter UML back to the grammar
   •   invert it -> map grammar (and info about steps) into UML!
4. What is missing? ... a parser
Map back
               from classes to grammar
Rules:
class B extends A         ---> A ::= B
class A{ ... i:I, j:J }   ---> A ::= something I somethingelse J sometingmore
                               // look at toString and constructor to find syntax!
class A{ ... x:int}       ---> A ::= NUMBER


External info: which symbol is the start symbol
Reconstructed grammar

STMT ::= SLIST | ASSIGN | WHILE | OUTPUT

COND ::= GREATER

EXPR ::= ID | NUMBER | ADD | SUB

SLIST ::= list<STMT>

ASSIGN ::= ID = EXPR

ID ::= _String_

...
Outline
1. The WHILE programming language:
   •   syntax and semantics
2. Demo and structure of the interpreter
   •   classes and attributes
   •   evaluation and step-by-step execution
3. The mapping
   •   map interpreter UML back to the grammar
   •   invert it -> map grammar (and info about steps) into UML!
4. What is missing? ... a parser
Parser
●   The parser needs to be implemented separately


●   Check out sableCC and tutorials
     http://nat.truemesh.com/archives/000531.html
●   Or build it manually
     http://www.cs.luther.edu/~leekent/tutorials/ll1.html
●   A nice animated demo of a recursive descent parser
     http://ag-kastens.uni-paderborn.de/lehre/material/compiler/parsdem

More Related Content

What's hot

Lecture 16 17 code-generation
Lecture 16 17 code-generationLecture 16 17 code-generation
Lecture 16 17 code-generation
Iffat Anjum
 
Compiler Design Unit 1
Compiler Design Unit 1Compiler Design Unit 1
Compiler Design Unit 1
Jena Catherine Bel D
 
C language
C languageC language
C language
Arafat Bin Reza
 
Code generation
Code generationCode generation
Code generation
Aparna Nayak
 
Lesson 4.2 5th and 6th step
Lesson 4.2 5th and 6th stepLesson 4.2 5th and 6th step
Lesson 4.2 5th and 6th step
MLG College of Learning, Inc
 
Managing I/O operations In C- Language
Managing I/O operations In C- LanguageManaging I/O operations In C- Language
Managing I/O operations In C- Language
RavindraSalunke3
 
Intermediate code- generation
Intermediate code- generationIntermediate code- generation
Intermediate code- generation
rawan_z
 
Lesson 5 .1 selection structure
Lesson 5 .1 selection structureLesson 5 .1 selection structure
Lesson 5 .1 selection structure
MLG College of Learning, Inc
 
Lesson 4.1 completing the problem solving process
Lesson 4.1 completing the problem solving processLesson 4.1 completing the problem solving process
Lesson 4.1 completing the problem solving process
MLG College of Learning, Inc
 
7. 8085 instruction set iv
7. 8085 instruction set iv7. 8085 instruction set iv
7. 8085 instruction set iv
sandip das
 
Issues in the design of Code Generator
Issues in the design of Code GeneratorIssues in the design of Code Generator
Issues in the design of Code Generator
Darshan sai Reddy
 
Code Optimization
Code OptimizationCode Optimization
Code Optimization
Akhil Kaushik
 
Assembly language programming_fundamentals 8086
Assembly language programming_fundamentals 8086Assembly language programming_fundamentals 8086
Assembly language programming_fundamentals 8086
Shehrevar Davierwala
 
Lesson 3.2 data types for memory location
Lesson 3.2 data types for memory locationLesson 3.2 data types for memory location
Lesson 3.2 data types for memory location
MLG College of Learning, Inc
 
Code optimization in compiler design
Code optimization in compiler designCode optimization in compiler design
Code optimization in compiler design
Kuppusamy P
 
Compiler Design Unit 4
Compiler Design Unit 4Compiler Design Unit 4
Compiler Design Unit 4
Jena Catherine Bel D
 
Lesson 1 introduction to programming
Lesson 1 introduction to programmingLesson 1 introduction to programming
Lesson 1 introduction to programming
MLG College of Learning, Inc
 
Programming the basic computer
Programming the basic computerProgramming the basic computer
Programming the basic computer
Kamal Acharya
 
The security professional's guide to programming - Eric Vanderburg
The security professional's guide to programming - Eric VanderburgThe security professional's guide to programming - Eric Vanderburg
The security professional's guide to programming - Eric Vanderburg
Eric Vanderburg
 
Lesson 3.1 variables and constant
Lesson 3.1 variables and constantLesson 3.1 variables and constant
Lesson 3.1 variables and constant
MLG College of Learning, Inc
 

What's hot (20)

Lecture 16 17 code-generation
Lecture 16 17 code-generationLecture 16 17 code-generation
Lecture 16 17 code-generation
 
Compiler Design Unit 1
Compiler Design Unit 1Compiler Design Unit 1
Compiler Design Unit 1
 
C language
C languageC language
C language
 
Code generation
Code generationCode generation
Code generation
 
Lesson 4.2 5th and 6th step
Lesson 4.2 5th and 6th stepLesson 4.2 5th and 6th step
Lesson 4.2 5th and 6th step
 
Managing I/O operations In C- Language
Managing I/O operations In C- LanguageManaging I/O operations In C- Language
Managing I/O operations In C- Language
 
Intermediate code- generation
Intermediate code- generationIntermediate code- generation
Intermediate code- generation
 
Lesson 5 .1 selection structure
Lesson 5 .1 selection structureLesson 5 .1 selection structure
Lesson 5 .1 selection structure
 
Lesson 4.1 completing the problem solving process
Lesson 4.1 completing the problem solving processLesson 4.1 completing the problem solving process
Lesson 4.1 completing the problem solving process
 
7. 8085 instruction set iv
7. 8085 instruction set iv7. 8085 instruction set iv
7. 8085 instruction set iv
 
Issues in the design of Code Generator
Issues in the design of Code GeneratorIssues in the design of Code Generator
Issues in the design of Code Generator
 
Code Optimization
Code OptimizationCode Optimization
Code Optimization
 
Assembly language programming_fundamentals 8086
Assembly language programming_fundamentals 8086Assembly language programming_fundamentals 8086
Assembly language programming_fundamentals 8086
 
Lesson 3.2 data types for memory location
Lesson 3.2 data types for memory locationLesson 3.2 data types for memory location
Lesson 3.2 data types for memory location
 
Code optimization in compiler design
Code optimization in compiler designCode optimization in compiler design
Code optimization in compiler design
 
Compiler Design Unit 4
Compiler Design Unit 4Compiler Design Unit 4
Compiler Design Unit 4
 
Lesson 1 introduction to programming
Lesson 1 introduction to programmingLesson 1 introduction to programming
Lesson 1 introduction to programming
 
Programming the basic computer
Programming the basic computerProgramming the basic computer
Programming the basic computer
 
The security professional's guide to programming - Eric Vanderburg
The security professional's guide to programming - Eric VanderburgThe security professional's guide to programming - Eric Vanderburg
The security professional's guide to programming - Eric Vanderburg
 
Lesson 3.1 variables and constant
Lesson 3.1 variables and constantLesson 3.1 variables and constant
Lesson 3.1 variables and constant
 

Viewers also liked

Paper turingmachine exercises
Paper turingmachine exercisesPaper turingmachine exercises
Paper turingmachine exercises
Andrea Valente
 
Digitel 2012 presentation
Digitel 2012 presentationDigitel 2012 presentation
Digitel 2012 presentation
Andrea Valente
 
MusiCards 2008
MusiCards 2008MusiCards 2008
MusiCards 2008
Andrea Valente
 
Social exploration of 1D games
Social exploration of 1D gamesSocial exploration of 1D games
Social exploration of 1D games
Andrea Valente
 
Paper turingmachine examples
Paper turingmachine examplesPaper turingmachine examples
Paper turingmachine examples
Andrea Valente
 
Pedagogical patterns
Pedagogical patternsPedagogical patterns
Pedagogical patterns
Andrea Valente
 
The prime slaughter game
The prime slaughter gameThe prime slaughter game
The prime slaughter game
Andrea Valente
 
Design games to learn (presented at ECGBL 2014)
Design games to learn (presented at ECGBL 2014)Design games to learn (presented at ECGBL 2014)
Design games to learn (presented at ECGBL 2014)
Andrea Valente
 

Viewers also liked (8)

Paper turingmachine exercises
Paper turingmachine exercisesPaper turingmachine exercises
Paper turingmachine exercises
 
Digitel 2012 presentation
Digitel 2012 presentationDigitel 2012 presentation
Digitel 2012 presentation
 
MusiCards 2008
MusiCards 2008MusiCards 2008
MusiCards 2008
 
Social exploration of 1D games
Social exploration of 1D gamesSocial exploration of 1D games
Social exploration of 1D games
 
Paper turingmachine examples
Paper turingmachine examplesPaper turingmachine examples
Paper turingmachine examples
 
Pedagogical patterns
Pedagogical patternsPedagogical patterns
Pedagogical patterns
 
The prime slaughter game
The prime slaughter gameThe prime slaughter game
The prime slaughter game
 
Design games to learn (presented at ECGBL 2014)
Design games to learn (presented at ECGBL 2014)Design games to learn (presented at ECGBL 2014)
Design games to learn (presented at ECGBL 2014)
 

Similar to While interpreter

System Programming Overview
System Programming OverviewSystem Programming Overview
System Programming Overview
Dattatray Gandhmal
 
Esoft Metro Campus - Programming with C++
Esoft Metro Campus - Programming with C++Esoft Metro Campus - Programming with C++
Esoft Metro Campus - Programming with C++
Rasan Samarasinghe
 
c-programming
c-programmingc-programming
c-programming
Zulhazmi Harith
 
Functional Programming in JavaScript & ESNext
Functional Programming in JavaScript & ESNextFunctional Programming in JavaScript & ESNext
Functional Programming in JavaScript & ESNext
Unfold UI
 
DSA
DSADSA
DSA
rrupa2
 
UNIT-2-PPTS-DAA.ppt
UNIT-2-PPTS-DAA.pptUNIT-2-PPTS-DAA.ppt
UNIT-2-PPTS-DAA.ppt
GovindUpadhyay25
 
Lecture 01 variables scripts and operations
Lecture 01   variables scripts and operationsLecture 01   variables scripts and operations
Lecture 01 variables scripts and operations
Smee Kaem Chann
 
The Scheme Language -- Using it on the iPhone
The Scheme Language -- Using it on the iPhoneThe Scheme Language -- Using it on the iPhone
The Scheme Language -- Using it on the iPhone
James Long
 
Rdbms chapter 1 function
Rdbms chapter 1 functionRdbms chapter 1 function
Rdbms chapter 1 function
dipumaliy
 
Unit 3 sp assembler
Unit 3 sp assemblerUnit 3 sp assembler
Unit 3 sp assembler
Deepmala Sharma
 
Polish
PolishPolish
Polish
joie rocker
 
MATLAB & Image Processing
MATLAB & Image ProcessingMATLAB & Image Processing
MATLAB & Image Processing
Techbuddy Consulting Pvt. Ltd.
 
c
cc
Memory Management with Java and C++
Memory Management with Java and C++Memory Management with Java and C++
Memory Management with Java and C++
Mohammad Shaker
 
IN4308 1
IN4308 1IN4308 1
IN4308 1
Eelco Visser
 
Unit 1.pptx
Unit 1.pptxUnit 1.pptx
Unit 1.pptx
NISHASOMSCS113
 
(3) cpp procedural programming
(3) cpp procedural programming(3) cpp procedural programming
(3) cpp procedural programming
Nico Ludwig
 
Matlab lec1
Matlab lec1Matlab lec1
Matlab lec1
Amba Research
 
Lecture1
Lecture1Lecture1
Lecture1
Amisha Dalal
 
Loop Statements TanCollege Programming course.pptx
Loop Statements TanCollege Programming course.pptxLoop Statements TanCollege Programming course.pptx
Loop Statements TanCollege Programming course.pptx
adamjackson818417
 

Similar to While interpreter (20)

System Programming Overview
System Programming OverviewSystem Programming Overview
System Programming Overview
 
Esoft Metro Campus - Programming with C++
Esoft Metro Campus - Programming with C++Esoft Metro Campus - Programming with C++
Esoft Metro Campus - Programming with C++
 
c-programming
c-programmingc-programming
c-programming
 
Functional Programming in JavaScript & ESNext
Functional Programming in JavaScript & ESNextFunctional Programming in JavaScript & ESNext
Functional Programming in JavaScript & ESNext
 
DSA
DSADSA
DSA
 
UNIT-2-PPTS-DAA.ppt
UNIT-2-PPTS-DAA.pptUNIT-2-PPTS-DAA.ppt
UNIT-2-PPTS-DAA.ppt
 
Lecture 01 variables scripts and operations
Lecture 01   variables scripts and operationsLecture 01   variables scripts and operations
Lecture 01 variables scripts and operations
 
The Scheme Language -- Using it on the iPhone
The Scheme Language -- Using it on the iPhoneThe Scheme Language -- Using it on the iPhone
The Scheme Language -- Using it on the iPhone
 
Rdbms chapter 1 function
Rdbms chapter 1 functionRdbms chapter 1 function
Rdbms chapter 1 function
 
Unit 3 sp assembler
Unit 3 sp assemblerUnit 3 sp assembler
Unit 3 sp assembler
 
Polish
PolishPolish
Polish
 
MATLAB & Image Processing
MATLAB & Image ProcessingMATLAB & Image Processing
MATLAB & Image Processing
 
c
cc
c
 
Memory Management with Java and C++
Memory Management with Java and C++Memory Management with Java and C++
Memory Management with Java and C++
 
IN4308 1
IN4308 1IN4308 1
IN4308 1
 
Unit 1.pptx
Unit 1.pptxUnit 1.pptx
Unit 1.pptx
 
(3) cpp procedural programming
(3) cpp procedural programming(3) cpp procedural programming
(3) cpp procedural programming
 
Matlab lec1
Matlab lec1Matlab lec1
Matlab lec1
 
Lecture1
Lecture1Lecture1
Lecture1
 
Loop Statements TanCollege Programming course.pptx
Loop Statements TanCollege Programming course.pptxLoop Statements TanCollege Programming course.pptx
Loop Statements TanCollege Programming course.pptx
 

Recently uploaded

June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
Recommendation System using RAG Architecture
Recommendation System using RAG ArchitectureRecommendation System using RAG Architecture
Recommendation System using RAG Architecture
fredae14
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Wask
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Alpen-Adria-Universität
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
IndexBug
 
Webinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data WarehouseWebinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data Warehouse
Federico Razzoli
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
Chart Kalyan
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Jeffrey Haguewood
 
Project Management Semester Long Project - Acuity
Project Management Semester Long Project - AcuityProject Management Semester Long Project - Acuity
Project Management Semester Long Project - Acuity
jpupo2018
 

Recently uploaded (20)

June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
 
Recommendation System using RAG Architecture
Recommendation System using RAG ArchitectureRecommendation System using RAG Architecture
Recommendation System using RAG Architecture
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
 
Webinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data WarehouseWebinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data Warehouse
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
 
Project Management Semester Long Project - Acuity
Project Management Semester Long Project - AcuityProject Management Semester Long Project - Acuity
Project Management Semester Long Project - Acuity
 

While interpreter

  • 1. WHILE interpreter How to quiclky implement a flexible OO interpreter for an imperative programming language (with code in Java) Andrea Valente aaue.dk/~av
  • 2. Outline 1. The WHILE programming language: • syntax and semantics 2. Demo and structure of the interpreter • classes and attributes • evaluation and step-by-step execution 3. The mapping • map interpreter UML back to the grammar • invert it -> map grammar (and info about steps) into UML! 4. What is missing? ... a parser
  • 3. The WHILE language It is possible to model a simple imperative programming language with only: ● Assignment - a := 3+2 ● Sequence - statement1;statement2 ● While loop – while a<b { statement } (the if-then-else statement can be emulated using the while, so it is not fundamental) Syntax Stmt -> id := Expr | Stmt1;Stmt2 | while Cond Stmt Expr -> id | number | Expr1 + Expr2 | … C -> Expr1 < Expr2 | …
  • 4. Semantics – an example Example: a:=5; b:=0; while b<a b:=b+1 Execution is simulated using a set S, a store, that represent the memory. Initial configuration: empty store, the whole program to execute {} , a:=5; b:=0; while b<a b:=b+1 The first step is to evaluate the assignment a:=5, and add a to the store: { (a,5) } , b:=0; while b<a b:=b+1 Then we evaluate the assignment b:=0 { (a,5) , (b,0) } , while b<a b:=b+1
  • 5. To execute the while -> evaluate boolean condition using values in store: ● if it is false we stop, ● otherwise execute body, then try again to execute the whole while In S={ (a,5) , (b,0) }, b<a is true, then we rewrite our program like this: { (a,5) , (b,0) } , b:=b+1; while b<a b:=b+1 Now evaluate assignment b:=b+1, and in current store b is 0, so b will became 1: { (a,5) , (b,1) } , while b<a b:=b+1 and we have to re-evaluate the while. Go on until we reach this configuration: { (a,5) , (b,5) } , while b<a b:=b+1 where the value of b is 5. At this point we stop, because the condition of the while is false in the current store, so: { (a,5) , (b,5) } , ε The program terminates, and we can read the results in the store.
  • 6. Outline 1. The WHILE programming language: • syntax and semantics 2. Demo and structure of the interpreter • classes and attributes • evaluation and step-by-step execution 3. The mapping • map interpreter UML back to the grammar • invert it -> map grammar (and info about steps) into UML! 4. What is missing? ... a parser
  • 8. Execution ● value eval(state) ● ASTNode step(state) – reshapes the ASTree
  • 9. Outline 1. The WHILE programming language: • syntax and semantics 2. Demo and structure of the interpreter • classes and attributes • evaluation and step-by-step execution 3. The mapping • map interpreter UML back to the grammar • invert it -> map grammar (and info about steps) into UML! 4. What is missing? ... a parser
  • 10. Map back from classes to grammar Rules: class B extends A ---> A ::= B class A{ ... i:I, j:J } ---> A ::= something I somethingelse J sometingmore // look at toString and constructor to find syntax! class A{ ... x:int} ---> A ::= NUMBER External info: which symbol is the start symbol
  • 11. Reconstructed grammar STMT ::= SLIST | ASSIGN | WHILE | OUTPUT COND ::= GREATER EXPR ::= ID | NUMBER | ADD | SUB SLIST ::= list<STMT> ASSIGN ::= ID = EXPR ID ::= _String_ ...
  • 12. Outline 1. The WHILE programming language: • syntax and semantics 2. Demo and structure of the interpreter • classes and attributes • evaluation and step-by-step execution 3. The mapping • map interpreter UML back to the grammar • invert it -> map grammar (and info about steps) into UML! 4. What is missing? ... a parser
  • 13. Parser ● The parser needs to be implemented separately ● Check out sableCC and tutorials http://nat.truemesh.com/archives/000531.html ● Or build it manually http://www.cs.luther.edu/~leekent/tutorials/ll1.html ● A nice animated demo of a recursive descent parser http://ag-kastens.uni-paderborn.de/lehre/material/compiler/parsdem