Набросал вариант с использованием PLY.
Правда, упрощенный, экспоненциальное представление не обрабатывает. Но с секциями :).
# -*- coding: utf-8
from ply import lex
from ply import yacc
raw = '#sec x =-12.57 y=2203 z=337.304 #sec abc=232'
tokens = ('SEC', 'VAR', 'DIG', 'EQ', 'SIG', 'DOT')
t_VAR = r'[a-z_]+'
t_EQ = r'='
t_DIG = r'[0-9]+'
t_SEC = r'\#sec'
t_SIG = r'[+-]'
t_DOT = '.'
t_ignore = ' \t'
def t_error(t):
print "Parse error at '%s'" % t.value
def p_product(p):
"""
prod : prod sec
prod : sec
"""
if len(p) == 2: p[0] = [p[1]]
if len(p) == 3: p[0] = p[1] + [p[2]]
def p_sec(p):
"""
sec : SEC
| sec expr
"""
if len(p) == 2: p[0] = []
if len(p) == 3: p[0] = p[1] + [p[2]]
def p_expr(p):
"""
expr : VAR EQ num
"""
p[0] = (p[1], p[3])
def p_num(p):
"""
num : DIG
| SIG num
| DIG DOT DIG
"""
if len(p) == 2: p[0] = p[1]
if len(p) == 3: p[0] = p[1] + p[2]
if len(p) == 4: p[0] = p[1] + p[2] + p[3]
def p_error(p):
print "Syntax error at '%s'" % p.value
lexer = lex.lex()
parser = yacc.yacc()
print parser.parse(raw)