interpreter

Switch or if statements in writing an interpreter in java

ε祈祈猫儿з 提交于 2019-12-02 11:23:56
Current assignment needs me to write a program to read a file with instructions in a very tiny and basic programming language (behaves a little like FORTRAN) and execute those instructions. Basically it's a simple interpreter for the language I guess. It's completely linear, with statements all being defined in sequence and it only has String and integer variables. There are 8 keywords and 4 arithmetic operators I would need to find and define if they exist within the source file, and each line must start off with one of the reserved words. A program in this language might look something like

Understanding how Python “Compiles” or “Interprets” Function Objects

主宰稳场 提交于 2019-12-02 08:25:39
I have read the following posts but I am still unsure of something. Python Compilation/Interpretation Process Why python compile the source to bytecode before interpreting? If I have a single Python file myfunctions.py containing the following code. x = 3 def f(): print x x = 2 Then, saying $ python myfunctions.py runs perfectly fine. But now make one small change to the above file. The new file looks as shown below. x = 3 def f(): print x x = 2 f() # there is a function call now This time, the code gives out an error. Now, I am trying to understand this behavior. And so far, these are my

Variable assigned to the last executed line? [closed]

感情迁移 提交于 2019-12-02 07:28:38
I just found something weird in the Python interpreter. Let me show you: $ python Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53) [GCC 4.5.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> _ Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name '_' is not defined >>> 5 + 4 9 >>> _ 9 >>> 'Hello world' 'Hello world' >>> _ 'Hello world' >>> type(3.5) <type 'float'> >>> _ <type 'float'> You can try this in your interpreter; there are no tricks at work here! Is the result of the last executed line being assigned to a variable

Converting bytes to string with str() returns string with speech marks

喜你入骨 提交于 2019-12-02 06:55:30
Say I have a variable containing bytes: >>> a = b'Hello World' It can be verified with: >>> type(a) <class 'bytes'> Now I try and convert a into a string with str() : >>> b = str(a) and sure enough it is a string: >>> type(b) <class 'str'> Now I try and print b but I get a totally unexpected result: >>> print(b) b'Hello World' It returns a string, as I would expect but also it keeps the b (byte symbol) and the ' (quotation marks). Why does it do this, and not just print the message between the quotation marks? Don't think of a bytes value as a string in some default 8-bit encoding. It's just

Get value from IO rather than the computation itself

巧了我就是萌 提交于 2019-12-02 06:29:56
问题 Being quite new to Haskell, I'm currently trying to improve my skills by writing an interpreter for a simple imperative toy language. One of the expressions in this language is input , which reads a single integer from standard input. However, when I assign the value of this expression to a variable and then use this variable later, it seems ot me that I actually stored the computation of reading a value rather the read value itself. This means that e.g. the statements x = input; y = x + x;

How can I add interpreter to PyCharm?

a 夏天 提交于 2019-12-02 05:37:53
问题 When I try to run code in editor,it says that there is no available interpreters.Please,help.How can I solve the problem? 回答1: Just read the PyCharm's Docs. https://www.jetbrains.com/pycharm/quickstart/configuring_interpreter.html Step by step: Go to Settings . Go to the section Project Interpreter . Click on the plus (+) button and select the Local option. Search for the interpreter, in Linux it is used to be in /usr/bin/python or /usr/bin/pythonX.Y where X and Y are the version. In Windows,

How does Python read and interpret source files?

落花浮王杯 提交于 2019-12-02 02:39:00
Say I run a Python (2.7, though I'm not sure that makes a difference here) script. Instead of terminating the script, I tab out, or somehow switch back to my editing environment. I can then modify the script and save it, but this changes nothing in the still-running script. Does Python load all source files into memory completely at launch? I am under the impression that this is how the Python interpreter works, but this contradicts my other views of the Python interpreter: I have heard that .pyc files serve as byte-code for Python's virtual machine, like .class files in Java. At the same time

How can I provide garbage collection for an interpreted language implemented in C?

不想你离开。 提交于 2019-12-01 22:34:07
问题 If I were to implement a garbage collected interpreted language in C, how can I go about providing precise (i.e. not conservative) garbage collection without writing my own garbage collector? Are there libraries available for this? If so, which ones? I understand that I would have to maintain certain invariants on my end for any objects tracked by the garbage collector. 回答1: If you want a precise GC (not a conservative one, like Boehm's GC, which performs quite well in practice) you should

Using WinPython as Interpreter for PyCharm

蹲街弑〆低调 提交于 2019-12-01 20:21:40
问题 sorry for a simple question! I want to use WinPython (recently installed) as a interpreter for PyCharm Community Edition but am getting an error "The selected file is not a valid home for Python SDK" (see image) Does anybody have any idea of what the issue may be? Do I have to do any other steps (with the path, etc.)? 回答1: You need to select the folder where a python.exe (and possibly pythonw.exe ) exists, which looks like maybe the python-3.4.4.amd64 folder And, according to this answer open

How to determine which Python install is being used by the interpreter? [duplicate]

陌路散爱 提交于 2019-12-01 19:39:15
This question already has an answer here: Find full path of the Python interpreter? 3 answers I have several software packages that install various installs of Python. For example: C:\Python27\ArcGIS10.1 C:\Python27\ArcGIS10.2 C:\Python27|ArcGISx6410.1 Using sys.version does not work for my case since I need to know where the actual install is located, not the version. How can I determine which install my Python interpreter is using? kindall What you want is sys.executable , which will give the path to actual interpreter executable. 来源: https://stackoverflow.com/questions/24895901/how-to