Addictional Optional Argument Recognition [message #1748558] |
Thu, 24 November 2016 11:48 |
Enrico Benini 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 #1748782 is a reply to message #1748779] |
Mon, 28 November 2016 15:21 |
Enrico Benini 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 #1748864 is a reply to message #1748862] |
Tue, 29 November 2016 13:20 |
Enrico Benini 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
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05471 seconds