hi! i'm working on some code to parse some text. here is my code:

'''
from rply import LexerGenerator, LexingError, ParserGenerator


def lex_spartytalk():
    """
    Lexer function for reading Tokens for spartytalk
    @return lexer of the tokens
    """
    lg = LexerGenerator()

    lg.ignore(r'\s')  # whitespace

    lg.add('GOGREEN', r'gogreen')
    lg.add('GOWHITE', r'gowhite')
    lg.add('SPARTYSAYS', r'spartysays')
    lg.add('SEMICOLON', r';')
    lg.add('NVAR', r'nvar')
    lg.add('SVAR', r'svar')
    lg.add('IDENTIFIER', r'[A-Za-z][A-Za-z0-9]*')

    # 5, 5.0, +5, +5.0, -5, -5.0
    lg.add('NUMBER', r'[0-9]+[.][0-9]+')
    lg.add('NUMBER', r'[0-9]+')
    lg.add('NUMBER', r'[\+][0-9]+[.][0-9]+')
    lg.add('NUMBER', r'[\+][0-9]+')
    lg.add('NUMBER', r'[\-][0-9]+[.][0-9]+')
    lg.add('NUMBER', r'[\-][0-9]+')
    lg.add('STRING', r'["][^"]*["]')
    lg.add('PLUS', r'[+]')
    lg.add('MINUS', r'[\-]')
    lg.add('MUL', r'[*]')
    lg.add('DIV', r'[/]')
    lg.add('ASSIGNMENT', r'[=]')
    lg.add('OPEN_PARENS', r'[(]')
    lg.add('CLOSE_PARENS', r'[)]')

    return lg.build()


def parse_spartytalk(program):
    # Implement this function

   program = """
gogreen;
spartysays "hi";
nvar b = 7;
nvar a = 10 + 20 - 10 * (b * 255) + (a + b);
spartysays a;
spartysays a + b;
spartysays (n + k);
gowhite;
"""

    lexer = lex_spartytalk()
    tokens_iter = lexer.lex(program)

    pg = ParserGenerator(['GOGREEN', 'GOWHITE', 'SPARTYSAYS', 'SEMICOLON', 'NVAR',
                          'SVAR', 'IDENTIFIER', 'NUMBER', 'STRING', 'PLUS',
                          'MINUS', 'MUL', 'DIV', 'ASSIGNMENT', 'OPEN_PARENS',
                          'CLOSE_PARENS'])

    @pg.production('program : GOGREEN SEMICOLON statements GOWHITE SEMICOLON')
    def program(p):
        print("<program> ::= ", end='')
        for i in range(len(p)):
            print(p[i], end='')
            if i != len(p) - 1:
                # avoid trailing whitespace
                print(' ', end='')
            else:
                print('\n', end='')

    @pg.production('statements : statement')
    @pg.production('statements : statements statement')
    def statements(p):
        print("<statements> ::= ", end='')
        for i in range(len(p)):
            print(p[i], end='')
            if i != len(p) - 1:
                # avoid trailing whitespace
                print(' ', end='')
            else:
                print('\n', end='')
        return "<statements>"

    @pg.production('statement : SPARTYSAYS expression SEMICOLON')
    @pg.production('statement : NVAR identifier ASSIGNMENT expression SEMICOLON')
    @pg.production('statement : SVAR identifier ASSIGNMENT expression SEMICOLON')
    @pg.production('statement : identifier ASSIGNMENT expression SEMICOLON')
    def statement(p):
        print("<statement> ::= ", end='')
        for i in range(len(p)):
            print(p[i], end='')
            if i != len(p) - 1:
                # avoid trailing whitespace
                print(' ', end='')
            else:
                print('\n', end='')
        return "<statement>"

    @pg.production('expression : number')
    @pg.production('expression : expression PLUS expression')
    @pg.production('expression : expression MINUS expression')
    @pg.production('expression : OPEN_PARENS expression CLOSE_PARENS')
    @pg.production('expression : expression MUL expression')
    @pg.production('expression : expression DIV expression')
    @pg.production('expression : identifier')
    @pg.production('expression : string')
    def expression(p):
        print("<expression> ::= ", end='')
        for i in range(len(p)):
            print(p[i], end='')
            if i != len(p) - 1:
                # avoid trailing whitespace
                print(' ', end='')
            else:
                print('\n', end='')
        return "<expression>"

    @pg.production('identifier : IDENTIFIER')
    def identifier(p):
        return p[0]

    @pg.production('number : NUMBER')
    def number(p):
        return p[0]

    @pg.production('string : STRING')
    def string(p):
        return p[0]

    parser = pg.build()
    parser.parse(tokens_iter)
'''

here is the expected output:
'''
('<expression> ::= Token(\'STRING\', \'"hi"\')\n'
 "<statement> ::= Token('SPARTYSAYS', 'spartysays') <expression> "
 "Token('SEMICOLON', ';')\n"
 '<statements> ::= <statement>\n'
 "<expression> ::= Token('NUMBER', '7')\n"
 "<statement> ::= Token('NVAR', 'nvar') Token('IDENTIFIER', 'b') "
 "Token('ASSIGNMENT', '=') <expression> Token('SEMICOLON', ';')\n"
 '<statements> ::= <statements> <statement>\n'
 "<expression> ::= Token('NUMBER', '10')\n"
 "<expression> ::= Token('NUMBER', '20')\n"
 "<expression> ::= <expression> Token('PLUS', '+') <expression>\n"
 "<expression> ::= Token('NUMBER', '10')\n"
 "<expression> ::= Token('IDENTIFIER', 'b')\n"
 "<expression> ::= Token('NUMBER', '255')\n"
 "<expression> ::= <expression> Token('MUL', '*') <expression>\n"
 "<expression> ::= Token('OPEN_PARENS', '(') <expression> "
 "Token('CLOSE_PARENS', ')')\n"
 "<expression> ::= <expression> Token('MUL', '*') <expression>\n"
 "<expression> ::= <expression> Token('MINUS', '-') <expression>\n"
 "<expression> ::= Token('IDENTIFIER', 'a')\n"
 "<expression> ::= Token('IDENTIFIER', 'b')\n"
 "<expression> ::= <expression> Token('PLUS', '+') <expression>\n"
 "<expression> ::= Token('OPEN_PARENS', '(') <expression> "
 "Token('CLOSE_PARENS', ')')\n"
 "<expression> ::= <expression> Token('PLUS', '+') <expression>\n"
 "<statement> ::= Token('NVAR', 'nvar') Token('IDENTIFIER', 'a') "
 "Token('ASSIGNMENT', '=') <expression> Token('SEMICOLON', ';')\n"
 '<statements> ::= <statements> <statement>\n'
 "<expression> ::= Token('IDENTIFIER', 'a')\n"
 "<statement> ::= Token('SPARTYSAYS', 'spartysays') <expression> "
 "Token('SEMICOLON', ';')\n"
 '<statements> ::= <statements> <statement>\n'
 "<expression> ::= Token('IDENTIFIER', 'a')\n"
 "<expression> ::= Token('IDENTIFIER', 'b')\n"
 "<expression> ::= <expression> Token('PLUS', '+') <expression>\n"
 "<statement> ::= Token('SPARTYSAYS', 'spartysays') <expression> "
 "Token('SEMICOLON', ';')\n"
 '<statements> ::= <statements> <statement>\n'
 "<expression> ::= Token('IDENTIFIER', 'n')\n"
 "<expression> ::= Token('IDENTIFIER', 'k')\n"
 "<expression> ::= <expression> Token('PLUS', '+') <expression>\n"
 "<expression> ::= Token('OPEN_PARENS', '(') <expression> "
 "Token('CLOSE_PARENS', ')')\n"
 "<statement> ::= Token('SPARTYSAYS', 'spartysays') <expression> "
 "Token('SEMICOLON', ';')\n"
 '<statements> ::= <statements> <statement>\n'
 "<program> ::= Token('GOGREEN', 'gogreen') Token('SEMICOLON', ';') "
 "<statements> Token('GOWHITE', 'gowhite') Token('SEMICOLON', ';')\n")
'''

and here is my output:
'''
('<expression> ::= Token(\'STRING\', \'"hi"\')\n'
 "<statement> ::= Token('SPARTYSAYS', 'spartysays') <expression> "
 "Token('SEMICOLON', ';')\n"
 '<statements> ::= <statement>\n'
 "<expression> ::= Token('NUMBER', '7')\n"
 "<statement> ::= Token('NVAR', 'nvar') Token('IDENTIFIER', 'b') "
 "Token('ASSIGNMENT', '=') <expression> Token('SEMICOLON', ';')\n"
 '<statements> ::= <statements> <statement>\n'
 "<expression> ::= Token('NUMBER', '10')\n"
 "<expression> ::= Token('NUMBER', '20')\n"
 "<expression> ::= Token('NUMBER', '10')\n"
 "<expression> ::= Token('IDENTIFIER', 'b')\n"
 "<expression> ::= Token('NUMBER', '255')\n"
 "<expression> ::= <expression> Token('MUL', '*') <expression>\n"
 "<expression> ::= Token('OPEN_PARENS', '(') <expression> "
 "Token('CLOSE_PARENS', ')')\n"
 "<expression> ::= Token('IDENTIFIER', 'a')\n"
 "<expression> ::= Token('IDENTIFIER', 'b')\n"
 "<expression> ::= <expression> Token('PLUS', '+') <expression>\n"
 "<expression> ::= Token('OPEN_PARENS', '(') <expression> "
 "Token('CLOSE_PARENS', ')')\n"
 "<expression> ::= <expression> Token('PLUS', '+') <expression>\n"
 "<expression> ::= <expression> Token('MUL', '*') <expression>\n"
 "<expression> ::= <expression> Token('MINUS', '-') <expression>\n"
 "<expression> ::= <expression> Token('PLUS', '+') <expression>\n"
 "<statement> ::= Token('NVAR', 'nvar') Token('IDENTIFIER', 'a') "
 "Token('ASSIGNMENT', '=') <expression> Token('SEMICOLON', ';')\n"
 '<statements> ::= <statements> <statement>\n'
 "<expression> ::= Token('IDENTIFIER', 'a')\n"
 "<statement> ::= Token('SPARTYSAYS', 'spartysays') <expression> "
 "Token('SEMICOLON', ';')\n"
 '<statements> ::= <statements> <statement>\n'
 "<expression> ::= Token('IDENTIFIER', 'a')\n"
 "<expression> ::= Token('IDENTIFIER', 'b')\n"
 "<expression> ::= <expression> Token('PLUS', '+') <expression>\n"
 "<statement> ::= Token('SPARTYSAYS', 'spartysays') <expression> "
 "Token('SEMICOLON', ';')\n"
 '<statements> ::= <statements> <statement>\n'
 "<expression> ::= Token('IDENTIFIER', 'n')\n"
 "<expression> ::= Token('IDENTIFIER', 'k')\n"
 "<expression> ::= <expression> Token('PLUS', '+') <expression>\n"
 "<expression> ::= Token('OPEN_PARENS', '(') <expression> "
 "Token('CLOSE_PARENS', ')')\n"
 "<statement> ::= Token('SPARTYSAYS', 'spartysays') <expression> "
 "Token('SEMICOLON', ';')\n"
 '<statements> ::= <statements> <statement>\n'
 "<program> ::= Token('GOGREEN', 'gogreen') Token('SEMICOLON', ';') "
 "<statements> Token('GOWHITE', 'gowhite') Token('SEMICOLON', ';')\n")
'''

can you tell me where i'm going wrong?