private void AddGoalStructArgumentVariables(PrologCodeTerm term)
 {
     if (PrologCodeTerm.IsAtom(term))
     {
         return;
     }
     else if (PrologCodeTerm.IsVariable(term))
     {
         this.Add(((PrologCodeVariable)term).Name, null);
     }
     else if (PrologCodeTerm.IsList(term))
     {
         if (term is PrologCodeNonEmptyList)
         {
             PrologCodeNonEmptyList list = (PrologCodeNonEmptyList)term;
             AddGoalStructArgumentVariables(list.Head);
             if (list.Tail is PrologCodeNonEmptyList)
             {
                 AddGoalStructArgumentVariables(list.Tail);
             }
             else
             {
                 AddGoalStructArgumentVariables(list.Tail);
             }
         }
     }
     else if (PrologCodeTerm.IsStruct(term))
     {
         PrologCodePredicate structure = (PrologCodePredicate)term;
         foreach (PrologCodeTerm argument in structure.Arguments)
         {
             AddGoalStructArgumentVariables(argument);
         }
     }
 }
 private void AddGoalVariables(PrologCodeTerm term)
 {
     // no variables to add: predicate/0
     if (PrologCodeTerm.IsAtom(term) || PrologCodeTerm.IsAtomicPredicate(term))
     {
         return;
     }
     // goal is a variable X
     else if (PrologCodeTerm.IsVariable(term))
     {
         _currentArgumentIndex = 0;
         this.Add(((PrologCodeVariable)term).Name, null);
         return;
     }
     // goal is a list, [Term|Term]
     else if (PrologCodeTerm.IsList(term))
     {
         _currentArgumentIndex = 0;
         if (term is PrologCodeNonEmptyList)
         {
             PrologCodeNonEmptyList list = (PrologCodeNonEmptyList)term;
             AddGoalArgumentVariables(list.Head);
             _currentArgumentIndex = 1;
             if (list.Tail != null)
             {
                 if (list.Tail is PrologCodeNonEmptyList)
                 {
                     AddGoalArgumentVariables(list.Tail);
                 }
                 else
                 {
                     AddGoalArgumentVariables(list.Tail);
                 }
             }
         }
     }
     // Goal is a predicate, term(term,...)
     else if (PrologCodeTerm.IsStruct(term))
     {
         _currentArgumentIndex = 0;
         PrologCodePredicate goal = (PrologCodePredicate)term;
         foreach (PrologCodeTerm argument in goal.Arguments)
         {
             AddGoalArgumentVariables(argument);
             _currentArgumentIndex++;
         }
     }
 }