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

More Related Content

PPTX
Domain specific languages - progressive f sharp tutorials nyc 2012
PPTX
BUILDING BASIC STRECH SQL COMPILER
PPT
Functions in php
PDF
Cs3430 lecture 15
PDF
Anonymous Functions in PHP 5.3 - Matthew Weier O’Phinney
PPTX
Yacc (yet another compiler compiler)
PPT
Yacc lex
PPTX
Domain specific languages - progressive f sharp tutorials nyc 2012
BUILDING BASIC STRECH SQL COMPILER
Functions in php
Cs3430 lecture 15
Anonymous Functions in PHP 5.3 - Matthew Weier O’Phinney
Yacc (yet another compiler compiler)
Yacc lex

What's hot (13)

PPT
Class 3 - PHP Functions
PPT
Introduction to php php++
PDF
Why Java Sucks and C# Rocks (Final)
PPT
Php Chapter 2 3 Training
PDF
PHP Unit 3 functions_in_php_2
DOC
Lex tool manual
PDF
TI1220 Lecture 14: Domain-Specific Languages
PPTX
Lex Tool
PPTX
Perl bhargav
PDF
PHP 7.0 new features (and new interpreter)
PPTX
Class 3 - PHP Functions
Introduction to php php++
Why Java Sucks and C# Rocks (Final)
Php Chapter 2 3 Training
PHP Unit 3 functions_in_php_2
Lex tool manual
TI1220 Lecture 14: Domain-Specific Languages
Lex Tool
Perl bhargav
PHP 7.0 new features (and new interpreter)
Ad

Viewers also liked (7)

PPTX
Ltr 1 Powerpoint
PPTX
Боломж систем MNB
PPTX
Doing Azure With PowerShell
PPTX
PowerShell 101 - What is it and Why should YOU Care!
ODP
Linux Introduction (Commands)
PDF
Learn 90% of Python in 90 Minutes
PPT
Introduction to Python
Ltr 1 Powerpoint
Боломж систем MNB
Doing Azure With PowerShell
PowerShell 101 - What is it and Why should YOU Care!
Linux Introduction (Commands)
Learn 90% of Python in 90 Minutes
Introduction to Python
Ad

Similar to Language processor implementation using python (20)

PDF
A Brief Overview of (Static) Program Query Languages
PPTX
Python programming workshop session 1
PPT
Visual Studio .NET2010
PPTX
PERTEMUAN 1 - MENGENAL ENVIRONTMENT PROGRAM VISUAL C#.pptx
PPT
Introduction to c_sharp
PPTX
Python basics
PPTX
Intro in understanding to C programming .pptx
PPTX
Intro in understanding to C programming .pptx
PPT
Groovy Introduction - JAX Germany - 2008
PPTX
Presentation c++
PDF
What we can learn from Rebol?
PPT
Groovy Update - JavaPolis 2007
PPTX
c programming session 1.pptx
PPT
An Overview Of Python With Functional Programming
PPTX
KScope14 Jython Scripting
PPT
javaeanjjisjejrehurfhjhjfeauojksfjdi.ppt
PPTX
Introduction to c programming
PPT
Java introduction
PPT
270_1_CIntro_Up_To_Functions.ppt 0478 computer
PPT
CIntro_Up_To_Functions.ppt;uoooooooooooooooooooo
A Brief Overview of (Static) Program Query Languages
Python programming workshop session 1
Visual Studio .NET2010
PERTEMUAN 1 - MENGENAL ENVIRONTMENT PROGRAM VISUAL C#.pptx
Introduction to c_sharp
Python basics
Intro in understanding to C programming .pptx
Intro in understanding to C programming .pptx
Groovy Introduction - JAX Germany - 2008
Presentation c++
What we can learn from Rebol?
Groovy Update - JavaPolis 2007
c programming session 1.pptx
An Overview Of Python With Functional Programming
KScope14 Jython Scripting
javaeanjjisjejrehurfhjhjfeauojksfjdi.ppt
Introduction to c programming
Java introduction
270_1_CIntro_Up_To_Functions.ppt 0478 computer
CIntro_Up_To_Functions.ppt;uoooooooooooooooooooo

Recently uploaded (20)

PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
Spectroscopy.pptx food analysis technology
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Machine learning based COVID-19 study performance prediction
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
Cloud computing and distributed systems.
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Approach and Philosophy of On baking technology
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Electronic commerce courselecture one. Pdf
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
“AI and Expert System Decision Support & Business Intelligence Systems”
Spectroscopy.pptx food analysis technology
Reach Out and Touch Someone: Haptics and Empathic Computing
Machine learning based COVID-19 study performance prediction
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Encapsulation_ Review paper, used for researhc scholars
NewMind AI Weekly Chronicles - August'25 Week I
MYSQL Presentation for SQL database connectivity
Cloud computing and distributed systems.
Building Integrated photovoltaic BIPV_UPV.pdf
sap open course for s4hana steps from ECC to s4
Advanced methodologies resolving dimensionality complications for autism neur...
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Approach and Philosophy of On baking technology
Network Security Unit 5.pdf for BCA BBA.
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Unlocking AI with Model Context Protocol (MCP)
Electronic commerce courselecture one. Pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton

Language processor implementation using python