before I start explaining, let me state this is not a "please-do-my-homework" question. I'll post my code and assumptions or guessings, but I'm asking for your assistance as I wasn't able to solve this, and found this matter not only intriguing, but also a good opportunity to learn very useful skills.
This exercise is part of a homework task at my University, and deadline is already over. Why am I asking for help then? Well, the teachers will only provide the results score, but not the actual explanation on how to solve the exercise (it's the University policy) until the next period, the next year. I can't wait so long, I'm very intrigued on how to solve this.
This is a summary of the exercise speech: "there's certain isolated island in which they have their own language, but most people make syntax mistakes, so their governor decides to ask a developer to issue some piece of software which, observing their language rules, corrects the syntax".
And these are the rules:

1. The only characters in that language are the characters from 'g' to 'p' plus 'A', 'F', 'D', 'Q', 'X'.
2. Each character from 'g' to 'p' is a valid sentence.
3. If 's' is a valid sentence, then 'As' is valid too.
4. If 's' and 't' are valid sentences, then 'Fst', 'Dst', 'Qst' and 'Xst' are valid sentences as well.
5. Rules from 1 to 4 are the only valid rules to determine the correct syntax.

And this was not clear enough for many of us, so we asked the teacher about points 3 and 4, and he explained -as 's' is not actually a valid sentence, that was just an example- they wanted to mean that 'A' can be followed only by 1 lower case character, and F, D, Q and X can be followed only by 2 valid lower case caracters.

Alright, that may not sound so much complicated to a lot of you who know about regular expressions. Actually we weren't taught regular expressions, only JUnit -nothing to do with it? well, the thing is this exercise is actually part of a JUnit workshop, and yes, I'm as surprised as you-. Then, why am I bringing up the regular expresions subject? Well, the teacher commented that some student suggested him this exercise could be easily solved using regular expressions.

I'm developing in Java using NetBeans, and I will post the most important part of the code I have so far:

```
Pattern patronUno = Pattern.compile("[ghijklmnop]");
Pattern patronDos = Pattern.compile("A*[ghijklmnop]|A*");
Pattern patronTres = Pattern.compile("([FDQX]+([ghijklmnop]{2,2}))");
Pattern patronCuatro = Pattern.compile("[A][FDQX]");

public String validar(String sentencia){        
    Matcher coincidenciaUno = patronUno.matcher(sentencia);
    Matcher coincidenciaDos = patronDos.matcher(sentencia);
    Matcher coincidenciaTres = patronTres.matcher(sentencia);
    Matcher coincidenciaCuatro = patronCuatro.matcher(sentencia);

    if(coincidenciaUno.matches() || coincidenciaDos.matches() || 
                coincidenciaTres.matches() || coincidenciaCuatro.matches())
        return "YES";
    else
        return "NO";
}

```

And my first testing cases I have, pre-approved by the teachers, are:

Example IN Example OUT

* Fg NO
* Xij YES
* AXij YES
* Dklm NO

Now, AXij is valid, because A is valid per sè, and Xij is also valid, so adding Xij to A is like adding a single one character valid sentence to it.
And that my friends, is the part of the exercise I haven't been able to deal with; as I couldn't learn -if there is a way to- how to join two valid sentences.
Could you help me on that part of the requirement?

With that code I posted, I'm getting these results:

Example IN Example OUT

* Fg NO
* Xij YES
* AXij NO
* Dklm NO
* AAg YES
* AA YES
* Am YES
* Amp NO
* Amng NO

I can't get AXij to be considered as a valid sentence, for example. However I could successfully validate Fx as invalid, Xij as valid, Dklm as invalid, etc.

Thanks in advance for your help. I'm posting this, as I've been searching through this website on examples that could explain this, but any of them was clear enough to me.