Vous êtes sur la page 1sur 7

!

"

! $
& '

((

& '

( )* +,

((

( )* + ,

12 #

:
5

3
3
3

3
3
3
3
3

3
3
3

4
6

:6

3
3

7
7

3
5

:8

0 9
90
4

< %
!
>%

$
@A
'

0=

0=

&" ?
.2 #
! "#
% &

()

:% :
*

"A

B
"

:
.

3:3

'
+

* ?

<

&

?
/
+
* #

" $
-#

"

'

'0= <

!"

B
$

&"
'
'0=
/
+ # ) +
)
#
" #+ #
-#

@/

&"
C DE 0

: :
'
/
CDE 0
CDE 0

&

'
F D 0

" 0=
F D 0
F D 0

FG
FG

" ." A "


= %
:
&
CDE 0 I F D 0

FG

:
I FG

"

1)

#H ! @=&

-#
23 %

(
(2

(2

" 0#0=
#:

2 #

0=

0#0=

" &

4#
%
' * #
5
*
6%
)
%

% #

*#
)
# ) 7 +

%
+

"A

4
98

< %

:
+
) )
)%
(2 )

&

&
2
+)
& (2
# -&
(2
*

? " 0=

!" "
;3 J
"

'
<

&
;= J

% ) +?

#
;3 J
( + % #=

<
"

<

"

1)

*+

" 'I=

'

&"

'@ "
!

#
:

9 '@ "

9 K *@=
:

D '@ "

D '@ "

%
*
()
#7

[E E * E, +]
[E E + E, +]

F
/F

! "A
" 'I
%
!"
? ?
"
4
& x * y + z
"
+
?

+
#

&
# )
#

@/

"
:% % :
@ @L @9@M @9
' " 2 #&

"A 2 #

'
'
>

"

[E E * E , +]
[E E + E, +]

% L
$
*#

B
2
8 )
1 )

A
7
&% )

$
#

[E E * E, +]
[E E + E, +]
<
5

7 7 *M 7 L

[E E + E, +]
[E E + E, +]

[E E * E , +]
[E E + E, +]

" 'I

+))

%
!
'
&% %

&
*

)
&
"# # +
#

[E E + E , +]
[E E + E, +]

'

@ @
#+ %

7
@ @
!
L

K"

<' 2 #

"

;3 J

"#
1%

<

# )
+

;= J
#
#

% I=

@/

&

%
N%
9

"

!
%#

"

*+
*

'
9

'

<
?

'

'
# *
)

"

A+
'+

'

* ?

"

'
%

"

% I=

'

" 2 #

[G S,
[S ,
[S id,
[S id S,
=

% I

$]
$]
$]
$]

[S id ,
[S id S,
[S ,
[S id,
[S id S,

id

'

$]
$]
$]
$]
$]

Input:

a1

sm
Xm
sm-1
Xm-1

s0

% ;

ai

an

Scanner

LR Parsing Engine

Compiler construction
Action

" :

a2

Stack:

&

<

0=

Parser
Generator

Goto

Grammar

LR tables

&OOOOOOOOOOOO

I
0

"

0#%

< % &#
.

'
I

%
':
'

0#0=
%

&

B
parser declarations
%%
grammar rules
%%
auxiliary code

$7
:

$7

"

' 3.

K% % &#
' 3
3
.3
3
.

+)+
B+)+
*# )
*
%#
7 - % #$7 )

B B
#
*
7% #$
)
1# )
)
5
)
+
+
*
-

B B
B B
#
B+)+

=%

P C

exp :

P G

*
P

0Q BQ0 < 0

2<R<2@

exp PLUS exp

+
B B
#

4
B8
+
%# )
+
# +

6 :
P

' 0Q B<HQ

' BQ0

P
P

{ semantic action }

2<R

@> H@> 0
QB<HQ

@/

&
(

?"

'

"

'

"

'

PC
.. / A
,
A
..
" M
C@BO
@BO PG
P
- <2 ! *<0@ @ <H @H2 2K 1
P
:
PP

'

.%

00,

+P +

,G

&
(
?"

: 0
'
"
'
"
0
00,

'
" 'S
2 '%

"A

% S

'

&

" 'I

% &"

% I

"'

% &%

& " 'I

" ' @0 @

B%

5A

1D
'8

E
E1D
'8

F5A
8 GB
B
B

'
%

&< <2 *@H

&< <2 *@H

3 @0 @

. %
'

'

8 & 8 5 A 8 G8 1D
'8

@0 @ " ' 8
3

T
TQ

8
8

83@8
883

.
@

8
8

8@83
838

(+ &
#
%
) +
#*# )
#
#
#
" ' 7 :7

2
@ @ M @ 3

" P
PC
P
P

@ @ 3 L @

%nonassoc EQ NEQ
%left PLUS MINUS

8
8 M

@ 8

8 @ 8

8 ? 8

"'

<H
/

'.. /
0Q B<HQ

A
..
PG
<B@ QB<HQ

P
' 0Q B<HQ
P
' <B@
P
' QB<HQ
PP

%left TIMES DIV


%right EXP

%left prefers reducing

%right prefers shifting


%nonassoc error

&<H
9 /
0Q
/
9 / B<HQ
/
9 /
<B@ /
9B<HQ
/
P

QB<HQ

/ A3

.
PC
P
P
P
P
P
PP

&
0

)
)

/ A3
-

'.. /
..
PG
< H 0Q B<HQ #H2 @>Q#0

<2 #

' K=
' #H2
' 0Q

&

I7
#

&<2 # < H
9<2 # < H
&
K=
9
#H2
9
@>Q#0
9<2
&
0Q
9<2
4

&

A .

0< '

J
+

A .

. -

. "

U :

0@/

" &

00

$,

#)

$ 4# *

) D
)
)@
)
)
)
)
)
)

)+

0 =

/
%

)
@B< K0KH

= #=@H

44

* ?2
<

!
?

-$

%
.

&

Q '

1
%

%
"

)
)

? V

?"
'
% 3

&
)
&

"'

' ?

9IM
/

&

@B< K0KH

@B< K0KH
.MI
/

9<2

&0 #=@H

L ,G

&= #=@H

S ,G

46

@
#

"

%- S

? .
'"

A &

&
(

.D

'

"

01
)

"

)
+)

=
* : -

W
&.

" %

K
&
"

? %
? .

K%

'
.

I
.

0 4#
) *

& .

& "# # 7
#

0(
+*#

47

&L -

%
*

'
09
0

2 ?

&)

%
$ '

%
0

+)

-&

+
% )

#
-& +

' @

" PA %

P A % <2 )

:% +

P A % <H

>7 #

PA %

&
$ 6 K%
% H
$ K @ K ? 6@ K ? 6)
>
# ))
M

# *

))

)+

P "

=<H

'
@> SX #

< H 9#

< H SX @>

9 @B< K0KH @0 @ SX @0 @ 9 SX <H <H @H2

45

let in end

48

: %
0

-: #
(2 *

0=
08

05
*

H ? !" $
(2

(2

+))
7

%
E
+))

+
*

Lexical
analyzer

tokens

Parser

)
)
M

IR
Errors

*
)

text
chars

(2

*M

:
1
+
I7 +
9+ % %
$ 9+
$ 5

)+
7

)
&
+ +
# -

$ # D
(
)+