diff --git a/src/compiler/tmlCPparser/CPparser.jjt b/src/compiler/tmlCPparser/CPparser.jjt
index e966b4199ca4656cec6cec2ef4cf75ea7f55fa6a..82ddfb1771b06eb6efcd1098b298e89c60f208a0 100644
--- a/src/compiler/tmlCPparser/CPparser.jjt
+++ b/src/compiler/tmlCPparser/CPparser.jjt
@@ -750,17 +750,7 @@ void SequenceDiagram():
 	<SEQUENCE_DIAGRAM> name = ID()
 	{
 		TMLCPSequenceDiagram currentSD = new TMLCPSequenceDiagram( name, new Object() );
-		//try	{
-			topCP.addCPSequenceDiagram( currentSD );
-		//}
-		/*catch( UndeclaredDiagramException e )	{
-			System.out.println( e.getMessage() );
-			System.exit(0);
-		}
-		catch( MultipleDiagDeclarationsException	e )	{
-			System.out.println( e.getMessage() );
-			System.exit(0);
-		}*/
+		topCP.addCPSequenceDiagram( currentSD );
 	}
 	ArchitectureNodes( currentSD )
 	( IntegerDeclaration( currentSD ) | BooleanDeclaration( currentSD ) )*
diff --git a/src/compiler/tmlCPparser/CPparserDEF.jjt b/src/compiler/tmlCPparser/CPparserDEF.jjt
new file mode 100644
index 0000000000000000000000000000000000000000..b5821c5dfd67582cbde3cb97548f43bdc3e14744
--- /dev/null
+++ b/src/compiler/tmlCPparser/CPparserDEF.jjt
@@ -0,0 +1,269 @@
+/**********************************************************************************************************************
+Author: 			Andrea ENRICI
+Description: 	Parser for the communication Patterns
+***********************************************************************************************************************/
+
+options {
+	/* These are all the options offered by Javacc set with their default values */
+//  LOOKAHEAD = 2;
+//  CHOICE_AMBIGUITY_CHECK = 2;
+//  OTHER_AMBIGUITY_CHECK = 1;
+//  STATIC = true;
+//  DEBUG_PARSER = false;
+//  DEBUG_LOOKAHEAD = true;
+//  DEBUG_TOKEN_MANAGER = true;
+//  ERROR_REPORTING = true;
+//  JAVA_UNICODE_ESCAPE = false;
+//  UNICODE_INPUT = false;
+//  IGNORE_CASE = false;
+//  USER_TOKEN_MANAGER = false;
+//  USER_CHAR_STREAM = false;
+//  BUILD_PARSER = true;
+//  BUILD_TOKEN_MANAGER = true;
+//  SANITY_CHECK = true;
+	/*When LOOKAHEAD is more than 1, lookahead adequacy checking is not performed. Option FORCE_LA_CHECK must be set to true to
+	 * force checking */
+//  FORCE_LA_CHECK = true;
+//	TRACK_TOKENS = true;
+//	TOKEN_EXTENDS ="BaseToken";
+	MULTI=true;	/* Generate a multimode parse tree */
+	KEEP_LINE_COLUMN = false; 
+//	NODE_PREFIX="AST";
+}
+
+PARSER_BEGIN(CPparserDEF) /* The parser class */
+
+//package compiler.tmlCPparserDEF;
+import tmltranslator.*;
+import tmltranslator.tmlcp.*;
+import java.util.*;
+import myutil.*;
+import java.util.ArrayList;
+
+public class CPparserDEF {
+
+	public static TMLCP topCP = new TMLCP( "noName", new Object() );
+
+  /* Main entry point. */
+  public static void main(String args[]) throws ParseException	{
+    CPparserDEF parser = new CPparserDEF(System.in);
+		try	{
+    	ASTStartSymbol n = parser.StartSymbol();
+			//print AST
+			//n.dump("");
+			//System.out.println("Thank you.");
+			topCP.printDataStructure();
+		}
+		catch ( Exception e )	{
+//			System.out.println("Ooops");
+			System.out.println(e.getMessage());
+//			e.printStackTrace();
+		}
+  }
+}
+
+PARSER_END(CPparserDEF)
+
+SKIP:
+{
+	" "
+| "\t"
+| "\n"
+| "\r"
+| < "#" (~["\n","\r"])* ("\n" | "\r" | "\r\n") >	/* One-line comment */
+| < "//" (~["\n","\r"])* ("\n" | "\r" | "\r\n") >	/* One-line comment */
+}
+
+/* The order in which TOKENs are declared matters! Moving the token declaration for the reserved keywords after the one for the
+ * identifiers makes parsing to go bananas as any reserved keyword is instead matched as an identifier! */
+/* Reserved keywords */
+TOKEN:
+{
+	< BOOLTYPE: "BOOL" >
+|	< INTTYPE: "INT" >
+| < START_KW: "START" >
+|	< ENDBLOCK: "END" >
+|	< MAINBLOCK: "MAIN" >
+|	< CP: "COMMUNICATION_PATTERN" >
+| < ACTIVITY_DIAGRAM: "ACTIVITY" >
+| < SEQUENCE_DIAGRAM: "SEQUENCE" >
+| < INCLUDE: "INCLUDE" >
+| < TRUECONST: "TRUE" >
+| < FALSECONST: "FALSE" >
+| < STORAGE_KW: "STORAGE" >
+| < CONTROLLER_KW: "CONTROLLER" >
+| < TRANSFER_KW: "TRANSFER" >
+| < ACTION_KW: "ACT:" >
+| < RCV_MSG_KW: "RCV:" >
+| < SND_MSG_KW: "SND:" >
+| < #TRANSFER_ACT: "Transfer" >
+| < #TRANSFER_REQ: "TransferRequest" >
+| < #TRANSFER_DONE: "TransferDone" >
+| < #READ_ACT: "Read" >
+| < #WRITE_ACT: "Write" >
+| < EXTENSION: <CP_LIB> >
+| < #CP_LIB: ".cplib" >
+}
+
+/* Operators */
+TOKEN:
+{
+	< BLOCKSTART: "{" >
+|	< BLOCKEND: "}" >
+|	< JOINSTART: "<" >
+|	< JOINEND: ">" >
+|	< SEQUENCING_OP: ";" >
+|	< PARALLELISM_OP: "*" >
+|	< MATH_PLUS: "+" >
+|	< MATH_MINUS: "-" >
+|	< DOT: "." >
+|	< GUARDSTART: "[" >
+|	< GUARDEND: "]" >
+|	< ITERATIONSTART: "(" >
+|	< ITERATIONEND: ")" >
+|	< SEPARATOR: "," >
+| < ASSIGNMENT: "=" >
+| < EQUALITY: "==" >
+| < BITWISEOR: "|" >
+| < LOGICALOR: "||" >
+| < BITWISEAND: "&" >
+| < LOGICALAND: "&&" >
+| < BITWISEEXOR: "^" >
+| < INCREMENT: "++" >
+| < DECREMENT: "--" >
+| < START_AD: "<>;" >
+| < END_AD: "><" >
+| < ORDEROPERATOR: <SEQUENCING_OP> | <PARALLELISM_OP> >
+| < EOL: ("\n" | "\r" | "\r\n") >
+| < PATH_SEPARATOR: "/" >
+| < QUOTATION_MARK: "\"" >
+}
+
+/* Identifiers */
+TOKEN:
+{
+	< IDENTIFIER: <LETTER> (<UNDERSCORE> | <LETTER> | <DIGIT>)* (<LETTER> | <DIGIT>) >
+| < #LETTER: ["a"-"z","A"-"Z"] >
+|	< #DIGIT: ["0"-"9"] >
+|	< UNDERSCORE: "_" >
+//| < INCLUDE_SYMBOL: "$" >
+}
+
+/* Literals */
+TOKEN:
+{
+	< INTEGER_LITERAL: <DECIMAL_LITERAL> (["l","L"])? >
+| < #DECIMAL_LITERAL: ["0"-"9"] (["0"-"9"])* >
+}
+
+
+/* List of productions defining the non-terminals. They are implemented as methods of the above parser class*/
+/* Root production. */
+ASTStartSymbol StartSymbol():	/* The left hand side of this production is called Input and must be followed by colon */
+{
+	int i;
+	String space = " ";
+	String undefinedDiagStringList = "";
+	ArrayList<String> undefinedADList;
+	ArrayList<String> undefinedSDList;
+}
+{
+	/*( IncludeFiles() )*
+	( MappingList() )*
+	CommunicationPattern()
+	( ActivityDiagram() ( ActivityDiagram() )* ( SequenceDiagram() )+ | ( SequenceDiagram() )+ )*/
+
+	// One or more attribute declaration followed by the declaration of the body of the Sequence Diagrams
+	( SequenceDiagramAttributeDeclaration() )+	
+	( SequenceDiagram() )+ | ( SequenceDiagram() )+
+	<EOF>		/* Force the parser to reach EOF */
+	{
+		//Must fill the Elements of each TMLCPActivityDiagram with the correct references to CPs and SDs that could not be done before
+		//encapsulate everything in one method as I do not know the type of the diagrams whose references where missing
+		topCP.correctReferences();
+		return jjtThis;
+	}
+}
+
+/********************************************************************************************************************************
+Include Files Section: the grammar for parsing the inclusion of library files
+********************************************************************************************************************************/
+/*void IncludeFiles():
+{}
+{
+	<INCLUDE> <QUOTATION_MARK> (<DOT>)? (<PATH_SEPARATOR>)? ID() (<PATH_SEPARATOR> ID() )* <EXTENSION> <QUOTATION_MARK>
+}
+
+void MappingList():
+{}
+{
+	ID() <ITERATIONSTART> ID() ( <SEPARATOR> ID() )+ <ITERATIONEND>
+}*/
+
+/********************************************************************************************************************************
+Sequence Diagram Section
+********************************************************************************************************************************/
+
+void SequenceDiagramAttributeDeclaration():
+{
+	String name;
+}
+{
+	name = ID()
+}
+
+// A SD is a list of instances. Each Instance is composed of messages or actions.
+void SequenceDiagram():
+{
+	String name;
+	ArrayList<TMLSDInstance> instancesList = new ArrayList<TMLSDInstance>();
+}
+{
+	<SEQUENCE_DIAGRAM> name = ID()
+	{
+		TMLCPSequenceDiagram currentSD = new TMLCPSequenceDiagram( name, new Object() );
+	}
+	( SequenceDiagramInstance() )+
+	<ENDBLOCK>
+}
+
+void SequenceDiagramInstance():
+{
+	String instanceName, type;
+	TMLSDAction action;
+}
+{
+	type = ID() instanceName = ID()
+	( Message() | action = Action( instanceName ) )+
+	// addActionFromParser(), addMessageFromParser()
+
+}
+
+void Message():
+{
+	String name;
+}
+{
+	( <RCV_MSG_KW> | <SND_MSG_KW> ) name = ID() "(" ( ID() )* ")"
+}
+
+TMLSDAction Action( String instanceName ):
+{
+	String actionName;
+}
+{
+	<ACTION_KW> actionName = ID() ID() <ASSIGNMENT> ( <INTEGER_LITERAL> | <FALSECONST> | <TRUECONST> )
+	{
+		TMLSDAction action = new TMLSDAction( actionName, instanceName );
+		return action;
+	}
+}
+
+String ID():
+{
+	Token t;
+}
+{
+	t = <IDENTIFIER>
+	{ jjtThis.setName(t.image); return t.image; }
+}
diff --git a/src/tmltranslator/tmlcp/TMLSDAction.java b/src/tmltranslator/tmlcp/TMLSDAction.java
index d1d8b3d2eec34dd550977585e920426fe6349829..9a1e840875f6814618df796f997b0bd745c76ada 100755
--- a/src/tmltranslator/tmlcp/TMLSDAction.java
+++ b/src/tmltranslator/tmlcp/TMLSDAction.java
@@ -63,6 +63,14 @@ public class TMLSDAction extends TMLSDElement  {
 		instanceName = _instanceName;
 		this.yCoord = _yCoord;
   }
+
+	// Constructor used for the TMLCPparser where in the TMLCP code there is no notion of yCoord and no notion of referenceObject
+   public TMLSDAction( String _action, String _instanceName ) {
+		super( "action", null );
+    action = _action;
+		instanceName = _instanceName;
+		this.yCoord = -1;
+  }
     
   public int getYCoord() {
   	return this.yCoord;
diff --git a/src/tmltranslator/tmlcp/TMLSDEvent.java b/src/tmltranslator/tmlcp/TMLSDEvent.java
index 840c8e55abcdaedfb8bb0e08787acc1ebcec6385..a5120aedbd6321266575123d39a3e685c6e2dfd9 100755
--- a/src/tmltranslator/tmlcp/TMLSDEvent.java
+++ b/src/tmltranslator/tmlcp/TMLSDEvent.java
@@ -72,6 +72,12 @@ public class TMLSDEvent implements Comparable<TMLSDEvent>  {
         this.type = _type;
     }
 
+    public TMLSDEvent( Object _referenceObject, int _type ) {
+        this.referenceObject = _referenceObject;
+        this.yCoord = -1;
+        this.type = _type;
+    }
+
     public int getYCoord()      {
         return yCoord;
     }
diff --git a/src/tmltranslator/tmlcp/TMLSDInstance.java b/src/tmltranslator/tmlcp/TMLSDInstance.java
index a96c41de319716c6ea7f75829aa799d8f0104a51..2981c69a3ab60e71eed95fd1e7000b871b478222 100755
--- a/src/tmltranslator/tmlcp/TMLSDInstance.java
+++ b/src/tmltranslator/tmlcp/TMLSDInstance.java
@@ -122,6 +122,12 @@ public class TMLSDInstance extends TMLElement  {
         Collections.sort( events );
     }
 
+		//Add an action from the parser where there is no notion of yCoord. Events are already ordered.
+    public void addActionFromParser( TMLSDAction _action ) {
+        actions.add( _action );
+        events.add( new TMLSDEvent( _action, TMLSDEvent.ACTION_EVENT ) );
+    }
+
     public void addMappedUnit( TMLArchiNode _mappedUnit ) {
         mappedUnit = _mappedUnit;
     }
@@ -145,6 +151,18 @@ public class TMLSDInstance extends TMLElement  {
 			Collections.sort( events );
     }
 
+		//Add a message from the parser where there is no notion of yCoord. Events are already ordered.
+    public void addMessageFromParser( TMLSDMessage _msg, int _type ) {
+
+			messages.add( _msg );
+			if( _type == TMLSDEvent.SEND_MESSAGE_EVENT )	{
+  	    events.add( new TMLSDEvent( _msg, TMLSDEvent.SEND_MESSAGE_EVENT ) );
+			}
+			if( _type == TMLSDEvent.RECEIVE_MESSAGE_EVENT )	{
+  	    events.add( new TMLSDEvent( _msg, TMLSDEvent.RECEIVE_MESSAGE_EVENT ) );
+			}
+    }
+
     public void insertInitialValue( String _name, String value ) {
 
         int i = 0;
diff --git a/src/tmltranslator/tmlcp/TMLSDMessage.java b/src/tmltranslator/tmlcp/TMLSDMessage.java
index dc27c633cfaaf15160fa819019cf62fe86ea111c..ad276342a763837ae73ef65dbfbe69926cc84e0f 100755
--- a/src/tmltranslator/tmlcp/TMLSDMessage.java
+++ b/src/tmltranslator/tmlcp/TMLSDMessage.java
@@ -86,6 +86,18 @@ public class TMLSDMessage extends TMLElement  {
 			attributeList.add( new TMLAttribute(p) );
 		}
 	}
+	
+	// Constructor used for the TMLCPparser where in the TMLCP code there is no notion of yCoord and of referenceObject
+	public TMLSDMessage( String _name, String _senderName, String _receiverName, Object _referenceObject, ArrayList<String> _params )	{
+		super( _name, null );
+		this.yCoord = -1;
+		this.senderName = _senderName;
+		this.receiverName = _receiverName;
+		attributeList = new ArrayList<TMLAttribute>();
+		for( String p: _params )	{
+			attributeList.add( new TMLAttribute(p) );
+		}
+	}
 
 	public String getSenderName()	{
 		return senderName;
diff --git a/src/ui/GTMLModeling.java b/src/ui/GTMLModeling.java
index f02b4ab809955a7f7ad018fffd97f9aa85bcb553..870a27f457e2c24c4449d06d629d1fdf5c00c4ae 100755
--- a/src/ui/GTMLModeling.java
+++ b/src/ui/GTMLModeling.java
@@ -643,7 +643,7 @@ public class GTMLModeling  {
                         TraceManager.addDev("port=" + ((TMLCPrimitivePort)(ite.next())).getPortName());
                     }
 
-                    if (portstome.size() != 1) {
+                    if ( (portstome.size() < 1) || (portstome.size() > 3) ) {
                         String msg = "port " + port1.getPortName() + " is not correctly connected";
                         CheckingError ce = new CheckingError(CheckingError.STRUCTURE_ERROR, msg);
                         ce.setTDiagramPanel(tmlcdp.tmlctdp);
@@ -763,7 +763,7 @@ public class GTMLModeling  {
                         TraceManager.addDev("port=" + ((TMLCPrimitivePort)(ite.next())).getPortName());
                     }
 
-                    if (portstome.size() != 1) {
+                    if ( (portstome.size() < 1) || (portstome.size() > 3) ) {
                         String msg = "port " + port1.getPortName() + " is not correctly connected";
                         CheckingError ce = new CheckingError(CheckingError.STRUCTURE_ERROR, msg);
                         ce.setTDiagramPanel(tmlcdp.tmlctdp);