You are on page 1of 8

syntax analysis

) (context _free grammar-:


) (digits
.. , 6+8-5 , 3-1 , 9-5+2
-:
-:
list +digit

.List

list - digit

.List

digit

.List

0|1|2|.|9

Digit

-:
terminal analysis (token):- +,-,0,1,2,.,9(1
list(2

non-termenal analysis:-

-:production (3
.
.
-:
.
list +digit l list digit|digit
.start symbol:- list (4

.List

parse tree

A
-:
A
XYZ
)(
A
Z

-:
(1 ) (root )start symbol).
(2 ) (token
(3
.
)nontermenal).
(4 ) (A X1,X2,
)( )
..Xn
(
)production
A
)X1,X2,
..Xn
X1,X2,..Xn .

>>
).(

-------------------------------------------------- )( )
(2+5-9

(Root(start symbol

token
.

) (begin-end
);(.
:
)(2

)(1
)(3

begin

begin
statement
;statement
)end
;statement

Begin

End
)empty
)(one statement

............
;Statement
End
)more
(than one statement
---------------------------------------------------------------- -:
)) ((production

end
stmt_list

opt_stmts

begin

Block

/opt_stmts

stmt_list;stmt/stmt

;stmt_list

-:
.Termenal symbol:- begin,end(1
nontermenal symbol:-opt_stmts,stmt_list,stmt,block(2
-:3)production
.start symbol:- block(4

)(stmt_list ) (list
);( )(+,-) (stmt ) (digit
)left to right

(order ) (a,b)( )(
a b a
b
-:
) (parsing .
-----------------------------------------------------------------

) (
Ambiguity
) , (

.

).
(.

) (unambigiuity
)( )
(

)( ) (list )
(digit )
(string
String+ String/ String- String/ String

String


-: )(2+5-9

-:
2=(2+5)-9


-:
)6=2+(5-9


.

Operators

Associativity of

) (digit

-: ) (+ ) (-
). (associate to the left

)*( )( associate
. ((to the left

) (digit ) (-,+

)2+(5-9

)(2+5-9

-: )=( )
(C .

)a=b=c

)a=(b=c

)C


-:

-:

.

) (2+5-9 ))C
a=b=c

* )(

precedent of operator
) (-,+,*,
)(
.

+,

)(*,

-:

)(

),*,
((/) -,+ -:
) term (
) Expr (

-:

di
git0|1|2|9

You might also like