Skip to content

Commit 5c5d8f4

Browse files
committed
Add python and wolfram support. Qiskit bug solved.
1 parent 8d28fad commit 5c5d8f4

21 files changed

+614
-25
lines changed

ex_python.pfcf

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
~Python code~
2+
<python>
3+
print("hello world")
4+
</python>,

ex_python.txt

Whitespace-only changes.

ex_qiskit.pfcf

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
~Qiskit code~
2+
<qiskit>
3+
q0 q1
4+
X
5+
H
6+
.---X
7+
c1
8+
$host qasm_simulator
9+
$hist true
10+
$draw true
11+
</qiskit>,

ex_qiskit.txt

Whitespace-only changes.

ex_wolfram.pfcf

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
~Wolfram code~
2+
<wolfram>
3+
Range[5]
4+
</wolfram>,

ex_wolfram.txt

Whitespace-only changes.

example.pfcf renamed to examples/example.pfcf

+10-13
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Welcome to the future,:),|
1919
May 10 2021\, 13:45,
2020
by Eanorambuena,|
2121

22-
Add qiskit code like this:,|
22+
Add code like this:,|
2323
\<qiskit\>,
2424
q0 q1,
2525
X,
@@ -29,15 +29,12 @@ c1,
2929
$host qasm_simulator,
3030
$hist true,
3131
$draw true,
32-
\</qiskit\>,
33-
34-
<qiskit>
35-
q0 q1
36-
X
37-
H
38-
.---X
39-
c1
40-
$host qasm_simulator
41-
$hist true
42-
$draw true
43-
</qiskit>,
32+
\</qiskit\>\,,
33+
|
34+
\<python\>,
35+
print(\"hello world\"),
36+
\</python\>\,,
37+
|
38+
\<wolfram\>,
39+
Range[5],
40+
\</wolfram\>\,,

example.txt renamed to examples/example.txt

+10-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Welcome to the future
1515
May 10 2021, 13:45
1616
by Eanorambuena
1717

18-
Add qiskit code like this:
18+
Add code like this:
1919

2020
<qiskit>
2121
q0 q1
@@ -26,4 +26,12 @@ c1
2626
$host qasm_simulator
2727
$hist true
2828
$draw true
29-
</qiskit>
29+
</qiskit>,
30+
31+
<python>
32+
print("hello world")
33+
</python>,
34+
35+
<wolfram>
36+
Range[5]
37+
</wolfram>,

main.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
from pfcf.read import read,executepfcf
22
from pfcf.utils import execute
3-
name="example"
4-
#execute("qiskit_compile")
5-
executepfcf(name)
3+
f1="example"
4+
f2="ex_qiskit"
5+
f3="ex_python"
6+
f4="ex_wolfram"
7+
#executepfcf(f4)
8+
execute("python_compile")

pfcf/__pycache__/code.cpython-38.pyc

756 Bytes
Binary file not shown.

pfcf/__pycache__/read.cpython-38.pyc

-29 Bytes
Binary file not shown.

pfcf/__pycache__/utils.cpython-38.pyc

0 Bytes
Binary file not shown.

pfcf/code.py

+38
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
from pfcf.utils import *
22
import pfcf.codel.qiskit as q
3+
import pfcf.codel.wolfram as w
34

45
def codef(codel: str,text: str): #code function
56
form="_compile.py"
67
f=open(codel+form,"w")
78
t=""
89
if codel=="qiskit":
910
t=qiskit(text)
11+
elif codel=="wolfram":
12+
t=wolfram(text)
13+
elif codel=="python":
14+
t=text
1015
f.write(t)
1116
f.close()
1217

@@ -61,3 +66,36 @@ def qiskit(text: str):
6166
Q+=1
6267
return T
6368

69+
def wolfram(text: str):
70+
T=""
71+
T+="from wolframclient.evaluation import WolframLanguageSession\n"
72+
T+="from wolframclient.language import wl, wlexpr\n"
73+
T+="session = WolframLanguageSession()\n"
74+
s=0
75+
command=""
76+
param=""
77+
t=""
78+
for i in text:
79+
if i==",":
80+
pass
81+
elif s==1: #settings mode on
82+
if i!=" ":
83+
command+=i
84+
else:
85+
s=2
86+
elif s==2:
87+
if i!=" " and i!="\n":
88+
param+=i
89+
else:
90+
T+=w.settings(command,param)
91+
command=""
92+
param=""
93+
s=0
94+
elif i=="$":
95+
s=1
96+
elif i=="\n" and t!="":
97+
T+="session.evaluate(wlexpr(\'"+t+"\'))\n"
98+
t=""
99+
elif i!="\n":
100+
t+=i
101+
return T
308 Bytes
Binary file not shown.

pfcf/codel/wolfram.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
def settings(command: str,param):
2+
t=""
3+
if command=="inject":
4+
t=param+"\n"
5+
return t

pfcf/read.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ def read(name: str,printYesOrNo: int =1,returnText: int =0):
77
t=""
88
code=""
99
codel="" #code language
10-
codel2=""
1110
m=0
1211
codem=0
1312
p=Parser()
@@ -31,16 +30,15 @@ def read(name: str,printYesOrNo: int =1,returnText: int =0):
3130
elif j=="<" or j==">":
3231
codem+=1
3332
elif codem==4:
34-
if codel2==codel:
33+
try:
3534
codef(codel,code)
3635
codem==0
3736
codel=""
38-
codel2=""
39-
else:
37+
code=""
38+
except:
4039
print("Sintax error")
4140
elif codem==3:
42-
if j!="/":
43-
codel2+=j
41+
pass
4442
elif codem==2:
4543
code+=j
4644
elif codem==1: #Code mode on

pfcf/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,4 @@ def execute(name):
5353
t="/usr/bin/python "+name+".py"
5454
os.system(t)
5555
except:
56-
print("Execute error in: "+"/usr/bin/python "+name+".py")
56+
print("Execute error in: "+"/usr/bin/python "+name+".py")

0 commit comments

Comments
 (0)