Pour la calculette, Python génère deux fichiers annexes
• un fichier parser.out :
Created by PLY version 3.11 (http://www.dabeaz.com/ply)
Grammar
Rule 0 S' -> S
Rule 1 S -> Nombre
Rule 2 S -> S PLUS S
Rule 3 S -> S MOINS S
Rule 4 S -> S MULT S
Rule 5 S -> S DIV S
Rule 6 S -> OUVR S FERM
Terminals, with rules where they appear
DIV : 5
FERM : 6
MOINS : 3
MULT : 4
Nombre : 1
OUVR : 6
PLUS : 2
error :
Nonterminals, with rules where they appear
S : 2 2 3 3 4 4 5 5 6 0
Parsing method: LALR
state 0
(0) S' -> . S
(1) S -> . Nombre
(2) S -> . S PLUS S
(3) S -> . S MOINS S
(4) S -> . S MULT S
(5) S -> . S DIV S
(6) S -> . OUVR S FERM
Nombre shift and go to state 2
OUVR shift and go to state 3
S shift and go to state 1
state 1
(0) S' -> S .
(2) S -> S . PLUS S
(3) S -> S . MOINS S
(4) S -> S . MULT S
(5) S -> S . DIV S
PLUS shift and go to state 4
MOINS shift and go to state 5
MULT shift and go to state 6
DIV shift and go to state 7
state 2
(1) S -> Nombre .
PLUS reduce using rule 1 (S -> Nombre .)
MOINS reduce using rule 1 (S -> Nombre .)
MULT reduce using rule 1 (S -> Nombre .)
DIV reduce using rule 1 (S -> Nombre .)
$end reduce using rule 1 (S -> Nombre .)
FERM reduce using rule 1 (S -> Nombre .)
state 3
(6) S -> OUVR . S FERM
(1) S -> . Nombre
(2) S -> . S PLUS S
(3) S -> . S MOINS S
(4) S -> . S MULT S
(5) S -> . S DIV S
(6) S -> . OUVR S FERM
Nombre shift and go to state 2
OUVR shift and go to state 3
S shift and go to state 8
state 4
(2) S -> S PLUS . S
(1) S -> . Nombre
(2) S -> . S PLUS S
(3) S -> . S MOINS S
(4) S -> . S MULT S
(5) S -> . S DIV S
(6) S -> . OUVR S FERM
Nombre shift and go to state 2
OUVR shift and go to state 3
S shift and go to state 9
state 5
(3) S -> S MOINS . S
(1) S -> . Nombre
(2) S -> . S PLUS S
(3) S -> . S MOINS S
(4) S -> . S MULT S
(5) S -> . S DIV S
(6) S -> . OUVR S FERM
Nombre shift and go to state 2
OUVR shift and go to state 3
S shift and go to state 10
state 6
(4) S -> S MULT . S
(1) S -> . Nombre
(2) S -> . S PLUS S
(3) S -> . S MOINS S
(4) S -> . S MULT S
(5) S -> . S DIV S
(6) S -> . OUVR S FERM
Nombre shift and go to state 2
OUVR shift and go to state 3
S shift and go to state 11
state 7
(5) S -> S DIV . S
(1) S -> . Nombre
(2) S -> . S PLUS S
(3) S -> . S MOINS S
(4) S -> . S MULT S
(5) S -> . S DIV S
(6) S -> . OUVR S FERM
Nombre shift and go to state 2
OUVR shift and go to state 3
S shift and go to state 12
state 8
(6) S -> OUVR S . FERM
(2) S -> S . PLUS S
(3) S -> S . MOINS S
(4) S -> S . MULT S
(5) S -> S . DIV S
FERM shift and go to state 13
PLUS shift and go to state 4
MOINS shift and go to state 5
MULT shift and go to state 6
DIV shift and go to state 7
state 9
(2) S -> S PLUS S .
(2) S -> S . PLUS S
(3) S -> S . MOINS S
(4) S -> S . MULT S
(5) S -> S . DIV S
PLUS reduce using rule 2 (S -> S PLUS S .)
MOINS reduce using rule 2 (S -> S PLUS S .)
$end reduce using rule 2 (S -> S PLUS S .)
FERM reduce using rule 2 (S -> S PLUS S .)
MULT shift and go to state 6
DIV shift and go to state 7
! MULT [ reduce using rule 2 (S -> S PLUS S .) ]
! DIV [ reduce using rule 2 (S -> S PLUS S .) ]
! PLUS [ shift and go to state 4 ]
! MOINS [ shift and go to state 5 ]
state 10
(3) S -> S MOINS S .
(2) S -> S . PLUS S
(3) S -> S . MOINS S
(4) S -> S . MULT S
(5) S -> S . DIV S
PLUS reduce using rule 3 (S -> S MOINS S .)
MOINS reduce using rule 3 (S -> S MOINS S .)
$end reduce using rule 3 (S -> S MOINS S .)
FERM reduce using rule 3 (S -> S MOINS S .)
MULT shift and go to state 6
DIV shift and go to state 7
! MULT [ reduce using rule 3 (S -> S MOINS S .) ]
! DIV [ reduce using rule 3 (S -> S MOINS S .) ]
! PLUS [ shift and go to state 4 ]
! MOINS [ shift and go to state 5 ]
state 11
(4) S -> S MULT S .
(2) S -> S . PLUS S
(3) S -> S . MOINS S
(4) S -> S . MULT S
(5) S -> S . DIV S
PLUS reduce using rule 4 (S -> S MULT S .)
MOINS reduce using rule 4 (S -> S MULT S .)
MULT reduce using rule 4 (S -> S MULT S .)
DIV reduce using rule 4 (S -> S MULT S .)
$end reduce using rule 4 (S -> S MULT S .)
FERM reduce using rule 4 (S -> S MULT S .)
! PLUS [ shift and go to state 4 ]
! MOINS [ shift and go to state 5 ]
! MULT [ shift and go to state 6 ]
! DIV [ shift and go to state 7 ]
state 12
(5) S -> S DIV S .
(2) S -> S . PLUS S
(3) S -> S . MOINS S
(4) S -> S . MULT S
(5) S -> S . DIV S
PLUS reduce using rule 5 (S -> S DIV S .)
MOINS reduce using rule 5 (S -> S DIV S .)
MULT reduce using rule 5 (S -> S DIV S .)
DIV reduce using rule 5 (S -> S DIV S .)
$end reduce using rule 5 (S -> S DIV S .)
FERM reduce using rule 5 (S -> S DIV S .)
! PLUS [ shift and go to state 4 ]
! MOINS [ shift and go to state 5 ]
! MULT [ shift and go to state 6 ]
! DIV [ shift and go to state 7 ]
state 13
(6) S -> OUVR S FERM .
PLUS reduce using rule 6 (S -> OUVR S FERM .)
MOINS reduce using rule 6 (S -> OUVR S FERM .)
MULT reduce using rule 6 (S -> OUVR S FERM .)
DIV reduce using rule 6 (S -> OUVR S FERM .)
$end reduce using rule 6 (S -> OUVR S FERM .)
FERM reduce using rule 6 (S -> OUVR S FERM .)
• un fichier parsetab.py :
# parsetab.py
# This file is automatically generated. Do not edit.
# pylint: disable=W,C,R
_tabversion = '3.10'
_lr_method = 'LALR'
_lr_signature = 'leftPLUSMOINSleftMULTDIVDIV FERM MOINS MULT Nombre OUVR PLUSS : NombreS : S PLUS SS : S MOINS SS : S MULT SS : S DIV SS : OUVR S FERM'
_lr_action_items = {'Nombre':([0,3,4,5,6,7,],[2,2,2,2,2,2,]),'OUVR':([0,3,4,5,6,7,],[3,3,3,3,3,3,]),'$end':([1,2,9,10,11,12,13,],[0,-1,-2,-3,-4,-5,-6,]),'PLUS':([1,2,8,9,10,11,12,13,],[4,-1,4,-2,-3,-4,-5,-6,]),'MOINS':([1,2,8,9,10,11,12,13,],[5,-1,5,-2,-3,-4,-5,-6,]),'MULT':([1,2,8,9,10,11,12,13,],[6,-1,6,6,6,-4,-5,-6,]),'DIV':([1,2,8,9,10,11,12,13,],[7,-1,7,7,7,-4,-5,-6,]),'FERM':([2,8,9,10,11,12,13,],[-1,13,-2,-3,-4,-5,-6,]),}
_lr_action = {}
for _k, _v in _lr_action_items.items():
for _x,_y in zip(_v[0],_v[1]):
if not _x in _lr_action: _lr_action[_x] = {}
_lr_action[_x][_k] = _y
del _lr_action_items
_lr_goto_items = {'S':([0,3,4,5,6,7,],[1,8,9,10,11,12,]),}
_lr_goto = {}
for _k, _v in _lr_goto_items.items():
for _x, _y in zip(_v[0], _v[1]):
if not _x in _lr_goto: _lr_goto[_x] = {}
_lr_goto[_x][_k] = _y
del _lr_goto_items
_lr_productions = [
("S' -> S","S'",1,None,None,None),
('S -> Nombre','S',1,'p_S_nombre','calculette.py',63),
('S -> S PLUS S','S',3,'p_S_addition','calculette.py',71),
('S -> S MOINS S','S',3,'p_S_soustraction','calculette.py',78),
('S -> S MULT S','S',3,'p_S_multiplication','calculette.py',81),
('S -> S DIV S','S',3,'p_S_division','calculette.py',84),
('S -> OUVR S FERM','S',3,'p_S_parentheses','calculette.py',89),
]