\documentclass{article}
\def\beginfoo{\bgroup}
\def\endfoo{\egroup}
\begin{document}
\section{Testing Over}
\[ a b c \over d e f \]

\[ a {b c \over d e} f \]

\[ a {b c \over d e\egroup f \]

\[ a \bgroup b c \over d e\egroup f \]

\[ a \beginfoo b c \over d e\endfoo f \]

% This one is ambiguous!
% \[ a { b c \over d \over e} f \]
\end{document}
