-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.html
117 lines (102 loc) · 3.9 KB
/
example.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="lib/lex.js"></script>
<script src="lib/ir.nodes.js"></script>
<script src="lib/ir.other.js"></script>
<script src="lib/ir.gen.js"></script>
<script src="lib/graphml.gen.js"></script>
<script src="graphml2svg/js/xslt.js"></script>
<script src="graphml2svg/js/layoutengine.js"></script>
<script src="graphml2svg/js/layout.js"></script>
<title>Parser</title>
</head>
<body>
<div class="container" id="page">
<h2>
Sisal translator check
</h2>
<script type="text/javascript">
function trn() {
var ast = lex.parse(document.getElementById('source').value);
console.log(ast);
var ir = new node.sisalir(ast);
console.log(ir);
console.log(ir.toGraphML());
}
function exc() {
var ast = lex.parse(document.getElementById('source').value);
var ir = new node.sisalir(ast);
ir.execute()
console.log(ir);
console.log(ir.toText());
}
function vis() {
var ast = lex.parse(document.getElementById('source').value);
console.log(ast);
var ir = new node.sisalir(ast);
var xsl = XsltTransform.getXMLFromUrl('graphml2svg/graphml2svg.xsl');
Layout.prepareGraphML(ir.toGraphML(), ir, function (xml) {
var canvSize = Layout.getSizeOf(xml.getElementById('ir1'));
svgimg = XsltTransform.transformXslt(xml, xsl, {
canvasWidth: ((canvSize.width | 0) + 50) + '',
canvasHeight: ((canvSize.height | 0) + 50) + '',
collapsedNodeWidth: '42',
collapsedNodeHeight: '42'
});
var node = Layout.getVisNode();
node.innerHTML = svgimg;
console.log(svgimg);
unescapePropertyOfNodes(document.getElementsByTagName('text'),'innerHTML');
});
}
function unescapePropertyOfNodes(nodes, propertyName) {
for(var i=0, length=nodes.length; i<length; i++) {
var node = nodes[i];
if(node[propertyName] !== undefined) {
node[propertyName] = unescape(node[propertyName]);
}
}
}
</script>
<textarea id="source" rows="12" cols="80">
function Main( M : integer returns array[real] )
for i in 1, M
returns array of
1
end for
end function
</textarea>
<!--
function Main2( M,N : integer returns integer )
M+N
end function
function Main( M : integer returns array[real] )
for i in 1, M
returns array of
1
end for
end function
function Main2( M,N : integer returns integer )
M+N*M
end function
-->
<p><button onclick='trn();'>translate (result in console log)</button></p>
<p><button onclick='exc();'>translate & execute (result in console log)</button></p>
<p><button onclick='vis();'>show IR1 (result in console log)</button></p>
Another example:
<pre>
function Main( A,B: array[array[real]]; M,N,L : integer returns array[array[real]] )
for i in 1, M cross j in 1, L
returns array of
for k in 1, N repeat
R := A[i,k] * B[k,j]
returns sum of R
end for
end for
end function
</pre>
</div><!-- page -->
</body>
</html>