Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » No error reported, but semantic model incomplete
No error reported, but semantic model incomplete [message #777405] Tue, 10 January 2012 07:38 Go to next message
Thomas Williams is currently offline Thomas Williams
Messages: 15
Registered: January 2012
Junior Member
Hello Xtexters,

I'm having some problems with my grammar where it seems to parse correctly but creates an incomplete semantic model.

The grammar - yes the DECLARE construct is a little odd and not how I would do it from scratch, but this is for a pre-existing language:

GeneralProcessModellingSystem:
	{GeneralProcessModellingSystem}
    (
    	"DECLARE"
    	      (	"TYPE" ( variableTypes += VariableTypeEntity )* )    	        
    	    | ( "STREAM" ( streamTypes += StreamTypeEntity )* )
    	"END"
    )*
;

VariableTypeEntity:
    name = ID
    '=' default=RealNumber
    ':' lowerBound=RealNumber 
    ':' upperBound=RealNumber 
    ("UNIT" '=' unit=STRING)? ;

StreamTypeEntity:
    name = ID
    "IS"
    elements += [VariableTypeEntity] ( ',' elements += [VariableTypeEntity] )
;

RealNumber returns ecore::EDoubleObject:
	('-')? INT ( '.' INT )?
;


The input:

String text = 
    "DECLARE TYPE\n" +
    "    GasConcentration = 1.0 : -0.0 : 10.0 UNIT = \"mol/m3\"\n" +
    "END\n" +		
    "DECLARE TYPE\n" +
    "    Length = 0.0 : 0.0 : 100.0 UNIT = \"m\"\n" +
    "END";	


The output from EmfFormatter#objToStr() on the domain model:

GeneralProcessModellingSystem {
    cref VariableTypeEntity variableTypes [
        0: VariableTypeEntity {
            attr EString name 'GasConcentration'
            attr EDoubleObject default '1.0'
            attr EDoubleObject lowerBound '-0.0'
            attr EDoubleObject upperBound '10.0'
            attr EString unit 'mol/m3'
        }
    ]
}


The "Length" TYPE is missing.

If I delete the line:
| ( "STREAM" ( streamTypes += StreamTypeEntity )* )

from the grammar then I get the correct result ...

Regards,

Tom
Re: No error reported, but semantic model incomplete [message #777424 is a reply to message #777405] Tue, 10 January 2012 08:34 Go to previous message
Thomas Williams is currently offline Thomas Williams
Messages: 15
Registered: January 2012
Junior Member
Ignore me, there was a mistake in the grammar, should have been:
GeneralProcessModellingSystem:
	{GeneralProcessModellingSystem}
    (
    	"DECLARE"
    	(
    	      (	"TYPE" ( variableTypes += VariableTypeEntity )* )    	        
    	    | ( "STREAM" ( streamTypes += StreamTypeEntity )* )
    	)
    	"END"
    )*
;
Previous Topic:Associating Xtext editors to file names, instead of file extensions
Next Topic:[xtend] Import values
Goto Forum:
  


Current Time: Wed Aug 27 17:15:45 EDT 2014

Powered by FUDForum. Page generated in 0.02967 seconds