  The Kleene theorem establishes a fundamental link between automata and
expressions over the free monoid. Numerous generalisations of this result exist
in the literature. Lifting this result to a weighted setting has been widely
studied. Moreover, different monoids can be considered: for instance, two-way
automata, and even tree-walking automata, can be described by expressions using
the free inverse monoid. In the present work, we aim at combining both research
directions and consider weighted extensions of automata and expressions over a
class of monoids that we call pre-rational, generalising both the free inverse
monoid and graded monoids. The presence of idempotent elements in these
pre-rational monoids leads in the weighted setting to consider infinite sums.
To handle such sums, we will have to restrict ourselves to rationally additive
semirings. Our main result is thus a generalisation of the Kleene theorem for
pre-rational monoids and rationally additive semirings. As a corollary, we
obtain a class of expressions equivalent to weighted two-way automata, as well
as one for tree-walking automata.
