from lark import Lark

# Note como o Lark precisa decidir entre '+' (SOMA) e '++' (INCREMENTO)
# Isso exige que o autômato "olhe para frente"
gramatica_automato = """
    start: (INCREMENTO | SOMA | NUMERO)+

    INCREMENTO: "++"
    SOMA: "+"
    NUMERO: /[0-9]+/

    %import common.WS
    %ignore WS
"""

parser = Lark(gramatica_automato, parser='lalr') 
# O parâmetro parser='lalr' gera um autômato de estados eficiente

texto = "10 + ++ "
print(f"Analisando: {texto}")
for token in parser.lex(texto):
    print(f"Token: {token.type:12} | Valor: {token.value}")