MCSN-project2014 / APproject

Project for the MCSN Advanced Programming Module A.Y. 2014/2015
http://mcsn-project2014.github.io/APproject/
MIT License
4 stars 0 forks source link

Function Declaration and Function Call (AST) #27

Closed lucarin91 closed 9 years ago

lucarin91 commented 9 years ago

I see that in the FsCodeGenerator(@teto1992 , @dido18) there is same mistake about the function call and the function declaration. Here I explain how have to be represented in the AST structure:

Obj fun = new Obj(){name="provaFun"};
Node funDec = new Node(Labels.FunDec, fun); //give to he node the Obj of function
funDec.addChildren(new Node(Labels.Block)); //the first children have to be the block of the function
funDec.addChildren(new Term(new Obj(){name="a"})); //the other children are the formal parameter

Instead the function call node have to be:

Node funCall = new Node(Labels.FunCall, fun);//give to the node the Obj of the function
funCall.addChildren(new Term(7));//all the children are the actual parameter of the function call
dido18 commented 9 years ago

I have re-write the translateFunCall()

The translateFunDecl() we have another syntax: the first child is the block, the second child is the return type (if there) the others children are the paramters. the function in funw@p : fun add ( int x, int y ) int {.<block>.} became in f#: `let add x y : int =

` ``` c# Obj fun = new Obj(){name="add"}; Node funDec = new Node(Labels.FunDecl, fun); //give to he node the Obj of function funDec.addChildren(new Node(Labels.Block)); //the first children have to be the block of the function funDec.addChildren(new Term(new Obj() { name = "int"})); // the return type of the function funDec.addChildren(new Term(new Obj(){name="x"})); //the other children are the formal parameter funDec.addChildren(new Term(new Obj(){name="y"})); //the other children are the formal parameter ``` ``` ```