interpreter

How do I add tab completion to the Python shell?

好久不见. 提交于 2019-11-26 14:59:30
问题 When starting a django application using python manage.py shell , I get an InteractiveConsole shell - I can use tab completion, etc. Python 2.5.1 (r251:54863, Apr 15 2008, 22:57:26) [GCC 4.0.1 (Apple Inc. build 5465)] on darwin Type "help", "copyright", "credits" or "license" for more information. (InteractiveConsole) When just starting a python interpreter using python , it doesn't offer tab completion. Can someone tell me what django is doing to give me an interactive console, or what I

Avoiding the infamous “eval(parse())” construct

徘徊边缘 提交于 2019-11-26 13:58:58
问题 Ok, so I'm running some loops to process data stored in list objects. Ever mindful of the infamous fortune admonishment not to use eval(parse(mystring)) , I came up with this: Rgames> bar $foo $foo$fast [1] 1 2 3 4 5 $foo$slow [1] 6 7 8 9 10 $oof $oof[[1]] [1] 6 7 8 9 10 $oof[[2]] [1] 1 2 3 4 5 Rgames> rab<-'bar' Rgames> do.call('$',list(as.name(rab),'oof')) [[1]] [1] 6 7 8 9 10 [[2]] [1] 1 2 3 4 5 Typically I'd be selecting a list (of which bar is one such) and then one element of the list

Suggestions for writing a programming language? [closed]

纵然是瞬间 提交于 2019-11-26 13:18:45
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 3 years ago . What tips can you give a person who is looking to write a programming or script language? I am not worried about how to program nor design a compiler but how to develop one quickly using tools and code generators. Last time i tried i coded it in c++ and the states and syntax took

Python Compilation/Interpretation Process

时光怂恿深爱的人放手 提交于 2019-11-26 12:53:33
问题 I\'m trying to understand the python compiler/interpreter process more clearly. Unfortunately, I have not taken a class in interpreters nor have I read much about them. Basically, what I understand right now is that Python code from .py files is first compiled into python bytecode (which i assume are the .pyc files i see occasionally?). Next, the bytecode is compiled into machine code, a language the processor actually understands. Pretty much, I\'ve read this thread Why python compile the

Load Scala file into interpreter to use functions?

烂漫一生 提交于 2019-11-26 12:39:58
问题 I have some Scala functions defined in a file, not in a class, and I would like to use them in the Scala interpreter. I know I can say scala filename.scala to simply run the file and exit the interpreter, but I would like to run the file and then stay in the interpreter so I can do some testing. Can anyone tell me how to simply load a file into the interpreter so I can use the functions defined within it? 回答1: type :load /path/to/file in Scala REPL. You can get complete list of available

Drop into interpreter during arbitrary scala code location

安稳与你 提交于 2019-11-26 12:15:40
问题 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? 回答1: 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

Do comments slow down an interpreted language?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-26 11:16:01
问题 I am asking this because I use Python, but it could apply to other interpreted languages as well (Ruby, PHP, JavaScript). Am I slowing down the interpreter whenever I leave a comment in my code? According to my limited understanding of an interpreter, it reads program expressions in as strings and then converts those strings into code. It seems that every time it parses a comment, that is wasted time. Is this the case? Is there some convention for comments in interpreted languages, or is the

Constructing an Abstract Syntax Tree with a list of Tokens

青春壹個敷衍的年華 提交于 2019-11-26 08:46:55
问题 I want to construct an AST from a list of tokens. I\'m making a scripting language and I\'ve already done the lexical analysis part, but I have no idea how to create an AST. So the question is, how do I take something like this: WORD, int WORD, x SYMBOL, = NUMBER, 5 SYMBOL, ; and convert it into an Abstract Syntax Tree? Preferably, I\'d like to do so without a library like ANTLR or whatever, I\'d rather try and do it from scratch myself. However, if it\'s a really complex task, I don\'t mind

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

自作多情 提交于 2019-11-26 07:55:56
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 4 years ago . 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

In Python interpreter, return without “ &#39; ”

拈花ヽ惹草 提交于 2019-11-26 05:37:30
问题 In Python, how do you return a variable like: function(x): return x Without the \'x\' ( \' ) being around the x ? 回答1: 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