compiler-theory

Steps to creating an NFA from a regular expression

霸气de小男生 提交于 2019-11-29 19:27:53
I'm having issues 'describing each step' when creating an NFA from a regular expression. The question is as follows: Convert the following regular expression to a non-deterministic finite-state automaton (NFA), clearly describing the steps of the algorithm that you use: (b|a)*b(a|b) I've made a simple 3-state machine but it's very much from intuition. This is a question from a past exam written by my lecturer, who also wrote the following explanation of Thompson's algorithm: http://www.cs.may.ie/staff/jpower/Courses/Previous/parsing/node5.html Can anyone clear up how to 'describe each step

What is the precise definition of a lookahead set?

偶尔善良 提交于 2019-11-29 10:41:44
I'm toying around with writing compilers and learning about the theory behind syntax analysis. I've found that even though it's a key concept for understanding recognition algorithms, information about it on the net is fairly poor. It seems StackOverflow is in a unique position to fix this problem. The lookahead sets for a grammar is defined in terms of the lookahead sets for each of its non-terminals, which in turn rely on the lookahead set for each production. Determining lookahead sets can help us determine if a grammar is LL(1) , and if it is, what information we need to construct a

What is the precise definition of a lookahead set?

大兔子大兔子 提交于 2019-11-29 10:39:51
I'm toying around with writing compilers and learning about the theory behind syntax analysis. I've found that even though it's a key concept for understanding recognition algorithms, information about it on the net is fairly poor. It seems StackOverflow is in a unique position to fix this problem. The lookahead sets for a grammar is defined in terms of the lookahead sets for each of its non-terminals, which in turn rely on the lookahead set for each production. Determining lookahead sets can help us determine if a grammar is LL(1) , and if it is, what information we need to construct a

complexity of parsing C++

强颜欢笑 提交于 2019-11-28 23:49:28
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! I think the term "parsing" is being interpreted by different people in different ways for the purposes of the question. In a narrow technical sense,

Register allocation and spilling, the easy way?

自古美人都是妖i 提交于 2019-11-28 15:51:16
问题 I'm looking for a way to allocate local variables to registers. I'm aware of a couple of serious methods for doing it (namely, those mentioned on Wikipedia), but I'm stuck on how "spilling" is accomplished. Also, the relevant literature is quite intimidating. I'm hoping there's something simpler that will satisfy my priorities: Correctness -- an algorithm that will generate correct code regardless of how many local variables there are. Simplicity -- something I can understand without having

Steps to creating an NFA from a regular expression

人盡茶涼 提交于 2019-11-28 14:54:26
问题 I'm having issues 'describing each step' when creating an NFA from a regular expression. The question is as follows: Convert the following regular expression to a non-deterministic finite-state automaton (NFA), clearly describing the steps of the algorithm that you use: (b|a)*b(a|b) I've made a simple 3-state machine but it's very much from intuition. This is a question from a past exam written by my lecturer, who also wrote the following explanation of Thompson's algorithm: http://www.cs.may

How do C compilers implement functions that return large structures?

给你一囗甜甜゛ 提交于 2019-11-28 06:51:00
The return value of a function is usually stored on the stack or in a register. But for a large structure, it has to be on the stack. How much copying has to happen in a real compiler for this code? Or is it optimized away? For example: struct Data { unsigned values[256]; }; Data createData() { Data data; // initialize data values... return data; } (Assuming the function cannot be inlined..) None; no copies are done. The address of the caller's Data return value is actually passed as a hidden argument to the function, and the createData function simply writes into the caller's stack frame.

Are there any “fun” ways to learn about Languages, Grammars, Parsing and Compilers? [closed]

╄→尐↘猪︶ㄣ 提交于 2019-11-28 04:12:26
I'm preparing for an exam concerning languages, grammars, parsing and compilers. It's not really my cup of tea and most resources I find use the language of mathematics to define the different terms of the trade and explain the different concepts I need to know rather than stick with English or French, which I would very much prefer. Therefore, I'm having some trouble both with finding the motivation to continue studying and with simply understanding the theory. So here is my question: Do any of you know where I could find a "fun" way of learning all this? Or at the very least, maybe a more

What is the precise definition of a lookahead set?

时光总嘲笑我的痴心妄想 提交于 2019-11-28 03:55:50
问题 I'm toying around with writing compilers and learning about the theory behind syntax analysis. I've found that even though it's a key concept for understanding recognition algorithms, information about it on the net is fairly poor. It seems StackOverflow is in a unique position to fix this problem. 回答1: The lookahead sets for a grammar is defined in terms of the lookahead sets for each of its non-terminals, which in turn rely on the lookahead set for each production. Determining lookahead

What programming languages are context-free?

旧时模样 提交于 2019-11-28 03:22:53
Or, to be a little more precise: which programming languages are defined by a context-free grammar? From what I gather C++ is not context-free due to things like macros and templates. My gut tells me that functional languages might be context free, but I don't have any hard data to back that up with. Extra rep for concise examples :-) The set of programs that are syntactically correct is context-free for almost all languages. The set of programs that compile is not context-free for almost all languages. For example, if the set of all compiling C programs were context free, then by intersecting