Skip to content

Commit 47a8bef

Browse files
readme updated
1 parent 65cca09 commit 47a8bef

File tree

1 file changed

+61
-10
lines changed

1 file changed

+61
-10
lines changed

README.md

+61-10
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,33 @@ There are 6 phases in a compiler. Each of these phases help in converting the hi
2323

2424
![](images/1.png)
2525

26-
**Lexical analyzer:** Reads the source code and converts it to tokens. Tokens are defined by regular expressions. Which are understood by the lexical analyzer. And the analyzer also removes the comments in the code and whitespaces.
26+
**Lexical analyzer:**
27+
Reads the source code and converts it to tokens. Tokens are defined by regular expressions. Which are understood by the lexical analyzer. And the analyzer also removes the comments in the code and whitespaces.
2728

28-
**Syntax analyzer:** this is also known as the parser. It reads the tokens one by one and uses context free grammar to construct the parse tree.
29+
**Syntax analyzer:**
30+
This is also known as the parser. It reads the tokens one by one and uses context free grammar to construct the parse tree.
2931

30-
**Semantic analyzer:** verifies the parse tree, and does - type checking, Label checking and Flow control checking.
32+
**Semantic analyzer:**
33+
Verifies the parse tree, and does - type checking, Label checking and Flow control checking.
3134

32-
**Intermediate Code Generator:** Generates intermediate code which can be executed by the machine. Till the intermediate code it's the same for every compiler. But Intermediate code generator and steps after that depends on the platform the code is compiled for.
35+
**Intermediate Code Generator:**
36+
Generates intermediate code which can be executed by the machine. Till the intermediate code it's the same for every compiler. But Intermediate code generator and steps after that depends on the platform the code is compiled for.
3337

34-
**Code optimizer:** transforms the intermediate code in a manner that it uses fewer resources and runs faster. But the meaning of the code is not altered. And there are two types of optimization, machine dependent and machine independent.
38+
**Code optimizer:**
39+
Transforms the intermediate code in a manner that it uses fewer resources and runs faster. But the meaning of the code is not altered. And there are two types of optimization, machine dependent and machine independent.
3540

36-
**Target code generator:** This is the final step of the compilation process. It rewrites the optimized code into machine language.
41+
**Target code generator:**
42+
This is the final step of the compilation process. It rewrites the optimized code into machine language.
3743

3844

39-
### **What is the Symbol table**
40-
45+
**What is the Symbol table?**
4146
Symbol table is a data structure maintained and being used by the compiler which contains all the identifier names with their symbols. It helps the compiler to find the identifiers quickly.
4247

4348
# **Design**
4449

4550
## **Architecture**
4651

47-
The language supports control structures and variable declarations. And it supports integer, boolean variable types. Boolen expressions only appear in control structures. The language supports arithmetic operations (addition, subtraction, multiplication, division) on integers and has IF-THEN-ELSE, IF-THEN and WHILE-DO control structures.
52+
The language supports **control structures** and **variable declarations**. And it supports **integer** , **boolean** variable types. Boolen expressions only appear in control structures. The language supports arithmetic operations **(addition, subtraction, multiplication, division)** on integers and has <code> IF-THEN-ELSE, IF-THEN </code> and <code> WHILE-DO </code> control structures.
4853

4954
![](images/2.png)
5055

@@ -56,8 +61,54 @@ The language supports control structures and variable declarations. And it suppo
5661

5762
## **Grammar**
5863

59-
![](images/grammar.png)
64+
<!--- ![](images/grammar.png) --->
65+
```
66+
G = { N , T , P , S }
67+
68+
N = { prgmbody, stmntlist, stmnt, explist, expitem, boolreln}
69+
70+
T = { PRINT, IF,THEN, ELSE, WHILE, DO, AND, OR, PLUS, MINUS, MULTI, OVER, SEMI,
71+
LESS, BIGGER, EQUAL, LAPREN, RPAREN, ASSIGN, LESSEQ, BIGEQ }
72+
73+
S = { prgmbody }
74+
75+
P = {
76+
prgmbody → stmntlist
77+
78+
stmntlist → stmnt-list stmnt
79+
80+
stmnt → START explist END
81+
| PRINT expitem SEMI
82+
| WHILE expitem DO stmnt
83+
| IF expitem THEN stmnt
84+
| IF expitem THEN stmnt ELSE stmnt
85+
| VARIABLE ASSIGN expitem SEMI
86+
87+
explist → expitem
88+
| explist SEMI expitem
89+
90+
expitem → NUMBER
91+
| expitem PLUS expitem
92+
| expitem MINUS expitem
93+
| expitem MULTI expitem
94+
| expitem OVER expitem
95+
| FALSE
96+
| TRUE
97+
| VARIABLE
98+
| boolreln
99+
| LAPREN expitem RPAREN
100+
| expitem OR expitem
101+
| expitem AND expitem
102+
| NOT expitem
103+
104+
boolreln → expitem LESS expitem
105+
| expitem LESSEQ expitem
106+
| expitem EQUAL expitem
107+
| expitem BIGEQ expitem
108+
| expitem BIGGER expitem
60109
110+
}
111+
```
61112
## **NDFA and DFA**
62113

63114
When we consider the sample statement

0 commit comments

Comments
 (0)