Skip to content

Instantly share code, notes, and snippets.

@joshuaboshi
Created April 11, 2013 12:13
Show Gist options
  • Save joshuaboshi/5362900 to your computer and use it in GitHub Desktop.
Save joshuaboshi/5362900 to your computer and use it in GitHub Desktop.
Python PLY: Yacc definition for IF/ELSE-IF/ELSE nesting
def p_block_if_statement(t):
'''block_if_statement : RULE_OPEN IF data RULE_CLOSE statements else_blocks'''
t[0] = _AstNode(Interpreter.r_if, t[3], t[5], t[6])
def p_else_if_blocks(t):
'''else_blocks : else_if_block
| else_block
| RULE_OPEN END RULE_CLOSE'''
t[0] = t[1]
def p_else_block(t):
'''else_block : RULE_OPEN ELSE RULE_CLOSE statements RULE_OPEN END RULE_CLOSE'''
t[0] = t[4]
def p_else_if_block(t):
'''else_if_block : RULE_OPEN ELSE_IF data RULE_CLOSE statements else_blocks'''
t[0] = _AstNode(Interpreter.r_if, t[3], t[5], t[6])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment