Q:

TeX capacity exceeded - Babel package

Please consider this document:
\documentclass{report}
\usepackage[portuguese]{babel}
\DeclareTextAccent{\'}{EU1}{"00B4}
\begin{document}
\chapter{Introduction}
\end{document}

If I try to compile it using XeLaTeX, then I get this error message:
! TeX capacity exceeded, sorry [input stack size=5000].
\'->\EU1-cmd \'
               \EU1\' 
l.5 \chapter{Introduction}

If you really absolutely need more capacity,
you can ask a wizard to enlarge me.

This occurs only if I use the Babel package with the portuguese option. I tried with other languages and all goes well.
What can I do to avoid this error?

A:

The error shows with Portuguese and not English or French because LaTeX wants to typeset the localized version of “chapter” and “Capítulo” in Portuguese happens to contain \'i, which doesn't happen for other languages.
You get exactly the same with
\documentclass{report}
\usepackage[<language>]{babel}
\DeclareTextAccent{\'}{EU1}{"00B4}
\begin{document}
\'a
\end{document}

(any language option).
What happens is that EU1 is not a known encoding with the most recent versions of LaTeX, when using babel (also with fontspec): the default encoding is TU.
Your \DeclareTextAccent defines \' to expand to
\EU1-cmd \'\EU1\'

but \EU1-cmd is just \relax (because the encoding is not known) and this makes TeX spin its wheels trying to expand again \':
\'->\EU1-cmd \'
               \EU1\' 
\'->\EU1-cmd \'
               \EU1\' 

Solution:
\documentclass{report}
\usepackage[portuguese]{babel}
\DeclareTextAccent{\'}{\encodingdefault}{"00B4}
\begin{document}
\chapter{Introduction}
\end{document}

