interpreter

Assigning a value to single underscore _ in Python/IPython interpreter

﹥>﹥吖頭↗ 提交于 2019-11-27 00:49:39
问题 I created this function in Python 2.7 with ipython : def _(v): return v later if I call _(somevalue) , I get _ = somevalue . in[3]: _(3) out[3]: 3 in[4]: print _ out[4]: 3 The function has disappeared! If I call _(4) I get: TypeError: 'int' object is not callable` Why? What's wrong with this function? 回答1: The Python interpreter assigns the last expression value to _ . This behaviour is limited to the REPL interpreter only, and is intended to assist in interactive coding sessions: >>> import

How to write a Parser in C#? [closed]

半世苍凉 提交于 2019-11-26 23:36:41
How do I go about writing a Parser (Recursive Descent?) in C#? For now I just want a simple parser that parses arithmetic expressions (and reads variables?). Though later I intend to write an xml and html parser (for learning purposes). I am doing this because of the wide range of stuff in which parsers are useful: Web development, Programming Language Interpreters, Inhouse Tools, Gaming Engines, Map and Tile Editors, etc. So what is the basic theory of writing parsers and how do I implement one in C#? Is C# the right language for parsers (I once wrote a simple arithmetic parser in C++ and it

In Python interpreter, return without “ ' ”

点点圈 提交于 2019-11-26 22:45:40
In Python, how do you return a variable like: function(x): return x Without the 'x' ( ' ) being around the x ? In the Python interactive prompt, if you return a string, it will be displayed with quotes around it, mainly so that you know it's a string. If you just print the string, it will not be shown with quotes (unless the string has quotes in it). >>> 1 # just a number, so no quotes 1 >>> "hi" # just a string, displayed with quotes 'hi' >>> print("hi") # being *printed* to the screen, so do not show quotes hi >>> "'hello'" # string with embedded single quotes "'hello'" >>> print("'hello'")

Implementing a language interpreter in Haskell

混江龙づ霸主 提交于 2019-11-26 18:51:52
问题 I want to implement an imperative language interpreter in Haskell (for educational purposes). But it's difficult for me to create right architecture for my interpreter: How should I store variables? How can I implement nested function calls? How should I implement variable scoping? How can I add debugging possibilities in my language? Should I use monads/monad transformers/other techniques? etc. Does anybody know good articles/papers/tutorials/sources on this subject? 回答1: If you are new to

How to fix column calculation in Python readline if using color prompt

半腔热情 提交于 2019-11-26 18:25:32
问题 I use standard tips for customizing interactive Python session: $ cat ~/.bashrc export PYTHONSTARTUP=~/.pystartup $ cat ~/.pystartup import os import sys import atexit import readline import rlcompleter historyPath = os.path.expanduser("~/.pyhistory") def save_history(historyPath=historyPath): import readline readline.write_history_file(historyPath) if os.path.exists(historyPath): readline.read_history_file(historyPath) term_with_colors = ['xterm', 'xterm-color', 'xterm-256color', 'linux',

Drop into interpreter during arbitrary scala code location

帅比萌擦擦* 提交于 2019-11-26 18:05:36
I come from a Python background, where at any point in my code I can add import pdb; pdb.set_trace() and at runtime I'll be dropped into an interactive interpreter at that spot. Is there an equivalent for scala, or is this not possible at runtime? Yes, you can, on Scala 2.8. Note that, for this to work, you have to include the scala-compiler.jar in your classpath. If you invoke your scala program with scala , it will be done automatically (or so it seems in the tests I made). You can then use it like this: import scala.tools.nsc.Interpreter._ object TestDebugger { def main(args: Array[String])

References Needed for Implementing an Interpreter in C/C++

非 Y 不嫁゛ 提交于 2019-11-26 17:55:51
问题 I find myself attached to a project to integerate an interpreter into an existing application. The language to be interpreted is a derivative of Lisp, with application-specific builtins. Individual 'programs' will be run batch-style in the application. I'm surprised that over the years I've written a couple of compilers, and several data-language translators/parsers, but I've never actually written an interpreter before. The prototype is pretty far along, implemented as a syntax tree walker,

CPython is bytecode interpreter?

ⅰ亾dé卋堺 提交于 2019-11-26 16:09:50
问题 I don't really get the concept of "bytecode interpreter" in the context of CPython. Can someone shed some light over the whole picture? Does it mean that CPython will compile and execute pyc file (bytecode file?). Then what compile py file to pyc file? And how is Jython different from CPython (except they are implemented in different languages). I also read somewhere that Python is C++ interpretation. Is this correct? And what does that mean? I'm still very new to Python, so forgive me if I

How to use third party libraries with Scala REPL?

核能气质少年 提交于 2019-11-26 15:57:00
问题 I've downloaded Algebird and I want to try out few things in the Scala interpreter using this library. How do I achieve this? 回答1: Of course, you can use scala -cp whatever and manually manage your dependencies. But that gets quite tedious, especially if you have multiple dependencies. A more flexible approach is to use sbt to manage your dependencies. Search for the library you want to use on search.maven.org. Algebird for example is available by simply searching for algebird. Then create a

Learning Resources on Parsers, Interpreters, and Compilers [closed]

被刻印的时光 ゝ 提交于 2019-11-26 15:47:19
I've been wanting to play around with writing my own language for a while now (ostensibly for the learning experience) and as such need to be relatively grounded in the construction of Parsers, Interpreters, and Compilers. So: Does anyone know of any good resources on constructing Parsers, Interpreters, and Compilers? EDIT: I'm not looking for compiler-compilers/parser-compilers such as Lex, Yacc and Bison... The best paper I ever read on compilers is dated 1964 "META II a syntax-oriented compiler writing language" by Val Schorre. ( http://doi.acm.org/10.1145/800257.808896 ) In 10 pages, he