mathematica 西門子plc語句表stl簡易直譯器
阿新 • • 發佈:2018-12-20
準備考試的,當前程式輸出每一步的操作和操作之後的棧,最後輸出程式輸出與輸入的關係
STLInterp[stl_]:=Block[{stllist,stack,out},
stack=ConstantArray[0,9];
out={"Q0."<>[email protected]#->0}&/@Range[0,7]//Association;
[email protected][stl,"\n"];
(Switch[#[[1]],
"LD",[email protected];stack[[1]]=#[[2]],
"LDN",[email protected] ;stack[[1]]=!#[[2]],
"O",stack[[1]]=stack[[1]]||#[[2]],
"A",stack[[1]]=stack[[1]]&&#[[2]],
"ON",stack[[1]]=stack[[1]]||!#[[2]],
"AN",stack[[1]]=stack[[1]]&&!#[[2]],
"=",out[#[[2]]]=stack[[1]],
"ALD",[email protected];stack[[1]]=stack[[1]]&&stack[[9]];stack[[9]]=0,
"OLD",[email protected] ;stack[[1]]=stack[[1]]||stack[[9]];stack[[9]]=0,
"LPS",[email protected];stack[[1]]=stack[[2]],
"LRD",stack[[1]]=stack[[2]],
"LPP",[email protected];stack[[9]]=0
];Print[{#,stack}])&/@stllist;
[email protected]@out
]