Skip to content
Railroad / syntax diagram templates

Railroad — Arithmetic Expressions

Classic expr / term / factor precedence-climbing grammar for calculators and compilers.

Template previewRailroad / syntax diagram
expr ::=term+-termterm ::=factor*/factorfactor ::=numberidentifier(expr)-factor

Make it your own.

# Operator precedence via layered rules
expr   ::= term { ( "+" | "-" ) term }
term   ::= factor { ( "*" | "/" ) factor }
factor ::= number | identifier | "(" expr ")" | "-" factor