def convert_atom(atom):
    if atom.LETTER_NO_E():
        subscriptName = ''
        s = atom.LETTER_NO_E().getText()
        if (s == 'I'):
            return sympy.I
        if atom.subexpr():
            subscript = None
            if atom.subexpr().expr():
                subscript = convert_expr(atom.subexpr().expr())
            else:
                subscript = convert_atom(atom.subexpr().atom())
            subscriptName = (('_{' + StrPrinter().doprint(subscript)) + '}')
        return sympy.Symbol((atom.LETTER_NO_E().getText() + subscriptName), real=True)
    elif atom.GREEK_LETTER():
        s = atom.GREEK_LETTER().getText()[1:]
        if atom.subexpr():
            subscript = None
            if atom.subexpr().expr():
                subscript = convert_expr(atom.subexpr().expr())
            else:
                subscript = convert_atom(atom.subexpr().atom())
            subscriptName = StrPrinter().doprint(subscript)
            s += (('_{' + subscriptName) + '}')
        return sympy.Symbol(s, real=True)
    elif atom.accent():
        name = atom.accent().start.text[1:]
        if (name in ['bar', 'overline']):
            name = 'bar'
        base = atom.accent().base.getText()
        s = (base + name)
        if atom.subexpr():
            subscript = None
            if atom.subexpr().expr():
                subscript = convert_expr(atom.subexpr().expr())
            else:
                subscript = convert_atom(atom.subexpr().atom())
            subscriptName = StrPrinter().doprint(subscript)
            s += (('_{' + subscriptName) + '}')
        return sympy.Symbol(s, real=True)
    elif atom.SYMBOL():
        s = atom.SYMBOL().getText().replace('\\$', '').replace('\\%', '')
        if (s == '\\infty'):
            return sympy.oo
        elif (s == '\\pi'):
            return sympy.pi
        elif (s == '\\emptyset'):
            return sympy.S.EmptySet
        else:
            raise Exception('Unrecognized symbol')
    elif atom.NUMBER():
        s = atom.NUMBER().getText().replace(',', '')
        try:
            sr = sympy.Rational(s)
            return sr
        except (TypeError, ValueError):
            return sympy.Number(s)
    elif atom.E_NOTATION():
        s = atom.E_NOTATION().getText().replace(',', '')
        try:
            sr = sympy.Rational(s)
            return sr
        except (TypeError, ValueError):
            return sympy.Number(s)
    elif atom.DIFFERENTIAL():
        var = get_differential_var(atom.DIFFERENTIAL())
        return sympy.Symbol(('d' + var.name), real=True)
    elif atom.mathit():
        text = rule2text(atom.mathit().mathit_text())
        return sympy.Symbol(text, real=True)
    elif atom.VARIABLE():
        text = atom.VARIABLE().getText()
        is_percent = text.endswith('\\%')
        trim_amount = (3 if is_percent else 1)
        name = text[10:]
        name = name[0:(len(name) - trim_amount)]
        symbol_name = name
        if (name in VARIABLE_VALUES):
            if isinstance(VARIABLE_VALUES[name], tuple(sympy.core.all_classes)):
                symbol = VARIABLE_VALUES[name]
            else:
                symbol = parse_expr(str(VARIABLE_VALUES[name]))
        else:
            symbol = sympy.Symbol(symbol_name, real=True)
        if is_percent:
            return sympy.Mul(symbol, sympy.Pow(100, (- 1), evaluate=False), evaluate=False)
        return symbol
    elif atom.PERCENT_NUMBER():
        text = atom.PERCENT_NUMBER().getText().replace('\\%', '').replace(',', '')
        try:
            number = sympy.Rational(text)
        except (TypeError, ValueError):
            number = sympy.Number(text)
        percent = sympy.Rational(number, 100)
        return percent
def convert_atom(atom):
    if atom.LETTER_NO_E():
        subscriptName = 
        s = atom.LETTER_NO_E().getText()
        if (s == 'I'):
            return sympy.I
        if atom.subexpr():
            subscript = None
            if atom.subexpr().expr():
                subscript = convert_expr(atom.subexpr().expr())
            else:
                subscript = convert_atom(atom.subexpr().atom())
            subscriptName = (('_{' + StrPrinter().doprint(subscript)) + '}')
        return sympy.Symbol((atom.LETTER_NO_E().getText() + subscriptName), real=True)
    elif atom.GREEK_LETTER():
        s = atom.GREEK_LETTER().getText()[1:]
        if atom.subexpr():
            subscript = None
            if atom.subexpr().expr():
                subscript = convert_expr(atom.subexpr().expr())
            else:
                subscript = convert_atom(atom.subexpr().atom())
            subscriptName = StrPrinter().doprint(subscript)
            s += (('_{' + subscriptName) + '}')
        return sympy.Symbol(s, real=True)
    elif atom.accent():
        name = atom.accent().start.text[1:]
        if (name in ['bar', 'overline']):
            name = 'bar'
        base = atom.accent().base.getText()
        s = (base + name)
        if atom.subexpr():
            subscript = None
            if atom.subexpr().expr():
                subscript = convert_expr(atom.subexpr().expr())
            else:
                subscript = convert_atom(atom.subexpr().atom())
            subscriptName = StrPrinter().doprint(subscript)
            s += (('_{' + subscriptName) + '}')
        return sympy.Symbol(s, real=True)
    elif atom.SYMBOL():
        s = atom.SYMBOL().getText().replace('\\$', ).replace('\\%', )
        if (s == '\\infty'):
            return sympy.oo
        elif (s == '\\pi'):
            return sympy.pi
        elif (s == '\\emptyset'):
            return sympy.S.EmptySet
        else:
            raise Exception('Unrecognized symbol')
    elif atom.NUMBER():
        s = atom.NUMBER().getText().replace(',', )
        try:
            sr = sympy.Rational(s)
            return sr
        except (TypeError, ValueError):
            return sympy.Number(s)
    elif atom.E_NOTATION():
        s = atom.E_NOTATION().getText().replace(',', )
        try:
            sr = sympy.Rational(s)
            return sr
        except (TypeError, ValueError):
            return sympy.Number(s)
    elif atom.DIFFERENTIAL():
        var = get_differential_var(atom.DIFFERENTIAL())
        return sympy.Symbol(('d' + var.name), real=True)
    elif atom.mathit():
        text = rule2text(atom.mathit().mathit_text())
        return sympy.Symbol(text, real=True)
    elif atom.VARIABLE():
        text = atom.VARIABLE().getText()
        is_percent = text.endswith('\\%')
        trim_amount = (3 if is_percent else 1)
        name = text[10:]
        name = name[0:(len(name) - trim_amount)]
        symbol_name = name
        if (name in VARIABLE_VALUES):
            if isinstance(VARIABLE_VALUES[name], tuple(sympy.core.all_classes)):
                symbol = VARIABLE_VALUES[name]
            else:
                symbol = parse_expr(str(VARIABLE_VALUES[name]))
        else:
            symbol = sympy.Symbol(symbol_name, real=True)
        if is_percent:
            return sympy.Mul(symbol, sympy.Pow(100, (- 1), evaluate=False), evaluate=False)
        return symbol
    elif atom.PERCENT_NUMBER():
        text = atom.PERCENT_NUMBER().getText().replace('\\%', ).replace(',', )
        try:
            number = sympy.Rational(text)
        except (TypeError, ValueError):
            number = sympy.Number(text)
        percent = sympy.Rational(number, 100)
        return percent