diff options
Diffstat (limited to 'src/Scilab2C/ASTGenerator')
-rw-r--r-- | src/Scilab2C/ASTGenerator/%program_p.sci | 153 | ||||
-rw-r--r-- | src/Scilab2C/ASTGenerator/DescriptionOfmacr2tree.txt | 82 | ||||
-rw-r--r-- | src/Scilab2C/ASTGenerator/GenerateASTfoo.sci | 6 | ||||
-rw-r--r-- | src/Scilab2C/ASTGenerator/foo.sci | 8 | ||||
-rw-r--r-- | src/Scilab2C/ASTGenerator/foo1.sci | 8 |
5 files changed, 257 insertions, 0 deletions
diff --git a/src/Scilab2C/ASTGenerator/%program_p.sci b/src/Scilab2C/ASTGenerator/%program_p.sci new file mode 100644 index 00000000..93e43a7a --- /dev/null +++ b/src/Scilab2C/ASTGenerator/%program_p.sci @@ -0,0 +1,153 @@ +function %program_p(p)
+ //overloading function for "program" type tlist display
+ mprintf("%s\n",string(p))
+endfunction
+
+function txt=%program_string(p)
+//overloading function for "program" type tlist string function
+//main (root) node of the Abstract Formal Tree
+//fields:
+// name : string (the function name)
+// outputs : list of "variable" type tlist (the output arg names)
+// inputs : list of "variable" type tlist (the intput arg names)
+// statements: list of "equal" type tlist and list('EOL') (the
+// instructions list)
+// nblines : number (the number of lines in the scilab function)
+ txt=['Program'
+ 'Name : '+p.name
+ 'Outputs: '+strcat(objectlist2string(p.outputs),' ')
+ 'Inputs : '+strcat(objectlist2string(p.inputs),' ')
+ 'Statements '
+ ' '+objectlist2string(p.statements)
+ 'EndProgram'
+ ]
+endfunction
+
+
+function txt=%equal_string(e)
+//overloading function for "equal" type tlist string function
+//this is a node of the AST
+
+//fields:
+// expression: "expression" type tlist (the right hand side)
+// lhs : list of "variable" type tlist and "operation" type tlist // (the assignment)
+// endsymbol : string (the orginal end-of-instruction symbol (, ; <CR>))
+ txt=['Equal'
+ ' Expression: '
+ ' '+string(e.expression)
+ ' Lhs : '
+ ' '+objectlist2string(e.lhs)
+ 'EndEqual'
+ ]
+endfunction
+
+
+function txt=%for_string(F)
+//overloading function for "for" type tlist string function
+//this is a node of the AST
+//fields:
+// expression : "expression" type tlist (the loop expression)
+// statements : list of "equal" type tlist and list('EOL') (the
+// for instructions list)
+ txt=['For'
+ ' Expression:'
+ ' '+string(F.expression)
+ ' Statements:'
+ ' '+objectlist2string(F.statements)
+ 'EndFor']
+endfunction
+
+function txt=%ifthenel_string(I)
+//overloading function for "ifthenel" type tlist string function
+//this is a node of the AST
+//fields:
+// expression : "expression" type tlist (the if expression)
+// then : list of "equal" type tlist and list('EOL') (the
+// then instructions list)
+// elseifs : a list of tlists
+// else : list of "equal" type tlist and list('EOL') (the
+// else instructions list)
+ txt=['If '
+ ' Expression:'
+ ' '+string(I.expression)
+ ' If Statements'
+ ' '+objectlist2string(I.then)]
+ for e=I.elseifs
+ txt=[txt;
+ " Else If Expression'
+ ' '+string(e.expression)
+ ' Else If Statements'
+ ' '+objectlist2string(e.then)]
+ end
+ txt=[txt;
+ " Else Statements'
+ ' '+objectlist2string(I.else)
+ 'EndIf']
+endfunction
+
+function txt=%operatio_string(O)
+//overloading function for "operation" type tlist string function
+//this is a node of the AST
+//fields:
+// operands: a list
+// operator: a string
+ txt=['Operation'
+ ' Operands:'
+ ' '+objectlist2string(O.operands)
+ ' Operator: '+O.operator
+ 'EndOperation'
+ ]
+endfunction
+
+function txt=%funcall_string(F)
+//overloading function for "funcall" type tlist string function
+//this is a node of the AST
+//fields:
+// rhs : a list
+// name : string, the name of the function
+// lhsnb: number, the number of function lhs
+
+txt=['Funcall : '+F.name
+ ' #lhs : '+string(F.lhsnb)
+ ' Rhs : '
+ ' '+objectlist2string(F.rhs)
+ 'EndFuncall'
+ ]
+endfunction
+
+function txt=%variable_string(v)
+//overloading function for "variable" type tlist string function
+//fields: name
+//this is a leaf of the AST
+ txt=v.name
+endfunction
+
+function txt=%cste_string(c)
+//overloading function for "cste" type tlist string function
+//this is a leaf of the AST
+//fields:
+// value : a number or a string
+ txt=string(c.value)
+endfunction
+
+function txt=%comment_string(e)
+//overloading function for "comment" type tlist string function
+//fields:
+// text: a string
+//this is a leaf of the AST
+ txt=['Comment : '+e.text]
+endfunction
+
+function txt=objectlist2string(L)
+//auxiliary function for conversion of a list of objects
+//into a string vector
+ txt=[];
+ for o=L,
+ if type(o)==15 then //EOL case
+ txt=[txt;'<'+o(1)+'>'],
+ else
+ txt=[txt; string(o)],
+ end
+ end
+ if txt==[] then txt='<empty>',end
+endfunction
diff --git a/src/Scilab2C/ASTGenerator/DescriptionOfmacr2tree.txt b/src/Scilab2C/ASTGenerator/DescriptionOfmacr2tree.txt new file mode 100644 index 00000000..21ec28d7 --- /dev/null +++ b/src/Scilab2C/ASTGenerator/DescriptionOfmacr2tree.txt @@ -0,0 +1,82 @@ +Description from Serge Steer
+Date:
+Fri, 28 Jul 2006 12:14:14 +0200
+To:
+raffaele.nutricato@tiscali.it
+CC:
+Fabio.Bovenga@ba.infn.it, Claude.Gomez@Inria.fr, Didier.Halgand@Inria.fr, Serge.Steer@Inria.fr
+
+>> Let me to ask you one more question: I read in the Scilab2C.doc
+>> document that among the tasks related to the Scilab team/ INRIA
+>> there is the "*_FORTRAN to C code translation"_* task. Is it
+>> possible to have more details about this activity?
+
+
+I am not able to answer this question, please ask it to Claude Gomez
+who wrote this document.
+
+
+
+>> Could you please send us a preliminary version of the output that
+>> will be generated by the Scilab2tree tool starting from the
+>> testscilab.sci code?
+
+
+
+If you have Scilab-4.0 installed you can play with it. The
+preliminary version of Scilab2tree is named macr2tree.
+
+here is very simple example of use
+
+-->function y=foo(x)
+--> y=x+1
+-->endfunction
+
+-->t=macr2tree(foo)
+
+It returns the full abstract syntax tree coded by a hierarchical
+structure of tlists and lists Scilab objects. To get a more readable
+display and also to illustrate how Scilab can deal with such a
+structure, I give you below a file of scilab functions for display
+overloading. If this file is loaded into Scilab
+
+--> exec %program_p.sci;
+
+The display of the t structure above become
+
+-->t
+ t =
+
+Program
+Name : foo
+Outputs: y
+Inputs : x
+Statements
+ <EOL>
+ Equal
+ Expression:
+ Operation
+ Operands:
+ x
+ 1
+ Operator: +
+ EndOperation
+ Lhs :
+ y
+ EndEqual
+ <EOL>
+ Funcall : return
+ #lhs : 0
+ Rhs :
+ <empty>
+ EndFuncall
+ <EOL>
+EndProgram
+
+
+These functions work with your testscilab function too (but select
+case constructs are not yet handled). Just try it and look at the
+comment for the structure explanation
+
+Serge Steer
+Scilab Team
diff --git a/src/Scilab2C/ASTGenerator/GenerateASTfoo.sci b/src/Scilab2C/ASTGenerator/GenerateASTfoo.sci new file mode 100644 index 00000000..70001632 --- /dev/null +++ b/src/Scilab2C/ASTGenerator/GenerateASTfoo.sci @@ -0,0 +1,6 @@ +// Generate the Abstract Syntactic Tree for the foo Scilab function
+
+getf("foo.sci");
+exec %program_p.sci;
+t=macr2tree(foo);
+t
diff --git a/src/Scilab2C/ASTGenerator/foo.sci b/src/Scilab2C/ASTGenerator/foo.sci new file mode 100644 index 00000000..1aad4c34 --- /dev/null +++ b/src/Scilab2C/ASTGenerator/foo.sci @@ -0,0 +1,8 @@ +// example to show how the AST is generated.
+// In the Scilab workspace type the following commands:
+//
+function y=foo(x)
+
+y = sin(cos(x));
+y = sin(convol(x,y));
+endfunction
diff --git a/src/Scilab2C/ASTGenerator/foo1.sci b/src/Scilab2C/ASTGenerator/foo1.sci new file mode 100644 index 00000000..a988bfd8 --- /dev/null +++ b/src/Scilab2C/ASTGenerator/foo1.sci @@ -0,0 +1,8 @@ +// example to show how the AST is generated.
+// In the Scilab workspace type the following commands:
+//
+function y=foo(x)
+
+y=x+1;
+
+endfunction
|