125
125
"Precedence" , "Spec" , "Token" , "Lr" , "Glr" ,
126
126
"ModuleSpecSource" ]
127
127
128
- from six import print_
129
- from six .moves import range
130
-
131
128
from parsing .errors import (ParsingError , SpecError , # noqa
132
129
UnexpectedToken , AnyException ) # noqa
133
130
from parsing .grammar import (Precedence , Production , SymbolSpec , # noqa
@@ -216,7 +213,7 @@ def eoi(self):
216
213
assert self ._stack [- 1 ][0 ] == token # <$>.
217
214
if self ._verbose :
218
215
self ._printStack ()
219
- print_ (" --> accept" )
216
+ print (" --> accept" )
220
217
self ._stack .pop ()
221
218
222
219
self ._start = [self ._stack [1 ][0 ]]
@@ -225,7 +222,7 @@ def eoi(self):
225
222
def _act (self , sym , symSpec ):
226
223
if self ._verbose :
227
224
self ._printStack ()
228
- print_ ("INPUT: %r" % sym )
225
+ print ("INPUT: %r" % sym )
229
226
230
227
while True :
231
228
top = self ._stack [- 1 ]
@@ -237,7 +234,7 @@ def _act(self, sym, symSpec):
237
234
action = actions [0 ]
238
235
239
236
if self ._verbose :
240
- print_ (" --> %r" % action )
237
+ print (" --> %r" % action )
241
238
if type (action ) == ShiftAction :
242
239
self ._stack .append ((sym , action .nextState ))
243
240
break
@@ -249,16 +246,16 @@ def _act(self, sym, symSpec):
249
246
self ._printStack ()
250
247
251
248
def _printStack (self ):
252
- print_ ("STACK:" , end = ' ' )
249
+ print ("STACK:" , end = ' ' )
253
250
for node in self ._stack :
254
- print_ ("%r" % node [0 ], end = ' ' )
255
- print_ ()
256
- print_ (" " , end = ' ' )
251
+ print ("%r" % node [0 ], end = ' ' )
252
+ print ()
253
+ print (" " , end = ' ' )
257
254
for node in self ._stack :
258
- print_ ("%r%s" % (
255
+ print ("%r%s" % (
259
256
node [1 ], (" " * (len ("%r" % node [0 ]) - len ("%r" % node [1 ])))),
260
257
end = ' ' )
261
- print_ ()
258
+ print ()
262
259
263
260
def _reduce (self , production ):
264
261
nRhs = len (production .rhs )
@@ -411,8 +408,8 @@ def token(self, token):
411
408
Feed a token to the parser.
412
409
"""
413
410
if self ._verbose :
414
- print_ ("%s" % ("-" * 80 ))
415
- print_ ("INPUT: %r" % token )
411
+ print ("%s" % ("-" * 80 ))
412
+ print ("INPUT: %r" % token )
416
413
tokenSpec = self ._spec ._sym2spec [type (token )]
417
414
self ._act (token , tokenSpec )
418
415
if len (self ._gss ) == 0 :
@@ -431,7 +428,7 @@ def eoi(self):
431
428
for path in top .paths ():
432
429
assert len (path ) == 5
433
430
if self ._verbose :
434
- print_ (" --> accept %r" % path )
431
+ print (" --> accept %r" % path )
435
432
edge = path [1 ]
436
433
assert isinstance (edge .value , Nonterm )
437
434
assert edge .value .symSpec == self ._spec ._userStartSym
@@ -441,8 +438,8 @@ def eoi(self):
441
438
raise UnexpectedToken ("Unexpected end of input" )
442
439
443
440
if self ._verbose :
444
- print_ ("Start: %r" % self ._start )
445
- print_ ("%s" % ("-" * 80 ))
441
+ print ("Start: %r" % self ._start )
442
+ print ("%s" % ("-" * 80 ))
446
443
447
444
def _act (self , sym , symSpec ):
448
445
self ._reductions (sym , symSpec )
@@ -477,37 +474,37 @@ def _reductions(self, sym, symSpec):
477
474
epsilons [action .production ] = [top ]
478
475
workQ .append ((path , action .production ))
479
476
if self ._verbose :
480
- print_ (" --> enqueue(a) %r" %
477
+ print (" --> enqueue(a) %r" %
481
478
action .production )
482
- print_ (" %r" % path )
479
+ print (" %r" % path )
483
480
elif top not in epsilons [action .production ]:
484
481
assert len (
485
482
[path for path in top .paths (0 )]) == 1
486
483
path = [p for p in top .paths (0 )][0 ]
487
484
epsilons [action .production ].append (top )
488
485
workQ .append ((path , action .production ))
489
486
if self ._verbose :
490
- print_ (" --> enqueue(b) %r" %
487
+ print (" --> enqueue(b) %r" %
491
488
action .production )
492
- print_ (" %r" % path )
489
+ print (" %r" % path )
493
490
else :
494
491
# Iterate over all reduction paths through stack
495
492
# and enqueue them.
496
493
for path in top .paths (len (action .production .rhs )):
497
494
workQ .append ((path , action .production ))
498
495
if self ._verbose :
499
- print_ (" --> enqueue(c) %r" %
496
+ print (" --> enqueue(c) %r" %
500
497
action .production )
501
- print_ (" %r" % path )
498
+ print (" %r" % path )
502
499
i += 1
503
500
504
501
# Process the work queue.
505
502
while len (workQ ) > 0 :
506
503
(path , production ) = workQ .pop (0 )
507
504
508
505
if self ._verbose :
509
- print_ (" --> reduce %r" % production )
510
- print_ (" %r" % path )
506
+ print (" --> reduce %r" % production )
507
+ print (" %r" % path )
511
508
nReduces += 1
512
509
513
510
self ._reduce (workQ , epsilons , path , production , symSpec )
@@ -538,14 +535,14 @@ def _reduce(self, workQ, epsilons, path, production, symSpec):
538
535
# There is already a below<--top link, so merge
539
536
# competing interpretations.
540
537
if self ._verbose :
541
- print_ (" --> merge %r <--> %r" % (edge .value , r ))
538
+ print (" --> merge %r <--> %r" % (edge .value , r ))
542
539
value = production .lhs .nontermType .merge (edge .value , r )
543
540
if self ._verbose :
544
541
if value == edge .value :
545
- print_ (" %s" %
542
+ print (" %s" %
546
543
("-" * len ("%r" % edge .value )))
547
544
else :
548
- print_ (" %s %s" %
545
+ print (" %s %s" %
549
546
((" " * len ("%r" % edge .value )),
550
547
"-" * len ("%r" % r )))
551
548
edge .value = value
@@ -555,7 +552,7 @@ def _reduce(self, workQ, epsilons, path, production, symSpec):
555
552
# Create a new below<--top link.
556
553
edge = Gsse (below , top , r )
557
554
if self ._verbose :
558
- print_ (" --> shift(b) %r" % top )
555
+ print (" --> shift(b) %r" % top )
559
556
560
557
# Enqueue reduction paths that were created as a result of
561
558
# the new link.
@@ -569,7 +566,7 @@ def _reduce(self, workQ, epsilons, path, production, symSpec):
569
566
below , r , self ._spec ._goto [below .nextState ][production .lhs ])
570
567
self ._gss .append (top )
571
568
if self ._verbose :
572
- print_ (" --> shift(c) %r" %
569
+ print (" --> shift(c) %r" %
573
570
self ._spec ._goto [below .nextState ][production .lhs ])
574
571
self ._enqueueLimitedReductions (workQ , epsilons , top .edge , symSpec )
575
572
@@ -593,27 +590,27 @@ def _enqueueLimitedReductions(self, workQ, epsilons, edge, symSpec):
593
590
epsilons [action .production ] = [top ]
594
591
workQ .append ((path , action .production ))
595
592
if self ._verbose :
596
- print_ (" --> enqueue(d) %r" %
593
+ print (" --> enqueue(d) %r" %
597
594
action .production )
598
- print_ (" %r" % path )
595
+ print (" %r" % path )
599
596
elif top not in epsilons [action .production ]:
600
597
path = [top ]
601
598
epsilons [action .production ].append (top )
602
599
workQ .append ((path , action .production ))
603
600
if self ._verbose :
604
- print_ (" --> enqueue(e) %r" %
601
+ print (" --> enqueue(e) %r" %
605
602
action .production )
606
- print_ (" %r" % path )
603
+ print (" %r" % path )
607
604
else :
608
605
# Iterate over all reduction paths through stack
609
606
# and enqueue them if they incorporate edge.
610
607
for path in top .paths (len (action .production .rhs )):
611
608
if edge in path [1 ::2 ]:
612
609
workQ .append ((path , action .production ))
613
610
if self ._verbose :
614
- print_ (" --> enqueue(f) %r" %
611
+ print (" --> enqueue(f) %r" %
615
612
action .production )
616
- print_ (" %r" % path )
613
+ print (" %r" % path )
617
614
618
615
def _shifts (self , sym , symSpec ):
619
616
prevGss = self ._gss
@@ -636,7 +633,7 @@ def _shifts(self, sym, symSpec):
636
633
top = Gssn (topA , sym , action .nextState )
637
634
self ._gss .append (top )
638
635
if self ._verbose :
639
- print_ (" --> shift(a) %d" % action .nextState )
636
+ print (" --> shift(a) %d" % action .nextState )
640
637
nShifts += 1
641
638
if self ._verbose :
642
639
if nShifts > 0 :
@@ -647,10 +644,10 @@ def _printStack(self):
647
644
for top in self ._gss :
648
645
for path in top .paths ():
649
646
if i == 0 :
650
- print_ ("STK 0:" , end = ' ' )
647
+ print ("STK 0:" , end = ' ' )
651
648
else :
652
- print_ (" %d:" % i , end = ' ' )
649
+ print (" %d:" % i , end = ' ' )
653
650
for elm in path :
654
- print_ ("%r" % elm , end = ' ' )
655
- print_ ()
651
+ print ("%r" % elm , end = ' ' )
652
+ print ()
656
653
i += 1
0 commit comments