2. 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
3. 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.
4. 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
7. 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
12. Configuration Format of Language
Grammar
EBNF
rule
program ::=
EBNF
Program ID ; block .
rule in configuration
programme:
- [program, id, ;, Block, "."]
16. 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
17. 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.
18. 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
19. 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