Addictional Optional Argument Recognition [message #1748558] |
Thu, 24 November 2016 11:48  |
Eclipse User |
|
|
|
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 #1748782 is a reply to message #1748779] |
Mon, 28 November 2016 15:21   |
Eclipse User |
|
|
|
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 #1748806 is a reply to message #1748787] |
Mon, 28 November 2016 21:13   |
Eclipse User |
|
|
|
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 #1748819 is a reply to message #1748815] |
Tue, 29 November 2016 04:55   |
Eclipse User |
|
|
|
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)
|
|
|
Re: Addictional Optional Argument Recognition [message #1748862 is a reply to message #1748819] |
Tue, 29 November 2016 12:59   |
Eclipse User |
|
|
|
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 #1748864 is a reply to message #1748862] |
Tue, 29 November 2016 13:20   |
Eclipse User |
|
|
|
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] by Moderator Report message to a moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.06176 seconds