Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Addictional Optional Argument Recognition
Addictional Optional Argument Recognition [message #1748558] Thu, 24 November 2016 11:48 Go to next message
Enrico Benini is currently offline Enrico BeniniFriend
Messages: 9
Registered: November 2016
Junior Member
Hi guys, I have a problem:

This is my grammar
grammar it.unibo.FPML with org.eclipse.xtext.common.Terminals

generate fPML "..."

import "http://www.eclipse.org/emf/2002/Ecore" as ecore

///////////////////////////////////////////////////////////////
// Entry element
//////////////////////////////////////////////////////////////
Model:
	elements+=PureBlock
	elements+=EffectFullBlock;

//////////////////////////////////////////////////////////////
// Outer Blocks
//////////////////////////////////////////////////////////////

PureBlock:
	'Pure' '{'
		elements+=DataBlock
		elements+=PureFunctionBlock
	'}';

PureFunctionBlock:
	'Functions' '{'
		(features+=PureFunctionDefinition)*
	'}';

DataBlock:
	'Data' '{'
		(elements+=Data)*
		value=ValueBlock
	'}';

ValueBlock:
	'Value' '{' 
		(elements+=Value)*
	'}'
;

EffectFullBlock:
    'Effects' '{'
    	(features+=EffectFullFunctionDefinition)*
		main=MainFunc
    '}';

/////////////////////////////////////////////////////////////////
// Outer Block Elements
/////////////////////////////////////////////////////////////////

Data:
    name=ID ':' content=AdtType;

Value returns PureFunctionDefinition: {Value} name=ID ':' value=Expression;

AdtType:
      ValueType
    | '[' adtElement1=AdtType adtElement2=(SumType | ProdType) ']';

SumType:
    '+' adtElement=AdtType;
ProdType:
    '*' adtElement=AdtType;
    
PureFunctionDefinition:
	'def' returnType=ValueType name=ID '(' args+=Argument ( ',' args+=Argument)? ')' ':' '{' functionBody=FunctionBodyPure '}';

EffectFullFunctionDefinition:
	'def' returnType=IOType name=ID '(' args+=EffectFullArgument (',' args+=EffectFullArgument)? ')' ':' '{'  functionBody=FunctionBodyEffectFull '}';

MainFunc:
	'IO' returnType=UnitType 'main' ':' '{' functionBody=FunctionBodyEffectFull '}';

Function: EffectFullFunction | PureFunction;

PureFunction: PureFunctionDefinition | PrimitivePureFunction;

EffectFullFunction: EffectFullFunctionDefinition | PrimitiveEffectFullFunction;

///////////////////////////////////////////////////////////////////
// Function Body Elements
///////////////////////////////////////////////////////////////////

EffectFullReference: Function | EffectFullArgument;

PureReference: PureFunctionDefinition | Argument;

EffectFullArgument:
	type=Type name=ID;

Argument: type=ValueType name=ID;

FunctionBodyPure:
		 EmptyFunctionBody | CompositionFunctionBodyPure;

FunctionBodyEffectFull:
  	     EmptyFunctionBody | CompositionFunctionBodyEffect;

EmptyFunctionBody:
    {EmptyFunctionBody} 'Undefined';

CompositionFunctionBodyPure:
      referenceElement=[PureFunctionDefinition] (functionChain+=CompositionFunctionBodyPureFactor)+ 
    | primitiveElement=PrimitivePureFunction (functionChain+=CompositionFunctionBodyPureFactor)+;
    
CompositionFunctionBodyPureFactor:
	  ( '|>' (referenceElement=[PureFunctionDefinition]))
	| ( '|>' (PrimitiveElement=PrimitivePureFunction));

CompositionFunctionBodyEffect:
      referenceElement=[EffectFullReference] (functionChain+=CompositionFunctionBodyEffectFullFactor)+
    | primitiveElement=(PrimitiveEffectFullFunction | PrimitivePureFunction) (functionChain+=CompositionFunctionBodyEffectFullFactor)+;
    
CompositionFunctionBodyEffectFullFactor:
	  ( '>>=' (referenceElement=[EffectFullReference]))
	| ( '>>=' (PrimitiveElement=(PrimitiveEffectFullFunction | PrimitivePureFunction)));

//////////////////////////////////////////////////////////////////////
// Types
//////////////////////////////////////////////////////////////////////

IOType:
	'IO' type=Type ;

ValueType:
	IntegerType | StringType | DataType | PureFunctionType;

Type:
	ValueType | UnitType | EffectFullFunctionType;

IntegerType:
	{IntegerType} type="int";

StringType:
	{StringType} type="String";

UnitType:
	{UnitType} type="Unit";

DataType:
    {DataType} 'ref' type=[Data];
    
PureFunctionType:
	{PureFunctionType} 'F' '<' argType=ValueType ',' returnType=ValueType '>';

EffectFullFunctionType:
	{EffectFullFunctionType} 'FIO' '<' argType=IOType ',' returnType=IOType '>';

////////////////////////////////////////////////////////////////////
// Values
////////////////////////////////////////////////////////////////////

Expression:
    IntValue | StringValue | DataValue | FunctionValue;

IntValue returns IntegerType: {IntegerType} value=INT;

StringValue returns StringType: {StringType} value=STRING;

FunctionValue returns PureFunctionType: value=PureLambda;

DataValue returns DataType: {DataValue} type=[Data]'(' value=AdtValue ')';

ValueRef: {ValueRef} value=[Value];

PureLambda returns PureFunctionDefinition: 
	{PureLambda} '(' arg=Argument ')' ':' functionBody=FunctionBodyPure
;

AdtValue:
	  IntValue
	| StringValue
	| ValueRef
	| DataValue
	| SumValue
	| FunctionValue
	| ProdValue;

ProdValue: 
	'(' prodAdtElement1=AdtValue ',' prodAdtElement2=AdtValue ')';

SumValue:
	'Left' '(' sumAdtElement1=AdtValue ')'
	| 'Right' '(' sumAdtElement2=AdtValue ')';
    
/////////////////////////////////////////////////////////////////////
// Primitives
/////////////////////////////////////////////////////////////////////

PrimitivePureFunction: 
	IntToString | IntPow | Plus | Minus | Times | Mod | ApplyF;

IntToString: {IntToString} 'IntToString';
IntPow:	{IntPow} 'IntPow';
Plus: {Plus} '+';
Minus: {Minus} '-';
Times: {Times} '*';
Mod: {Mod} 'mod';
ApplyF:{ApplyF} 'applyF' functionType=PureFunctionType value=[PureReference];

PrimitiveEffectFullFunction:
	PrimitivePrint | PrimitiveRandom | ApplyFIO;

PrimitivePrint:
    {PrimitivePrint} "print";

PrimitiveRandom:
	{PrimitiveRandom} "randomInt";

ApplyFIO: {ApplyFIO} 'applyFIO' functionType=EffectFullFunctionType value=[EffectFullReference];
    


All works fine, but this strange behaviour showed in the attach image.
As you can see, it seems that the second arguments aren't recognized by xtext and so I've problems in typechecking them and using them.
Sometimes when I run the eclipse runtime only the second argument ID is recognized, but the type still not be seen.
I simply can't figure out the cause of this behaviour.
Any suggestions??

Thanks in advance
Re: Addictional Optional Argument Recognition [message #1748693 is a reply to message #1748558] Sun, 27 November 2016 08:29 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14738
Registered: July 2009
Senior Member
can you please post the test model as well? or a unit test showing the problem

and how does your scope provider impl look like


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com

[Updated on: Sun, 27 November 2016 08:44]

Report message to a moderator

Re: Addictional Optional Argument Recognition [message #1748762 is a reply to message #1748693] Mon, 28 November 2016 13:14 Go to previous messageGo to next message
Enrico Benini is currently offline Enrico BeniniFriend
Messages: 9
Registered: November 2016
Junior Member
Hi,
Thanks for the reply.
My scope provider is empty and unfortunately I don't have a test for the model.
Anyway you can clone the repo at this link:

https://github.com/benkio/FPML

Thanks again
Re: Addictional Optional Argument Recognition [message #1748770 is a reply to message #1748762] Mon, 28 November 2016 14:11 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14738
Registered: July 2009
Senior Member
without a test model i cannot help you.
yoiur editor shows you have a test model


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Addictional Optional Argument Recognition [message #1748778 is a reply to message #1748770] Mon, 28 November 2016 15:01 Go to previous messageGo to next message
Enrico Benini is currently offline Enrico BeniniFriend
Messages: 9
Registered: November 2016
Junior Member
you mean the validator?
Because I have done only the validator and the generator xtend classes
Re: Addictional Optional Argument Recognition [message #1748779 is a reply to message #1748778] Mon, 28 November 2016 15:03 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14738
Registered: July 2009
Senior Member
no i mean the model file you use to reproduce the error
you grammar is to complex to stick a test model together i a few seconds


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Addictional Optional Argument Recognition [message #1748782 is a reply to message #1748779] Mon, 28 November 2016 15:21 Go to previous messageGo to next message
Enrico Benini is currently offline Enrico BeniniFriend
Messages: 9
Registered: November 2016
Junior Member
AAA ok right...

here's my last example, a little bit complex but i will attach also an image that show where there're the missing parameters.
Where I use a single parameter all works fine.

Pure {
	Data {
		MyData: int
		MyDataString: String
		MyDataRef: ref MyData
		MyDataProd: [int * int]
		MyDataFunc: F<int, F<int,int> >
		Value {
			num2: 3
			num: 2
			randomMessage1: "This is the random generated: "
			randomMessage2: "Result of the computation: "
			DataProdValue: MyDataProd((2, 6))
		}
	}
	Functions{
		def F<int, int> a(int b, int c): { + |> applyF F<int, int> num |> * |> applyF F<int, int> c }
		def ref MyData a1(F<int, int> b1): { Undefined }
		def String a2(int b2): { IntPow |> IntToString}
		def F<int,int> a3(int b3, int b4): { a |> applyF F<int,int> num2 |> IntPow |> - |> applyF F<int,int> b4 }
	}
}
Effects {
	Data {
		MyDataIO: IO int
		MyDataIOString: IO String
		MyDataIOProd: [IO int + IO int]
		MyDataIORef: IO refIO MyDataIO
		MyDataIOFunc: IO FIO<int, IO String>
		Value {
			MyDataIOValue: MyDataIO(IO (4)) 
			MyDataValue: randomInt >>= return int
			MyDataFuncValue: MyDataIOFunc([int a] : a2 >>= return String)
		}
	}
	Functions {
		def IO FIO <String,IO int> printValueAndMassageAndPassValue(int g, String m): { IntToString >>= print >>= m >>= print >>= g } 
		def IO int d2(int e2): { e2 >>= + >>= applyF F<int,int> num  } 
		def IO FIO<String, IO String> d(String e, String c): { print >>= c }
		def IO String d1(String e1): { Undefined }
		IO Unit main: { Undefined }
	}
}


Anyway, for the updated grammar see here:

https://github.com/benkio/FPML/blob/master/fpml/src/it/unibo/FPML.xtext

Because the one of the starting message can be outdated.

Thanks again
Re: Addictional Optional Argument Recognition [message #1748786 is a reply to message #1748782] Mon, 28 November 2016 15:29 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14738
Registered: July 2009
Senior Member
i dont get any errors. are you sure your antlr generation is not running into any timeouts (e.g. slow machine)?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Addictional Optional Argument Recognition [message #1748787 is a reply to message #1748786] Mon, 28 November 2016 15:35 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14738
Registered: July 2009
Senior Member
p.s.: and your screenshot looks fine? or what is wrong with it?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Addictional Optional Argument Recognition [message #1748806 is a reply to message #1748787] Mon, 28 November 2016 21:13 Go to previous messageGo to next message
Enrico Benini is currently offline Enrico BeniniFriend
Messages: 9
Registered: November 2016
Junior Member
As you can see in the screenshot, sometimes in the outline, the arguments have the type (int, String) and sometimes not. (for example the 'e' has the String type, but the 'c' not)
I cannot see errors, and in the grammar the EffectFullArgument has the "type"...but during the validation sometimes it has null value.
What i can't understand is why the type isn't initialized in the right way in some cases. This behavior blows up my type checking during the validation, when i try to match the types of arguments and return types of functions, so i get errors when are none.
Re: Addictional Optional Argument Recognition [message #1748815 is a reply to message #1748806] Tue, 29 November 2016 04:04 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14738
Registered: July 2009
Senior Member
In the sometimes between edits or after regeneration of grammar and restart

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Addictional Optional Argument Recognition [message #1748819 is a reply to message #1748815] Tue, 29 November 2016 04:55 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14738
Registered: July 2009
Senior Member
HI

i had a look at your type checker and this guy is the bad guy.
you do things like

functionType.argType = argument2.arg2.type

if you have a look at how EMF containment references work you will notice that this will move
the argument2.arg2.type from the arg2 object to the functionType object

(you may have other places like that)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Addictional Optional Argument Recognition [message #1748862 is a reply to message #1748819] Tue, 29 November 2016 12:59 Go to previous messageGo to next message
Enrico Benini is currently offline Enrico BeniniFriend
Messages: 9
Registered: November 2016
Junior Member
Yep, I know it's a complicated type checker
But when I do this assignment I create the functionType element from scratch, I don't change an existing element, I use it for higher order functions.
Anyway I don't think this is a problem related to the type checker, because from the outline it seems that the grammar can't figure out the argument type, and going at debug I found that actually the second argument has the type field to null.

I will check in the codebase the point where I create new objects in search of bugs or strange things.
Thank you
Re: Addictional Optional Argument Recognition [message #1748863 is a reply to message #1748862] Tue, 29 November 2016 13:19 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14738
Registered: July 2009
Senior Member
yes but you steal the type of an existing element and give to another one this is how emf works with containment reference.
a element can have only one container and if you set it as a child of a second one it gets removed from the first one


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Addictional Optional Argument Recognition [message #1748864 is a reply to message #1748862] Tue, 29 November 2016 13:20 Go to previous messageGo to next message
Enrico Benini is currently offline Enrico BeniniFriend
Messages: 9
Registered: November 2016
Junior Member
Here the proof of what I'm saying.
I placed a breakpoint in the first line of my validator and wait for the 'd' function showed in the previous attach image (the blue one).
Then I open the prospective and find the arg2 field.
As you can see the type field is NULL way before any action from the validator itself.

What I suppose here is that there's something strange in the grammar

[Updated on: Tue, 29 November 2016 13:24]

Report message to a moderator

Re: Addictional Optional Argument Recognition [message #1748869 is a reply to message #1748863] Tue, 29 November 2016 13:57 Go to previous messageGo to next message
Enrico Benini is currently offline Enrico BeniniFriend
Messages: 9
Registered: November 2016
Junior Member
Thanks for the suggestion,
I will try to create a copy of the type instead of directly set the new objects with the existing type, avoiding stealing.

I will update you if this change something, I hope. Smile
Re: Addictional Optional Argument Recognition [message #1748870 is a reply to message #1748869] Tue, 29 November 2016 14:12 Go to previous message
Enrico Benini is currently offline Enrico BeniniFriend
Messages: 9
Registered: November 2016
Junior Member
I changed the assingment with EcoreUtil.copy(EObject) method as suggested here:

https://www.eclipse.org/forums/index.php/t/126974/

and TYPES REAPPERED!!!!

http://clipsforclass.com/wp-content/uploads/2016/09/THB.png

Cool
Previous Topic:XText Formatter: organize elements
Next Topic:method generateFile undefined for the type MyDslGenerator
Goto Forum:
  


Current Time: Fri Dec 27 00:11:51 GMT 2024

Powered by FUDForum. Page generated in 0.05471 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top