interpreter

How can I implement my own basic unix shell in C?

一曲冷凌霜 提交于 2019-11-28 17:52:14
问题 I'm a newbie to process and thread management. My Shell should understand PATH environment variable. It can be set and modified. It runs in two ways -interactive & batch mode. Shell is capable of taking more than one job like ls;ps;wc file;cal. I want to get my hands dirty on signals too. So I should handle ^K , ^c as well. I know I will have to use execs, forks and pipes but just can't get started. 回答1: All the unix shells are open-source - so a good place to start may be to read the code.

Does Python optimize away a variable that's only used as a return value?

痴心易碎 提交于 2019-11-28 17:20:47
Is there any ultimate difference between the following two code snippets? The first assigns a value to a variable in a function and then returns that variable. The second function just returns the value directly. Does Python turn them into equivalent bytecode? Is one of them faster? Case 1 : def func(): a = 42 return a Case 2 : def func(): return 42 No, it doesn't . The compilation to CPython byte code is only passed through a small peephole optimizer that is designed to do only basic optimizations (See test_peepholer.py in the test suite for more on these optimizations). To take a look at

What are the primitive Forth operators? [closed]

試著忘記壹切 提交于 2019-11-28 16:43:01
问题 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 months ago . I'm interested in implementing a Forth system, just so I can get some experience building a simple VM and runtime. When starting in Forth, one typically learns about the stack and its operators (DROP, DUP, SWAP, etc.) first, so it's natural to think of these as being among the

What are the differences between a Just-in-Time-Compiler and an Interpreter?

别来无恙 提交于 2019-11-28 16:13:23
What are the differences between a Just-in-Time-Compiler and an Interpreter, and are there differences between the .NET and the Java JIT compiler? Just-in-time compilation is the conversion of non-native code, for example bytecode, into native code just before it is executed. From Wikipedia: JIT builds upon two earlier ideas in run-time environments: bytecode compilation and dynamic compilation. It converts code at runtime prior to executing it natively, for example bytecode into native machine code. An interpreter executes a program. It may or may not have a jitter. Again, from Wikipedia: An

Java Threads vs OS Threads

雨燕双飞 提交于 2019-11-28 16:06:32
Looks like I have messed up with Java Threads/OS Threads and Interpreted language. Before I begin, I do understand that Green Threads are Java Threads where the threading is taken care of by the JVM and the entire Java process runs only as a single OS Thread. Thereby on a multi processor system it is useless. Now my questions is. I have two Threads A and B. Each with 100 thousand lines of independent code. I run these threads in my Java Program on a multiprocessor system. Each Thread will be given a native OS Thread to RUN which can run on a different CPU but since Java is interpreted these

Tab-completion in Python interpreter in OS X Terminal

泄露秘密 提交于 2019-11-28 16:01:50
问题 Several months ago, I wrote a blog post detailing how to achieve tab-completion in the standard Python interactive interpreter--a feature I once thought only available in IPython. I've found it tremendously handy given that I sometimes have to switch to the standard interpreter due to IPython unicode issues. Recently I've done some work in OS X. To my discontent, the script doesn't seem to work for OS X's Terminal application. I'm hoping some of you with experience in OS X might be able to

How to write an interpreter?

♀尐吖头ヾ 提交于 2019-11-28 15:40:58
问题 I have decided to write a small interpreter as my next project, in Ruby. What knowledge/skills will I need to have to be successful? I haven't decided on the language to interpret yet, but I am looking for something that is not a toy language, but would be relatively easy to write an interpreter for. Thanks in advance. 回答1: You will have to learn at least: lexical analysis (grouping characters into tokens) parsing (grouping tokens together into structure) abstract syntax trees (representing

C++ - Check if pointer is pointing to valid memory (Can't use NULL checks here)

天涯浪子 提交于 2019-11-28 11:28:59
问题 I am creating scripting language. When I allocate thing ,it's allocate the thing and returns the address and then I do whatever with it and then delete it. I can't control the variables in it like creating struct in my lang (Struct with pointer and bool to check if pointer is pointing to valid data) and etc because it'll make my lang slower and bigger in the RAM. For example: (My scripting language is easily to understood. I doubt you'll not understand this ,but I'll put some comments in it

C++ interpreter / console / snippet compiler

时间秒杀一切 提交于 2019-11-28 10:17:34
I am looking for a program where I can enter a C++ code snippet in one window, press a button, and get output in another window. Compilation should somehow be hidden behind the button. On a per-snippet basis would be fine, full interactive probably asking too much. It should run under Linux/Unix. Main use case would be learning/testing/short debugging, etc. Related stuff I found: -- the Reinteract project for python (which i'm told sage has features similar to) -- the same thread for C# here: C# Console? -- the CINT interpreter from the CERN ROOT project (which may be close, but maybe there

Javascript: When writing a for loop, why does it print the last index number?

自作多情 提交于 2019-11-28 09:43:47
问题 When writing a simple for loop in the js interpreter, I automatically get the last value the index number (i, in this case). js> for (var i=0; i<100; ++i) { numbers[i]=i+1; } 100 js> i 100 Can someone please explain why the interpreter works like that? I didn't explicitly ask it to print the value of i. Sorry for the ambiguous formulation, guys, but I didn't really know how to describe what's happening. 回答1: All statements in javascript have a value, including the block executed in looping