SlideShare a Scribd company logo
Language Processor Implementation
using Python
Objectiv
e


Implement parser, syntax analyzer, semantic
analyzer for Pascal language



Show main approaches to implementation of
semantic analysis as well as intermediary code
generation



Parameterize language processor
Choosing Programming
Language

I investigated strong and week points of
several programming languages:
 Java
 Perl
 Python
 C++
 Delphi
As a result I chose Python due to several very good
reasons.
Python
Benefits

High level programming language
 Supports object oriented paradigm
 Convenient data types
 Relatively fast due to using C based libraries
 Easy readable syntax
 Cross-platform
 Convenient tools for parsing YAML
 Supports regular expressions out of the box

Language Processor Work
Scheme
Entry

Parser

Syntax

Semantics

Code gen

Exit
Вихід
In memory tables
Parser.
Tokens
Identifier

^[A-Za-z][A-Za-z_0-9]{0,255}$
Integer Const
^[+-]?d{1,10}$
Float Const
^([+-]?((d+.d+)|(d+.d+e[+-]d+)))$
String Literal
^'.{0,65535}'$
Algorythm of Analyzing
Lexems

def getClass(self, word):
c = None
if ((word in self.KeyWords)
or (word in metadata["delimiters"])
or (word in metadata["double"])
or (word in metadata["conditional_delimiters"])
or (word in metadata["multiplicative"])
or (word in metadata["additive"])
or (word in metadata["Relation"])):
c = word
else:
for r in self.RegExp.keys():
if re.compile(r).match(word):
c = self.RegExp[r]
return c
Attribute Table



Separate class



Design pattern Singleton



Uses hash table as internal structure



Fast access



Convenient format
Attribute Table Look
Syntax
Analyzer


Context free grammar



Left associated grammar



EBNF



Configuration format is yaml



Language grammar is easily changed without
source code modification
YAML Configuration Format
Benefits


Short and readable



yaml uses data structures that are native to
programming languages like Perl, Python
Configuration Format of Language
Grammar

EBNF

rule
program ::=
EBNF

Program ID ; block .

rule in configuration
programme:
- [program, id, ;, Block, "."]
Semantic Analyzer. Semantic
Actions
Rule

without semantic actions
complex_action:
- [begin, action_list, end]
Rule

with semantic actions
complex_action:
- [begin, "#200", action_list, end, "#220"]
Attribute
classes
Making

code generation process easier, I created a
bunch of classes like AttrFor.

class

AttrFor (AttrObject):

self.parameter = None
self.first = None
self.last = None
self.step = None
self.body = None
Abstract Parse
Tree
Intermediary code
generation
We

are using tetrads language in order to generate
intermediary code
How tetrads language looks:
Z := X op Y
Z := op X
Z := Y
Z := Y[X]
Z:
GOTO Z
If condition GOTO Z
Example of input file
program q;
var
a, b: integer;
i: integer;
d: integer;
begin
d := 4;
for i:= 1 to (2+2*2)*2 do
begin
b:=b + 1;
a:=a * 2;
end;
d:=a;
end.
Output of language processor using intermediary code

d:=4
i:=1
@Lid1:
if i > 12 goto @Lid2
b:=b + 1
a:=a * 2
i := i + 1
goto @Lid1
@Lid2:
d:=a
Bottom line


I implemented parser, syntax analyzer, semantic analyzer,
intermediary code generation of Pascal programming
language



I showed main concepts of semantic analysis as well as
intermediary code generation



Language processor has been parameterized
Ad

More Related Content

What's hot (13)

Class 3 - PHP Functions
Class 3 - PHP FunctionsClass 3 - PHP Functions
Class 3 - PHP Functions
Ahmed Swilam
 
Introduction to php php++
Introduction to php php++Introduction to php php++
Introduction to php php++
Tanay Kishore Mishra
 
Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)
jeffz
 
LEX & YACC TOOL
LEX & YACC TOOLLEX & YACC TOOL
LEX & YACC TOOL
PUNE VIDYARTHI GRIHA'S COLLEGE OF ENGINEERING, NASHIK
 
Php Chapter 2 3 Training
Php Chapter 2 3 TrainingPhp Chapter 2 3 Training
Php Chapter 2 3 Training
Chris Chubb
 
PHP Unit 3 functions_in_php_2
PHP Unit 3 functions_in_php_2PHP Unit 3 functions_in_php_2
PHP Unit 3 functions_in_php_2
Kumar
 
Lex tool manual
Lex tool manualLex tool manual
Lex tool manual
Sami Said
 
TI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific LanguagesTI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific Languages
Eelco Visser
 
Lex Tool
Lex ToolLex Tool
Lex Tool
Rajan Shah
 
Perl bhargav
Perl bhargavPerl bhargav
Perl bhargav
Bhargav Reddy
 
Ch4c
Ch4cCh4c
Ch4c
kinnarshah8888
 
PHP 7.0 new features (and new interpreter)
PHP 7.0 new features (and new interpreter)PHP 7.0 new features (and new interpreter)
PHP 7.0 new features (and new interpreter)
Andrea Telatin
 
Yacc
YaccYacc
Yacc
BBDITM LUCKNOW
 

Viewers also liked (7)

Ltr 1 Powerpoint
Ltr 1 PowerpointLtr 1 Powerpoint
Ltr 1 Powerpoint
Mary Chu
 
Боломж систем MNB
Боломж систем MNBБоломж систем MNB
Боломж систем MNB
Энхбаяр Д.
 
Doing Azure With PowerShell
Doing Azure With PowerShellDoing Azure With PowerShell
Doing Azure With PowerShell
Thomas Lee
 
PowerShell 101 - What is it and Why should YOU Care!
PowerShell 101 - What is it and Why should YOU Care!PowerShell 101 - What is it and Why should YOU Care!
PowerShell 101 - What is it and Why should YOU Care!
Thomas Lee
 
Linux Introduction (Commands)
Linux Introduction (Commands)Linux Introduction (Commands)
Linux Introduction (Commands)
anandvaidya
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 Minutes
Matt Harrison
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
Nowell Strite
 
Ltr 1 Powerpoint
Ltr 1 PowerpointLtr 1 Powerpoint
Ltr 1 Powerpoint
Mary Chu
 
Doing Azure With PowerShell
Doing Azure With PowerShellDoing Azure With PowerShell
Doing Azure With PowerShell
Thomas Lee
 
PowerShell 101 - What is it and Why should YOU Care!
PowerShell 101 - What is it and Why should YOU Care!PowerShell 101 - What is it and Why should YOU Care!
PowerShell 101 - What is it and Why should YOU Care!
Thomas Lee
 
Linux Introduction (Commands)
Linux Introduction (Commands)Linux Introduction (Commands)
Linux Introduction (Commands)
anandvaidya
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 Minutes
Matt Harrison
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
Nowell Strite
 
Ad

Similar to Language processor implementation using python (20)

A Brief Overview of (Static) Program Query Languages
A Brief Overview of (Static) Program Query LanguagesA Brief Overview of (Static) Program Query Languages
A Brief Overview of (Static) Program Query Languages
Kim Mens
 
Python programming workshop session 1
Python programming workshop session 1Python programming workshop session 1
Python programming workshop session 1
Abdul Haseeb
 
Visual Studio .NET2010
Visual Studio .NET2010Visual Studio .NET2010
Visual Studio .NET2010
Satish Verma
 
PERTEMUAN 1 - MENGENAL ENVIRONTMENT PROGRAM VISUAL C#.pptx
PERTEMUAN 1 - MENGENAL ENVIRONTMENT PROGRAM VISUAL C#.pptxPERTEMUAN 1 - MENGENAL ENVIRONTMENT PROGRAM VISUAL C#.pptx
PERTEMUAN 1 - MENGENAL ENVIRONTMENT PROGRAM VISUAL C#.pptx
TriSandhikaJaya
 
Introduction to c_sharp
Introduction to c_sharpIntroduction to c_sharp
Introduction to c_sharp
Jorge Antonio Contre Vargas
 
Python basics
Python basicsPython basics
Python basics
RANAALIMAJEEDRAJPUT
 
Intro in understanding to C programming .pptx
Intro in understanding to C   programming .pptxIntro in understanding to C   programming .pptx
Intro in understanding to C programming .pptx
abadinasargie
 
Intro in understanding to C programming .pptx
Intro in understanding to C   programming .pptxIntro in understanding to C   programming .pptx
Intro in understanding to C programming .pptx
abadinasargie
 
Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008
Guillaume Laforge
 
Presentation c++
Presentation c++Presentation c++
Presentation c++
JosephAlex21
 
What we can learn from Rebol?
What we can learn from Rebol?What we can learn from Rebol?
What we can learn from Rebol?
lichtkind
 
Groovy Update - JavaPolis 2007
Groovy Update - JavaPolis 2007Groovy Update - JavaPolis 2007
Groovy Update - JavaPolis 2007
Guillaume Laforge
 
c programming session 1.pptx
c programming session 1.pptxc programming session 1.pptx
c programming session 1.pptx
RSathyaPriyaCSEKIOT
 
An Overview Of Python With Functional Programming
An Overview Of Python With Functional ProgrammingAn Overview Of Python With Functional Programming
An Overview Of Python With Functional Programming
Adam Getchell
 
KScope14 Jython Scripting
KScope14 Jython ScriptingKScope14 Jython Scripting
KScope14 Jython Scripting
Alithya
 
javaeanjjisjejrehurfhjhjfeauojksfjdi.ppt
javaeanjjisjejrehurfhjhjfeauojksfjdi.pptjavaeanjjisjejrehurfhjhjfeauojksfjdi.ppt
javaeanjjisjejrehurfhjhjfeauojksfjdi.ppt
eraqhuzay69
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
Alpana Gupta
 
Java introduction
Java introductionJava introduction
Java introduction
Migrant Systems
 
R and Python, A Code Demo
R and Python, A Code DemoR and Python, A Code Demo
R and Python, A Code Demo
Vineet Jaiswal
 
Introduction To Groovy 2005
Introduction To Groovy 2005Introduction To Groovy 2005
Introduction To Groovy 2005
Tugdual Grall
 
A Brief Overview of (Static) Program Query Languages
A Brief Overview of (Static) Program Query LanguagesA Brief Overview of (Static) Program Query Languages
A Brief Overview of (Static) Program Query Languages
Kim Mens
 
Python programming workshop session 1
Python programming workshop session 1Python programming workshop session 1
Python programming workshop session 1
Abdul Haseeb
 
Visual Studio .NET2010
Visual Studio .NET2010Visual Studio .NET2010
Visual Studio .NET2010
Satish Verma
 
PERTEMUAN 1 - MENGENAL ENVIRONTMENT PROGRAM VISUAL C#.pptx
PERTEMUAN 1 - MENGENAL ENVIRONTMENT PROGRAM VISUAL C#.pptxPERTEMUAN 1 - MENGENAL ENVIRONTMENT PROGRAM VISUAL C#.pptx
PERTEMUAN 1 - MENGENAL ENVIRONTMENT PROGRAM VISUAL C#.pptx
TriSandhikaJaya
 
Intro in understanding to C programming .pptx
Intro in understanding to C   programming .pptxIntro in understanding to C   programming .pptx
Intro in understanding to C programming .pptx
abadinasargie
 
Intro in understanding to C programming .pptx
Intro in understanding to C   programming .pptxIntro in understanding to C   programming .pptx
Intro in understanding to C programming .pptx
abadinasargie
 
Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008
Guillaume Laforge
 
What we can learn from Rebol?
What we can learn from Rebol?What we can learn from Rebol?
What we can learn from Rebol?
lichtkind
 
Groovy Update - JavaPolis 2007
Groovy Update - JavaPolis 2007Groovy Update - JavaPolis 2007
Groovy Update - JavaPolis 2007
Guillaume Laforge
 
An Overview Of Python With Functional Programming
An Overview Of Python With Functional ProgrammingAn Overview Of Python With Functional Programming
An Overview Of Python With Functional Programming
Adam Getchell
 
KScope14 Jython Scripting
KScope14 Jython ScriptingKScope14 Jython Scripting
KScope14 Jython Scripting
Alithya
 
javaeanjjisjejrehurfhjhjfeauojksfjdi.ppt
javaeanjjisjejrehurfhjhjfeauojksfjdi.pptjavaeanjjisjejrehurfhjhjfeauojksfjdi.ppt
javaeanjjisjejrehurfhjhjfeauojksfjdi.ppt
eraqhuzay69
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
Alpana Gupta
 
R and Python, A Code Demo
R and Python, A Code DemoR and Python, A Code Demo
R and Python, A Code Demo
Vineet Jaiswal
 
Introduction To Groovy 2005
Introduction To Groovy 2005Introduction To Groovy 2005
Introduction To Groovy 2005
Tugdual Grall
 
Ad

Recently uploaded (20)

May Patch Tuesday
May Patch TuesdayMay Patch Tuesday
May Patch Tuesday
Ivanti
 
Top Hyper-Casual Game Studio Services
Top  Hyper-Casual  Game  Studio ServicesTop  Hyper-Casual  Game  Studio Services
Top Hyper-Casual Game Studio Services
Nova Carter
 
Design pattern talk by Kaya Weers - 2025 (v2)
Design pattern talk by Kaya Weers - 2025 (v2)Design pattern talk by Kaya Weers - 2025 (v2)
Design pattern talk by Kaya Weers - 2025 (v2)
Kaya Weers
 
Config 2025 presentation recap covering both days
Config 2025 presentation recap covering both daysConfig 2025 presentation recap covering both days
Config 2025 presentation recap covering both days
TrishAntoni1
 
OpenAI Just Announced Codex: A cloud engineering agent that excels in handlin...
OpenAI Just Announced Codex: A cloud engineering agent that excels in handlin...OpenAI Just Announced Codex: A cloud engineering agent that excels in handlin...
OpenAI Just Announced Codex: A cloud engineering agent that excels in handlin...
SOFTTECHHUB
 
Refactoring meta-rauc-community: Cleaner Code, Better Maintenance, More Machines
Refactoring meta-rauc-community: Cleaner Code, Better Maintenance, More MachinesRefactoring meta-rauc-community: Cleaner Code, Better Maintenance, More Machines
Refactoring meta-rauc-community: Cleaner Code, Better Maintenance, More Machines
Leon Anavi
 
Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Kit-Works Team Study_아직도 Dockefile.pdf_김성호Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Wonjun Hwang
 
IT488 Wireless Sensor Networks_Information Technology
IT488 Wireless Sensor Networks_Information TechnologyIT488 Wireless Sensor Networks_Information Technology
IT488 Wireless Sensor Networks_Information Technology
SHEHABALYAMANI
 
Distributionally Robust Statistical Verification with Imprecise Neural Networks
Distributionally Robust Statistical Verification with Imprecise Neural NetworksDistributionally Robust Statistical Verification with Imprecise Neural Networks
Distributionally Robust Statistical Verification with Imprecise Neural Networks
Ivan Ruchkin
 
Digital Technologies for Culture, Arts and Heritage: Insights from Interdisci...
Digital Technologies for Culture, Arts and Heritage: Insights from Interdisci...Digital Technologies for Culture, Arts and Heritage: Insights from Interdisci...
Digital Technologies for Culture, Arts and Heritage: Insights from Interdisci...
Vasileios Komianos
 
Master Data Management - Enterprise Application Integration
Master Data Management - Enterprise Application IntegrationMaster Data Management - Enterprise Application Integration
Master Data Management - Enterprise Application Integration
Sherif Rasmy
 
machines-for-woodworking-shops-en-compressed.pdf
machines-for-woodworking-shops-en-compressed.pdfmachines-for-woodworking-shops-en-compressed.pdf
machines-for-woodworking-shops-en-compressed.pdf
AmirStern2
 
Secondary Storage for a microcontroller system
Secondary Storage for a microcontroller systemSecondary Storage for a microcontroller system
Secondary Storage for a microcontroller system
fizarcse
 
Dark Dynamism: drones, dark factories and deurbanization
Dark Dynamism: drones, dark factories and deurbanizationDark Dynamism: drones, dark factories and deurbanization
Dark Dynamism: drones, dark factories and deurbanization
Jakub Šimek
 
MULTI-STAKEHOLDER CONSULTATION PROGRAM On Implementation of DNF 2.0 and Way F...
MULTI-STAKEHOLDER CONSULTATION PROGRAM On Implementation of DNF 2.0 and Way F...MULTI-STAKEHOLDER CONSULTATION PROGRAM On Implementation of DNF 2.0 and Way F...
MULTI-STAKEHOLDER CONSULTATION PROGRAM On Implementation of DNF 2.0 and Way F...
ICT Frame Magazine Pvt. Ltd.
 
Build With AI - In Person Session Slides.pdf
Build With AI - In Person Session Slides.pdfBuild With AI - In Person Session Slides.pdf
Build With AI - In Person Session Slides.pdf
Google Developer Group - Harare
 
Building a research repository that works by Clare Cady
Building a research repository that works by Clare CadyBuilding a research repository that works by Clare Cady
Building a research repository that works by Clare Cady
UXPA Boston
 
React Native for Business Solutions: Building Scalable Apps for Success
React Native for Business Solutions: Building Scalable Apps for SuccessReact Native for Business Solutions: Building Scalable Apps for Success
React Native for Business Solutions: Building Scalable Apps for Success
Amelia Swank
 
Cybersecurity Threat Vectors and Mitigation
Cybersecurity Threat Vectors and MitigationCybersecurity Threat Vectors and Mitigation
Cybersecurity Threat Vectors and Mitigation
VICTOR MAESTRE RAMIREZ
 
How Top Companies Benefit from Outsourcing
How Top Companies Benefit from OutsourcingHow Top Companies Benefit from Outsourcing
How Top Companies Benefit from Outsourcing
Nascenture
 
May Patch Tuesday
May Patch TuesdayMay Patch Tuesday
May Patch Tuesday
Ivanti
 
Top Hyper-Casual Game Studio Services
Top  Hyper-Casual  Game  Studio ServicesTop  Hyper-Casual  Game  Studio Services
Top Hyper-Casual Game Studio Services
Nova Carter
 
Design pattern talk by Kaya Weers - 2025 (v2)
Design pattern talk by Kaya Weers - 2025 (v2)Design pattern talk by Kaya Weers - 2025 (v2)
Design pattern talk by Kaya Weers - 2025 (v2)
Kaya Weers
 
Config 2025 presentation recap covering both days
Config 2025 presentation recap covering both daysConfig 2025 presentation recap covering both days
Config 2025 presentation recap covering both days
TrishAntoni1
 
OpenAI Just Announced Codex: A cloud engineering agent that excels in handlin...
OpenAI Just Announced Codex: A cloud engineering agent that excels in handlin...OpenAI Just Announced Codex: A cloud engineering agent that excels in handlin...
OpenAI Just Announced Codex: A cloud engineering agent that excels in handlin...
SOFTTECHHUB
 
Refactoring meta-rauc-community: Cleaner Code, Better Maintenance, More Machines
Refactoring meta-rauc-community: Cleaner Code, Better Maintenance, More MachinesRefactoring meta-rauc-community: Cleaner Code, Better Maintenance, More Machines
Refactoring meta-rauc-community: Cleaner Code, Better Maintenance, More Machines
Leon Anavi
 
Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Kit-Works Team Study_아직도 Dockefile.pdf_김성호Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Wonjun Hwang
 
IT488 Wireless Sensor Networks_Information Technology
IT488 Wireless Sensor Networks_Information TechnologyIT488 Wireless Sensor Networks_Information Technology
IT488 Wireless Sensor Networks_Information Technology
SHEHABALYAMANI
 
Distributionally Robust Statistical Verification with Imprecise Neural Networks
Distributionally Robust Statistical Verification with Imprecise Neural NetworksDistributionally Robust Statistical Verification with Imprecise Neural Networks
Distributionally Robust Statistical Verification with Imprecise Neural Networks
Ivan Ruchkin
 
Digital Technologies for Culture, Arts and Heritage: Insights from Interdisci...
Digital Technologies for Culture, Arts and Heritage: Insights from Interdisci...Digital Technologies for Culture, Arts and Heritage: Insights from Interdisci...
Digital Technologies for Culture, Arts and Heritage: Insights from Interdisci...
Vasileios Komianos
 
Master Data Management - Enterprise Application Integration
Master Data Management - Enterprise Application IntegrationMaster Data Management - Enterprise Application Integration
Master Data Management - Enterprise Application Integration
Sherif Rasmy
 
machines-for-woodworking-shops-en-compressed.pdf
machines-for-woodworking-shops-en-compressed.pdfmachines-for-woodworking-shops-en-compressed.pdf
machines-for-woodworking-shops-en-compressed.pdf
AmirStern2
 
Secondary Storage for a microcontroller system
Secondary Storage for a microcontroller systemSecondary Storage for a microcontroller system
Secondary Storage for a microcontroller system
fizarcse
 
Dark Dynamism: drones, dark factories and deurbanization
Dark Dynamism: drones, dark factories and deurbanizationDark Dynamism: drones, dark factories and deurbanization
Dark Dynamism: drones, dark factories and deurbanization
Jakub Šimek
 
MULTI-STAKEHOLDER CONSULTATION PROGRAM On Implementation of DNF 2.0 and Way F...
MULTI-STAKEHOLDER CONSULTATION PROGRAM On Implementation of DNF 2.0 and Way F...MULTI-STAKEHOLDER CONSULTATION PROGRAM On Implementation of DNF 2.0 and Way F...
MULTI-STAKEHOLDER CONSULTATION PROGRAM On Implementation of DNF 2.0 and Way F...
ICT Frame Magazine Pvt. Ltd.
 
Building a research repository that works by Clare Cady
Building a research repository that works by Clare CadyBuilding a research repository that works by Clare Cady
Building a research repository that works by Clare Cady
UXPA Boston
 
React Native for Business Solutions: Building Scalable Apps for Success
React Native for Business Solutions: Building Scalable Apps for SuccessReact Native for Business Solutions: Building Scalable Apps for Success
React Native for Business Solutions: Building Scalable Apps for Success
Amelia Swank
 
Cybersecurity Threat Vectors and Mitigation
Cybersecurity Threat Vectors and MitigationCybersecurity Threat Vectors and Mitigation
Cybersecurity Threat Vectors and Mitigation
VICTOR MAESTRE RAMIREZ
 
How Top Companies Benefit from Outsourcing
How Top Companies Benefit from OutsourcingHow Top Companies Benefit from Outsourcing
How Top Companies Benefit from Outsourcing
Nascenture
 

Language processor implementation using python

  翻译: