interpreter

How exactly is a PHP script executed?

这一生的挚爱 提交于 2019-12-17 03:09:13
问题 I was just thinking to myself "How exactly is a PHP script executed?" I thought it was parsed first for syntax errors etc, and then interpreted and executed. However, I don't know why I believe that is correct. I'm probably wrong. So, how exactly is a PHP file interpreted and executed? What stages does this involve? How do included files fit into the parsing of the script? This is just to help me get my head around it. I'm interested and can not find a good answer with Google. 回答1: PHP is a

Setting default interpreter for a python script

淺唱寂寞╮ 提交于 2019-12-14 01:47:44
问题 I am using a module that can only be found in python 2.7, so when I run my script I have to specify python2.7 script instead of just script . I know there are bigger issues out there, but still I was wondering - is it possible, when writing a python script, to set the interpreter to 2.7 by default? Maybe by setting #! /usr/bin/env python for example? 回答1: Most unix environments will have the python2.7 executable, such that you can write: #!/usr/bin/env python2.7 Obviously this doesn't help

Python shows wrong gcc version

只愿长相守 提交于 2019-12-13 22:43:59
问题 I updated gcc to v6 few weeks ago. Today i noticed that python2 and python3 both the interpreters were using gcc v5. Why does python interpreter show gcc v5 but I have gcc v6 installed? I am using xubuntu 16. Here is my terminal: 回答1: On your platform, gcc-6 command is referring to GCC V6 . gcc command is still referring to GCC V5 , Note: You can check it via typing gcc --version on terminal. 回答2: Did you download python or build it yourself? If you download python binaries, it's already

What is a cell in the context of an interpreter or compiler?

安稳与你 提交于 2019-12-13 11:33:55
问题 Python code objects have an attribute co_cellvars. The documentation to PyPy's bytecode interpreter often uses the term Cell . Among other langauges, Rust provides a Cell datatype. Googling suggests they relate to closures somehow. What is a cell , in the context of a programming language implementation? What problem do cells solve? 回答1: In Python, cell objects are used to store the free variables of a closure. Let's say you want a function that always returns a particular fraction of its

How to bring an interpreter to the IO monad?

微笑、不失礼 提交于 2019-12-13 09:06:49
问题 My question relates to the simple interpreter written in in this answer How could one add IO capabilities to this interpreter (the first non monadic version)? By this I simply mean adding a statement that uses putStrLn. I'm not that well versed in Haskell yet, but I'm guessing you can just combine the IO monad somehow. Can somebody point me in the right direction? data Stmt = Var := Exp | While Exp Stmt | Seq [Stmt] | Print Exp -- a print statement 回答1: You can make your interpreter have a

how do I implement loops (For) in javacc

懵懂的女人 提交于 2019-12-13 07:34:29
问题 I made an interpreter for a script language containing a loop for, using javacc I have defined the grammar but I can't have a way to back up to line to repeat the execution of the block "for". how back up the token manager so that loop-bodies can be re-parsed, and thus reevaluated, over and over again ?. void For(): {ArrayList<String> lst;Token n,v;int i=0;} { "for" "(" n=<ID> ":" v=<ID> ")" "{" (actions()";" )+ "}" } 回答1: As explained in the JavaCC FAQ (http://www.engr.mun.ca/~theo/JavaCC

Is there a way to emulate the Java behaviour of calling a parent class' static method for simple global-ish error handling?

元气小坏坏 提交于 2019-12-13 05:33:52
问题 I'm trying to implement a simple interpreter in Rust for a made up programming language called rlox , following Bob Nystrom's book Crafting Interpreters. I want errors to be able to occur in any child module, and for them to be "reported" in the main module (this is done in the book, with Java, by simply calling a static method on the containing class which prints the offending token and line). However, if an error occurs, it's not like I can just return early with Result::Err (which is, I

Tcl: Interpreter creates copy of traced object whet it goes changed

北城余情 提交于 2019-12-13 05:11:40
问题 #include <tcl.h> #include <iostream> using namespace std; char* myTraceProc(ClientData clientData, Tcl_Interp* interp, const char* name1, const char* name2, int flags) { cout << "myTraceProc" << endl; //changing the object return NULL; } int main(int argc, char* argv[]) { Tcl_FindExecutable(argv[0]); Tcl_Interp *interp = Tcl_CreateInterp(); Tcl_TraceVar(interp, "database", TCL_TRACE_WRITES, myTraceProc, 0); return 0; } This is a part of my c++/tcl program. In fact it doesn't show the problem

Classpath issue when binding an instance in a Scala Interpreter

 ̄綄美尐妖づ 提交于 2019-12-13 02:33:17
问题 I already posted this question in scala lang forum but unfortunately I did not get any answer. Second chance ? I try to embed an interpreter an evaluate a scala snippet into this interpreter. I would like to bind an instance of a custom class within the interpreter. To sum up that would look like: import scala.tools.nsc._ import scala.tools.nsc.interpreter._ class C { def sayHello(s:String) = "hello "+s } object Main extends App { val c= new C val s = new Settings s.usejavacp.value=true val i

I build a interpreter on a language with a garbage collector. I need a garbage collector for the interpreter?

不羁岁月 提交于 2019-12-13 02:05:06
问题 This is a naive question, but in the tutorials I have seen so far is not spelled clearly. If I build a interpreter on top a high-level language (not C, C++, etc) and this have a garbage collector... is necessary to also make one for the interpreter itself? And if the answers is yes... it must be the same kind of the host? (ie: If the host is mark-sweep, the interpreter too?), or is possible to leverage the host and let it manage all of this? The selection of host make a difference? I plan to