bugPLY (Python Lex-Yacc) - Bugs: bug #11071, Parsing rror with the LALR method

 
 

bug #11071: Parsing rror with the LALR method

Submitted by:  None
Submitted on:  Sat 20 Nov 2004 11:43:34 PM UTC  
 
Category: NoneSeverity: 3 - Normal
Item Group: NoneStatus: None
Privacy: PublicAssigned to: None
Open/Closed: Open

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

Sat 16 Apr 2005 08:19:35 PM UTC, comment #1:

Here is a very small example that shows the SLR parser working correctly, but the LALR parser failing. Small changes to this code (e.g. substituting expression for conditional_expression and eliminiating the 'expression:conditional_expression' rule) can make the parser generator itself fail.

-------------------------------------------------------------------------

import lex

tokens='CONDITIONAL_OPERATOR COLON LBRACE RBRACE INTEGER' . split()
t_CONDITIONAL_OPERATOR=r'\?'
t_COLON =r':'
t_LBRACE =r'{'
t_RBRACE =r'}'
t_INTEGER =r'\d+'

t_ignore =r' '

def t_error(t ) :
exit('Bad token % r' % t )

import yacc

def p_singleton(p ) :
'set : LBRACE expression RBRACE'
p[0]='begin %s end' % p[2]

def p_expression(p ) :
'expression : conditional_expression'
p[0]=p[1]

def p_conditional_expression_1(p ) :
'conditional_expression : inclusive_OR_expression'
p[0]=p[1]

def p_conditional_expression_2(p ) :
'conditional_expression : inclusive_OR_expression CONDITIONAL_OPERATOR expression COLON conditional_expression'
p[0]='if %s then %s else %s fi' % (p [1], p[3], p[5] )

def p_inclusive_OR_expression_1(p ) :
'inclusive_OR_expression : INTEGER'
p[0]=p[1]

def p_error(p ) :
print "Syntax error: % r" % p

if _name_=="__main__" :
lexer=lex . lex()
# Test the parser
for method in('SLR', 'LALR' ) :
parser=yacc . yacc(tabmodule=method, method=method )
for expression in ('1', '1 ? 2 : 3' ) :
input='{%s} ' % (expression )
print 'method=%r input=%r' % (method, input )
print 'output=%r' % parser . parse(input=input , debug=1 )

Anonymous
Sat 20 Nov 2004 11:43:34 PM UTC, original submission:

Hi,

I wrote a C parser that runs correctly with the SLR method ans fails with the LALR method.

SLR:
yacc: Generating SLR parsing table...
yacc: 13 shift/reduce conflicts

LALR:
yacc: Generating LALR(1) parsing table...
yacc: 1 shift/reduce conflict
LexToken(RBRACE,'}',6)
Whoa. We're hosed

for testing run python cparse.py test.h provided in the attached archive.

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach File(s):
   
   
Comment:
   

Attached Files
file #2036:  test.zip added by None (32KiB - application/x-zip-compressed)

 

Depends on the following items: None found

Items that depend on this one: None found

 

CC list is empty

 

Do you think this task is very important?
If so, you can click here to add your encouragement to it.
This task has 0 encouragements so far.

Only logged-in users can vote.

 

Please enter the title of George Orwell's famous dystopian book (it's a date):

 

 

Follows 1 latest change.

Date Changed By Updated Field Previous Value => Replaced By
Sat 20 Nov 2004 11:43:34 PM UTCNoneAttached File-=>Added test.zip, #1898

Back to the top


Powered by Savane 3.1-cleanup1