theory

Why can't a recursive-descent parser handle left recursion

匆匆过客 提交于 2019-11-27 19:05:56
Could someone please explain to me why recursive-descent parsers can't work with a grammar containing left recursion? consider: A ::= A B the equivalent code is boolean A() { if (A()) { return B(); } return false; } see the infinite recursion? For whoever is interested A ::= A B | A C | D | E can be rewritten as: A ::= (D | E) (B | C)* The general form of the transformation is: any one of the non left recursive disjuncts followed by any number of the left recursive disjuncts without the first element. Reforming the action code is a bit trickery but I thing that can be plug-n-chug as well. 来源:

Learning garbage collection theory [closed]

我与影子孤独终老i 提交于 2019-11-27 17:00:07
I want to learn the theory behind garbage collection. How do i go about it? The obvious answer is - a compiler textbook... The question is, is it necessary to learn lexical analysis, parsing and other stuff that usually precedes garbage collection in a text? In short, what are the prerequisites to learning about Garbage collection theory? P.S - I do know what is the purpose of parsing, lexical analysis etc. Just not how they are implemented. Sam Harwell Read these papers in order. They are in progressive subject matter/difficulty order (not chronological). List taken directly from Prof.

Text editor theory [closed]

泪湿孤枕 提交于 2019-11-27 16:50:31
As I'm always dissatisfied with existing editors, a project I always wanted to start is my own text editor. However doing text editing is serious business. Besides analyzing the source code of existing text editors, is there any book or other resource (like academic work) about this topic? I'm interested especially in something that teaches how to handle memory and how to manage text insertion (if you have a 100 MB file and want to add a char at x position, you can't just memmove the huge text block...). Take a look at Rob Pike's description of his Sam text editor . Be sure to browse past the

How to program a fractal?

血红的双手。 提交于 2019-11-27 16:41:41
I do not have any experience with programming fractals. Of course I've seen the famous Mandelbrot images and such. Can you provide me with simple algorithms for fractals. Programming language doesn't matter really, but I'm most familiar with actionscript, C#, Java. I know that if I google fractals, I get a lot of (complicated) information but I would like to start with a simple algorithm and play with it. Suggestions to improve on the basic algorithm are also welcome, like how to make them in those lovely colors and such. Programming the Mandelbrot is easy. My quick-n-dirty code is below (not

What is an NP-complete in computer science?

谁都会走 提交于 2019-11-27 16:33:15
What is an NP-complete problem? Why is it such an important topic in computer science? Sam Hoice NP stands for Non-deterministic Polynomial time. This means that the problem can be solved in Polynomial time using a Non-deterministic Turing machine (like a regular Turing machine but also including a non-deterministic "choice" function). Basically, a solution has to be testable in poly time. If that's the case, and a known NP problem can be solved using the given problem with modified input (an NP problem can be reduced to the given problem) then the problem is NP complete. The main thing to

What will be the DFA for the regular expression 0(0+1)*0+1(0+1)*1?

孤人 提交于 2019-11-27 16:22:39
This is the DFA i have drawn- Is it correct? I am confused because q4 state has 2 different transitions for same input symbol which violates the rule of DFA , but I can't think of any other solution. Your DFA is not correct. your DFA is completely wrong so I don't comment DFA for RE: 0(1 + 0)*0 + 1(1 + 0)*1 Language Description : if string start with 0 it should end with 0 or if string start with 1 it should end with 1 . hence two final states (state-5, state-4). state-4 : accepts 1(1 + 0)*1 state-5 : accepts 0(1 + 0)*0 state-1 : start state. DFA : EDIT : + Operator in Regular Expression (0 +

complexity of parsing C++

社会主义新天地 提交于 2019-11-27 15:17:20
问题 Out of curiosity, I was wondering what were some "theoretical" results about parsing C++. Let n be the size of my project (in LOC, for example, but since we'll deal with big-O it's not very important) Is C++ parsed in O(n) ? If not, what's the complexity? Is C (or Java or any simpler language in the sense of its grammar) parsed in O(n)? Will C++1x introduce new features that will be even harder to parse? References would be greatly appreciated! 回答1: I think the term "parsing" is being

Recovering built-in methods that have been overwritten

一曲冷凌霜 提交于 2019-11-27 14:42:18
Let's say that our script is included in a web-page, and a prior script (that already executed) did this: String.prototype.split = function () { return 'U MAD BRO?'; }; So, the split string method has been overwritten. We would like to use this method, so we need to recover it somehow. Of course, we could just define our own implementation of this method and use that instead. However, for the sake of this question, let's just say that we really wanted to recover the browser's implementation of that method. So, the browser has an implementation of the split method (in native code, I believe),

How do we decide the number of dimensions for Latent semantic analysis ?

牧云@^-^@ 提交于 2019-11-27 14:06:20
问题 I have been working on latent semantic analysis lately. I have implemented it in java by making use of the Jama package. Here is the code: Matrix vtranspose ; a = new Matrix(termdoc); termdoc = a.getArray(); a = a.transpose() ; SingularValueDecomposition sv =new SingularValueDecomposition(a) ; u = sv.getU(); v = sv.getV(); s = sv.getS(); vtranspose = v.transpose() ; // we obtain this as a result of svd uarray = u.getArray(); sarray = s.getArray(); varray = vtranspose.getArray(); if(semantics

What is a DSL and where should I use it?

喜你入骨 提交于 2019-11-27 13:54:34
问题 I'm hearing more and more about domain specific languages being thrown about and how they change the way you treat business logic, and I've seen Ayende's blog posts and things, but I've never really gotten exactly why I would take my business logic away from the methods and situations I'm using in my provider. If you've got some background using these things, any chance you could put it in real laymans terms: What exactly building DSLs means? What languages are you using? Where using a DSL