Maned

Postfix basics

Generated by tools/gen_example_pages.py from mnd_scripts/examples/example_rpn_postfix.mnd — the output below is a real run, not a transcription. Regenerating the page reruns it.

the core evaluation model — Reverse Polish (postfix) notation with NO operator precedence and NO parentheses.

The program#

# ============================================================================
# example_rpn_postfix.mnd
# ----------------------------------------------------------------------------
# FUNCTIONALITY: the core evaluation model -- Reverse Polish (postfix) notation
# with NO operator precedence and NO parentheses.
#
# Every Maned expression is read strictly left to right against an operand
# stack. Operands push; an operator pops its arity and pushes one result; the
# trailing name(s) plus `=` bind whatever is on top.
#
#     a b add result =
#     ^ ^  ^   ^      ^
#     | |  |   |      +-- bind
#     | |  |   +--------- target name
#     | |  +------------- pop 2, push 1
#     | +---------------- push b
#     +------------------ push a
#
# WHY IT MATTERS: precedence is the main source of "I read the formula wrong"
# bugs, and the main obstacle to laying a program out as a hardware dataflow
# graph. Postfix has neither. The token order IS the dependency order, which is
# exactly what the SSA dataflow builder and the FPGA back end need.
#
# RUN: ../maned-run examples/example_rpn_postfix.mnd
# ============================================================================
mnd::quantmax=1000;
mnd::quantmin=-1000;
mnd::quantres=0;

in::a = 2;
in::b = 3;
in::c = 4;

calc::lambda_flow arithmetic(a, b, c) {
    # (a + b) * c  =  (2 + 3) * 4  =  20
    #
    #   token | stack after it
    #   ------+------------------
    #   a     | 2
    #   b     | 2, 3
    #   add   | 5
    #   c     | 5, 4
    #   mul   | 20
    a b add c mul sum_then_scale =

    # a + (b * c)  =  2 + (3 * 4)  =  14
    # Same three values, same three operators -- ONLY the token order differs.
    # In an infix language this distinction needs parentheses; here it is just
    # where you put `mul`.
    b c mul a add scale_then_sum =

    # Deeper nesting stays flat. This is ((a+b) * (b+c)) - a  =  (5 * 7) - 2.
    a b add b c add mul a sub nested =

    # Multiple operators of different arity mix freely: `relu` pops 1.
    a b sub negative_then_clamped_input =
    negative_then_clamped_input relu clamped =
} return sum_then_scale, scale_then_sum, nested, clamped;

The run#

$ maned-run mnd_scripts/examples/example_rpn_postfix.mnd
flow 'arithmetic' outputs:
sum_then_scale : scalar = 20
scale_then_sum : scalar = 14
nested : scalar = 33
clamped : scalar = 0

Next#

© 2026 Fabiano Dicheti · Found a problem on this page? Open an issue