Two's Complement Representation of Negative Numbers
Two's Complement Representation of Negative Numbers
compilatio
n
• This is the first stage
• It starts by converting lexemes (words)
into a series of tokens
• As it reads the source code it reads it
letter by letter.
What is Identifier
Keyword
Any function or variable name
As, If, Else, Endif, Function, End
consider Separator
Function, return, Then
() &
ed as Operator +, -, *, /, %, ^, DIV, MOD, <, <=, >,
>=
valid Literal Hello world
tokens
Number -4, 0, 3, 4
Quote “”
Boolean True, False
Datatype Integer, Decimal, String, Boolean,
Character
Function checkScore(score As Interger) Then
if score > 75 Then
return"pass"
Example else
of
return "fail"
endif
Lexical endFunction
[Keyword : Then]
What next
1 checkScore Identifier
2
• ( Separator
Index
•Token
3 score Identifier
•4Token class As Keyword
The next is that after we •5Data Integer Datatype
created the token streams
6 ) Separator
from the lexemes in the
7 If Keyword
source code, it is time to This is
8 > Operator added at
input those tokens into a
symbol table. 9 75 Literal the
10 Then Keyword syntax
11 Return Keyword analysis
From our example we will 12 “ Quote stage
assume that the lexer: 13 Pass Literal
14 “ Quote
- Only creates one symbol
15 Else Keyword
table
16 “ Quote
- Does not store duplicate 17 Fail Literal
entries 18 “ Quote
Easier semantic analysis: Once the parse tree has been built, the
compiler can do semantic analysis much more easily since
semantic analysis depends on the structural information
provided by the parse tree.
Disadvantages
Parsing is a complicated process and the quality of the parser itself can
drastically affect the performance of the outputted code. It is challenging to
provide a parser for languages. In particular, it is even more complicated for
languages that have ambiguous syntaxes.