# - - - T x n y . _ _ b i n d E q u i v a l e n t A l t
def __bindEquivalentAlt ( self, scan, code, otherCode, eng ):
'''Try to add a binding for code |-> otherCode.
[ (scan is a Scan instance) and
(code and otherCode are bird codes) and
(eng is an English name) ->
if an equivalence binding for (code) to (otherCode)
is valid ->
self.abTab +:= that new binding using English
name (eng)
else ->
Log() +:= error message(s)
raise SyntaxError ]
'''
The first order of business is to make sure there is
a symbol table entry for otherCode,
because the EqBind constructor wants
to bind to that symbol table entry.
#-- 1 --
# [ if self.abTab has an entry for (otherCode) ->
# otherSym := that entry
# else ->
# self.abTab +:= a new symbol table entry for (otherCode)
# otherSym := that entry ]
otherSym = self.abTab.addAbbr ( otherCode )
#-- 2 --
# [ eqBind := a new EqBind instance equating (code)
# to (otherCode) ]
eqBind = EqBind ( code, otherSym, eng )
#-- 3 --
# [ if self.abTab has an entry for (code) ->
# sym := that entry
# else ->
# self.abTab +:= a new entry for (code)
# sym := that new entry ]
sym = self.abTab.addAbbr ( code )
#-- 4 --
# [ if sym can have eqBind added ->
# sym := sym bound to eqBind
# else ->
# Log() +:= error message(s)
# raise SyntaxError ]
try:
sym.bind ( eqBind )
except ValueError:
scan.error ( "Code '%s' already defined as %s." %
(code, sym.binding) )