FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Update the notebook to use LFortran kernel · gaecom/lpython@f9b38dc · GitHub

/ lpython Public
forked from lcompilers/lpython

Commit f9b38dc

Browse files
committed
Update the notebook to use LFortran kernel
1 parent 7666332 commit f9b38dc

1 file changed

Lines changed: 32 additions & 75 deletions

File tree

‎doc/nb/developer_tutorial.ipynb‎

Lines changed: 32 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
"are encouraged to use them independently for other applications and build tools\n",
1717
"on top:\n",
1818
"\n",
19-
"* Abstract Syntax Tree (AST), module `lfortran.ast`: Represents any Fortran\n",
19+
"* Abstract Syntax Tree (AST): Represents any Fortran\n",
2020
" source code, strictly based on syntax, no semantic is included. The AST\n",
2121
" module can convert itself to Fortran source code.\n",
2222
"\n",
23-
"* Abstract Semantic Representation (ASR), module `lfortran.asr`: Represents a\n",
23+
"* Abstract Semantic Representation (ASR): Represents a\n",
2424
" valid Fortran source code, all semantic is included. Invalid Fortran code is\n",
2525
" not allowed (an error will be given). The ASR module can convert itself to an\n",
2626
" AST.\n",
@@ -37,38 +37,39 @@
3737
"metadata": {},
3838
"outputs": [],
3939
"source": [
40-
"from lfortran.ast import src_to_ast, print_tree\n",
41-
"from lfortran.ast.ast_to_src import ast_to_src\n",
42-
"src = \"\"\"\\\n",
4340
"integer function f(a, b) result(r)\n",
4441
"integer, intent(in) :: a, b\n",
4542
"r = a + b\n",
46-
"end function\n",
47-
"\"\"\"\n",
48-
"ast = src_to_ast(src, translation_unit=False)"
43+
"end function"
4944
]
5045
},
5146
{
5247
"cell_type": "markdown",
5348
"metadata": {},
5449
"source": [
55-
"We can pretty print it using `print_tree()` ([#59](https://gitlab.com/lfortran/lfortran/issues/59)):"
50+
"We can pretty print it using the `%%showast` magic:"
5651
]
5752
},
5853
{
5954
"cell_type": "code",
6055
"execution_count": null,
61-
"metadata": {},
56+
"metadata": {
57+
"scrolled": true
58+
},
6259
"outputs": [],
6360
"source": [
64-
"print_tree(ast)"
61+
"%%showast\n",
62+
"integer function f(a, b) result(r)\n",
63+
"integer, intent(in) :: a, b\n",
64+
"r = a + b\n",
65+
"end function"
6566
]
6667
},
6768
{
6869
"cell_type": "markdown",
6970
"metadata": {},
7071
"source": [
71-
"We can convert AST to Fortran source code using `ast_to_src()`:"
72+
"We can convert AST to Fortran source code using `%%showfmt`:"
7273
]
7374
},
7475
{
@@ -77,7 +78,11 @@
7778
"metadata": {},
7879
"outputs": [],
7980
"source": [
80-
"print(ast_to_src(ast))"
81+
"%%showfmt\n",
82+
"integer function f(a, b) result(r)\n",
83+
"integer, intent(in) :: a, b\n",
84+
"r = a + b\n",
85+
"end function"
8186
]
8287
},
8388
{
@@ -87,27 +92,14 @@
8792
"All AST nodes and their arguments are described in\n",
8893
"[AST.asdl](https://gitlab.com/lfortran/lfortran/blob/master/grammar/AST.asdl).\n",
8994
"\n",
90-
"## Abstract Semantic Representation (ASR)\n",
91-
"\n",
92-
"We can convert AST to ASR using the `ast_to_asr()` function:"
93-
]
94-
},
95-
{
96-
"cell_type": "code",
97-
"execution_count": null,
98-
"metadata": {},
99-
"outputs": [],
100-
"source": [
101-
"from lfortran.semantic.ast_to_asr import ast_to_asr\n",
102-
"from lfortran.asr.pprint import pprint_asr\n",
103-
"asr = ast_to_asr(ast)"
95+
"## Abstract Semantic Representation (ASR)"
10496
]
10597
},
10698
{
10799
"cell_type": "markdown",
108100
"metadata": {},
109101
"source": [
110-
"We can pretty print using the `pprint_asr()` function:"
102+
"We can pretty print using the `%%showasr` magic:"
111103
]
112104
},
113105
{
@@ -116,40 +108,11 @@
116108
"metadata": {},
117109
"outputs": [],
118110
"source": [
119-
"pprint_asr(asr)"
120-
]
121-
},
122-
{
123-
"cell_type": "markdown",
124-
"metadata": {},
125-
"source": [
126-
"For example to get the variables defined in the function scope:"
127-
]
128-
},
129-
{
130-
"cell_type": "code",
131-
"execution_count": null,
132-
"metadata": {},
133-
"outputs": [],
134-
"source": [
135-
"asr.global_scope.symbols[\"f\"].symtab.symbols.keys()"
136-
]
137-
},
138-
{
139-
"cell_type": "markdown",
140-
"metadata": {},
141-
"source": [
142-
"We can convert ASR to AST and to source code:"
143-
]
144-
},
145-
{
146-
"cell_type": "code",
147-
"execution_count": null,
148-
"metadata": {},
149-
"outputs": [],
150-
"source": [
151-
"from lfortran.asr.asr_to_ast import asr_to_ast\n",
152-
"print(ast_to_src(asr_to_ast(asr)))"
111+
"%%showasr\n",
112+
"integer function f(a, b) result(r)\n",
113+
"integer, intent(in) :: a, b\n",
114+
"r = a + b\n",
115+
"end function"
153116
]
154117
},
155118
{
@@ -163,21 +126,15 @@
163126
],
164127
"metadata": {
165128
"kernelspec": {
166-
"display_name": "Python 3",
167-
"language": "python",
168-
"name": "python3"
129+
"display_name": "Fortran",
130+
"language": "fortran",
131+
"name": "fortran"
169132
},
170133
"language_info": {
171-
"codemirror_mode": {
172-
"name": "ipython",
173-
"version": 3
174-
},
175-
"file_extension": ".py",
176-
"mimetype": "text/x-python",
177-
"name": "python",
178-
"nbconvert_exporter": "python",
179-
"pygments_lexer": "ipython3",
180-
"version": "3.7.3"
134+
"file_extension": ".f90",
135+
"mimetype": "text/x-fortran",
136+
"name": "fortran",
137+
"version": "2018"
181138
}
182139
},
183140
"nbformat": 4,

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL