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

Recommended

Domain specific languages - progressive f sharp tutorials nyc 2012
Domain specific languages - progressive f sharp tutorials nyc 2012
Phillip Trelford
 
BUILDING BASIC STRECH SQL COMPILER
BUILDING BASIC STRECH SQL COMPILER
Ajeet Dubey
 
Functions in php
Functions in php
Mudasir Syed
 
Cs3430 lecture 15
Cs3430 lecture 15
Tanwir Zaman
 
Anonymous Functions in PHP 5.3 - Matthew Weier O’Phinney
Anonymous Functions in PHP 5.3 - Matthew Weier O’Phinney
Hipot Studio
 
Yacc (yet another compiler compiler)
Yacc (yet another compiler compiler)
omercomail
 
Yacc lex
Yacc lex
915086731
 
PHPLinq
PHPLinq
Maarten Balliauw
 
Class 3 - PHP Functions
Class 3 - PHP Functions
Ahmed Swilam
 
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)
jeffz
 
LEX & YACC TOOL
LEX & YACC TOOL
PUNE VIDYARTHI GRIHA'S COLLEGE OF ENGINEERING, NASHIK
 
Php Chapter 2 3 Training
Php Chapter 2 3 Training
Chris Chubb
 
PHP Unit 3 functions_in_php_2
PHP Unit 3 functions_in_php_2
Kumar
 
Lex tool manual
Lex tool manual
Sami Said
 
TI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific Languages
Eelco Visser
 
Lex Tool
Lex Tool
Rajan Shah
 
Perl bhargav
Perl bhargav
Bhargav Reddy
 
Ch4c
Ch4c
kinnarshah8888
 
PHP 7.0 new features (and new interpreter)
PHP 7.0 new features (and new interpreter)
Andrea Telatin
 
Yacc
Yacc
BBDITM LUCKNOW
 
Ltr 1 Powerpoint
Ltr 1 Powerpoint
Mary Chu
 
Боломж систем MNB
Боломж систем MNB
Энхбаяр Д.
 
Doing 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!
Thomas Lee
 
Linux Introduction (Commands)
Linux Introduction (Commands)
anandvaidya
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 Minutes
Matt Harrison
 
Introduction to Python
Introduction to Python
Nowell Strite
 
Compiler Design in Computer Applications
Compiler Design in Computer Applications
Mohit422982
 
Unit1.ppt
Unit1.ppt
BerlinShaheema2
 

More Related Content

What's hot (13)

Class 3 - PHP Functions
Class 3 - PHP Functions
Ahmed Swilam
 
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)
jeffz
 
LEX & YACC TOOL
LEX & YACC TOOL
PUNE VIDYARTHI GRIHA'S COLLEGE OF ENGINEERING, NASHIK
 
Php Chapter 2 3 Training
Php Chapter 2 3 Training
Chris Chubb
 
PHP Unit 3 functions_in_php_2
PHP Unit 3 functions_in_php_2
Kumar
 
Lex tool manual
Lex tool manual
Sami Said
 
TI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific Languages
Eelco Visser
 
Lex Tool
Lex Tool
Rajan Shah
 
Perl bhargav
Perl bhargav
Bhargav Reddy
 
Ch4c
Ch4c
kinnarshah8888
 
PHP 7.0 new features (and new interpreter)
PHP 7.0 new features (and new interpreter)
Andrea Telatin
 
Yacc
Yacc
BBDITM LUCKNOW
 

Viewers also liked (7)

Ltr 1 Powerpoint
Ltr 1 Powerpoint
Mary Chu
 
Боломж систем MNB
Боломж систем MNB
Энхбаяр Д.
 
Doing 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!
Thomas Lee
 
Linux Introduction (Commands)
Linux Introduction (Commands)
anandvaidya
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 Minutes
Matt Harrison
 
Introduction to Python
Introduction to Python
Nowell Strite
 
Ltr 1 Powerpoint
Ltr 1 Powerpoint
Mary Chu
 
Doing 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!
Thomas Lee
 
Linux Introduction (Commands)
Linux Introduction (Commands)
anandvaidya
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 Minutes
Matt Harrison
 
Introduction to Python
Introduction to Python
Nowell Strite
 
Ad

Similar to Language processor implementation using python (20)

Compiler Design in Computer Applications
Compiler Design in Computer Applications
Mohit422982
 
Unit1.ppt
Unit1.ppt
BerlinShaheema2
 
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGE
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGE
IJCI JOURNAL
 
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGE
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGE
IJCI JOURNAL
 
lec00-Introduction.pdf
lec00-Introduction.pdf
wigewej294
 
1 compiler outline
1 compiler outline
ASHOK KUMAR REDDY
 
Cpcs302 1
Cpcs302 1
guest5de1a5
 
Ss ui lecture 2
Ss ui lecture 2
Avinash Kapse
 
CD U1-5.pptx
CD U1-5.pptx
Himajanaidu2
 
Lecture 1 introduction to language processors
Lecture 1 introduction to language processors
Rebaz Najeeb
 
Compiler_Lecture1.pdf
Compiler_Lecture1.pdf
AkarTaher
 
Compiler design computer science engineering.ppt
Compiler design computer science engineering.ppt
khandareshobhit17
 
Compiler_Project_Srikanth_Vanama
Compiler_Project_Srikanth_Vanama
Srikanth Vanama
 
Structure-Compiler-phases information about basics of compiler. Pdfpdf
Structure-Compiler-phases information about basics of compiler. Pdfpdf
ovidlivi91
 
1._Introduction_.pptx
1._Introduction_.pptx
Anbarasan Radhakrishnan R
 
COMPILER CONSTRUCTION KU 1.pptx
COMPILER CONSTRUCTION KU 1.pptx
Rossy719186
 
Compiler design Introduction
Compiler design Introduction
Aman Sharma
 
Building Interpreters with PyPy
Building Interpreters with PyPy
Daniel Neuhäuser
 
PSEUDOCODE TO SOURCE PROGRAMMING LANGUAGE TRANSLATOR
PSEUDOCODE TO SOURCE PROGRAMMING LANGUAGE TRANSLATOR
ijistjournal
 
Compiler Design Material
Compiler Design Material
Dr. C.V. Suresh Babu
 
Compiler Design in Computer Applications
Compiler Design in Computer Applications
Mohit422982
 
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGE
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGE
IJCI JOURNAL
 
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGE
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGE
IJCI JOURNAL
 
lec00-Introduction.pdf
lec00-Introduction.pdf
wigewej294
 
Lecture 1 introduction to language processors
Lecture 1 introduction to language processors
Rebaz Najeeb
 
Compiler_Lecture1.pdf
Compiler_Lecture1.pdf
AkarTaher
 
Compiler design computer science engineering.ppt
Compiler design computer science engineering.ppt
khandareshobhit17
 
Compiler_Project_Srikanth_Vanama
Compiler_Project_Srikanth_Vanama
Srikanth Vanama
 
Structure-Compiler-phases information about basics of compiler. Pdfpdf
Structure-Compiler-phases information about basics of compiler. Pdfpdf
ovidlivi91
 
COMPILER CONSTRUCTION KU 1.pptx
COMPILER CONSTRUCTION KU 1.pptx
Rossy719186
 
Compiler design Introduction
Compiler design Introduction
Aman Sharma
 
Building Interpreters with PyPy
Building Interpreters with PyPy
Daniel Neuhäuser
 
PSEUDOCODE TO SOURCE PROGRAMMING LANGUAGE TRANSLATOR
PSEUDOCODE TO SOURCE PROGRAMMING LANGUAGE TRANSLATOR
ijistjournal
 
Ad

Recently uploaded (20)

FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Alliance
 
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Alliance
 
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
Muhammad Rizwan Akram
 
Python Conference Singapore - 19 Jun 2025
Python Conference Singapore - 19 Jun 2025
ninefyi
 
From Manual to Auto Searching- FME in the Driver's Seat
From Manual to Auto Searching- FME in the Driver's Seat
Safe Software
 
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Safe Software
 
June Patch Tuesday
June Patch Tuesday
Ivanti
 
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Alliance
 
Securing Account Lifecycles in the Age of Deepfakes.pptx
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
 
AI VIDEO MAGAZINE - June 2025 - r/aivideo
AI VIDEO MAGAZINE - June 2025 - r/aivideo
1pcity Studios, Inc
 
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
caoyixuan2019
 
The Future of Data, AI, and AR: Innovation Inspired by You.pdf
The Future of Data, AI, and AR: Innovation Inspired by You.pdf
Safe Software
 
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
 
PyCon SG 25 - Firecracker Made Easy with Python.pdf
PyCon SG 25 - Firecracker Made Easy with Python.pdf
Muhammad Yuga Nugraha
 
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Alliance
 
Creating Inclusive Digital Learning with AI: A Smarter, Fairer Future
Creating Inclusive Digital Learning with AI: A Smarter, Fairer Future
Impelsys Inc.
 
Powering Multi-Page Web Applications Using Flow Apps and FME Data Streaming
Powering Multi-Page Web Applications Using Flow Apps and FME Data Streaming
Safe Software
 
Artificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdf
OnBoard
 
MuleSoft for AgentForce : Topic Center and API Catalog
MuleSoft for AgentForce : Topic Center and API Catalog
shyamraj55
 
OpenPOWER Foundation & Open-Source Core Innovations
OpenPOWER Foundation & Open-Source Core Innovations
IBM
 
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Alliance
 
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Alliance
 
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
Muhammad Rizwan Akram
 
Python Conference Singapore - 19 Jun 2025
Python Conference Singapore - 19 Jun 2025
ninefyi
 
From Manual to Auto Searching- FME in the Driver's Seat
From Manual to Auto Searching- FME in the Driver's Seat
Safe Software
 
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Safe Software
 
June Patch Tuesday
June Patch Tuesday
Ivanti
 
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Alliance
 
Securing Account Lifecycles in the Age of Deepfakes.pptx
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
 
AI VIDEO MAGAZINE - June 2025 - r/aivideo
AI VIDEO MAGAZINE - June 2025 - r/aivideo
1pcity Studios, Inc
 
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
caoyixuan2019
 
The Future of Data, AI, and AR: Innovation Inspired by You.pdf
The Future of Data, AI, and AR: Innovation Inspired by You.pdf
Safe Software
 
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
 
PyCon SG 25 - Firecracker Made Easy with Python.pdf
PyCon SG 25 - Firecracker Made Easy with Python.pdf
Muhammad Yuga Nugraha
 
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Alliance
 
Creating Inclusive Digital Learning with AI: A Smarter, Fairer Future
Creating Inclusive Digital Learning with AI: A Smarter, Fairer Future
Impelsys Inc.
 
Powering Multi-Page Web Applications Using Flow Apps and FME Data Streaming
Powering Multi-Page Web Applications Using Flow Apps and FME Data Streaming
Safe Software
 
Artificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdf
OnBoard
 
MuleSoft for AgentForce : Topic Center and API Catalog
MuleSoft for AgentForce : Topic Center and API Catalog
shyamraj55
 
OpenPOWER Foundation & Open-Source Core Innovations
OpenPOWER Foundation & Open-Source Core Innovations
IBM
 

Language processor implementation using python