Skip to content

Commit

Permalink
shift reduce fixes
Browse files Browse the repository at this point in the history
-changed module to be simpler and
  added a statement_list grammar
  which is right recursive to prevent
  shift reduce warnings
-gave IDENT less precedence than '(' to
  prevent a shift reduce warning
  • Loading branch information
cantora committed Sep 17, 2012
1 parent 61e17fa commit a157cd2
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions pyc_ply_parser.py
Expand Up @@ -53,7 +53,6 @@
'MINUS',
'SEMI',
'IDENT',
'FUNC_CALL'
) + tuple(reserved.values())

t_PLUS = r'\+'
Expand Down Expand Up @@ -100,24 +99,30 @@ def t_error(t):
import compiler

precedence = (
('left', 'IDENT'),
('left', '('),
('left', 'PLUS', 'MINUS'),
('right', 'UMINUS'),
)


def p_module_stmt(m):
'module : statement'
m[0] = compiler.ast.Module(None, compiler.ast.Stmt([]))
m[0].node.nodes.append(m[1])
def p_module(m):
'module : statement_list'
m[0] = compiler.ast.Module(None, m[1])


def p_module_pgm(m):
'module : module statement'
def p_statement_list(sl):
'statement_list : statement statement_list'
sl[0] = sl[2]
sl[0].nodes.insert(0, sl[1])

#pyc_log.log("p_module: %s" % repr([x for x in m]))
def p_empty(t):
'empty : '
pass

m[0] = m[1]
m[0].node.nodes.append(m[2])
def p_statement_list_empty(sl):
'statement_list : empty'
sl[0] = compiler.ast.Stmt([])

def p_statement(t):
'''statement : stmt SEMI
Expand All @@ -130,15 +135,6 @@ def p_print_stmt(t):
t[0] = compiler.ast.Printnl([t[2]], None)


def p_empty(t):
'empty : '
pass

def p_module_empty(m):
'module : empty'
pass


def p_assign_stmt(t):
'stmt : IDENT "=" expr'

Expand All @@ -153,7 +149,7 @@ def p_discard(t):
t[0] = compiler.ast.Discard(t[1])

def p_call_expr(t):
'expr : FUNC_CALL'
'expr : IDENT "(" ")"'

t[0] = compiler.ast.CallFunc(compiler.ast.Name(t[1]), [])

Expand Down

0 comments on commit a157cd2

Please sign in to comment.