compiler-theory

LR(1) parsing table with epsilon productions

青春壹個敷衍的年華 提交于 2020-05-27 05:03:06
问题 I'm having trouble building the collection of sets of items for LR(1) parsers with a grammar containing epsilon productions. For example, given the following grammar (where eps stands for epsilon) S -> a S U U -> b | eps State0 would be S' -> .S, $ S -> .a S U, $ Moving with 'a' from State0 would give the following state, let's call it State2 S -> a .S U, $ S -> .a S U, $/??? In order to have the lookahead for the second item of State2 I need to calculate FIRST(U$). I know that FIRST(U) = {'b

LR(1) parsing table with epsilon productions

早过忘川 提交于 2020-05-27 05:02:09
问题 I'm having trouble building the collection of sets of items for LR(1) parsers with a grammar containing epsilon productions. For example, given the following grammar (where eps stands for epsilon) S -> a S U U -> b | eps State0 would be S' -> .S, $ S -> .a S U, $ Moving with 'a' from State0 would give the following state, let's call it State2 S -> a .S U, $ S -> .a S U, $/??? In order to have the lookahead for the second item of State2 I need to calculate FIRST(U$). I know that FIRST(U) = {'b

What are modern and old compilers written in?

送分小仙女□ 提交于 2020-01-12 09:58:44
问题 As a compiler, other than an interpreter, only needs to translate the input and not run it the performance of itself should be not that problematic as with an interpreter. Therefore, you wouldn't write an interpreter in, let's say Ruby or PHP because it would be far too slow. However, what about compilers? If you would write a compiler in a scripting language maybe even featuring rapid development you could possibly cut the source code and initial development time by halv, at least I think so

What are good resources on compilation? [duplicate]

こ雲淡風輕ζ 提交于 2020-01-11 19:51:57
问题 This question already has answers here : Learning Resources on Parsers, Interpreters, and Compilers [closed] (12 answers) Closed 5 years ago . Summary for the impatient: I'm searching for good references on generating code for common language constructs but not parsing. I am interested in programming languages and try to read the literature as much as possible. But most of them covers the topic in a functional and theoretical perspective that, I find them hard to understand let alone

What are good resources on compilation? [duplicate]

余生长醉 提交于 2020-01-11 19:50:30
问题 This question already has answers here : Learning Resources on Parsers, Interpreters, and Compilers [closed] (12 answers) Closed 5 years ago . Summary for the impatient: I'm searching for good references on generating code for common language constructs but not parsing. I am interested in programming languages and try to read the literature as much as possible. But most of them covers the topic in a functional and theoretical perspective that, I find them hard to understand let alone

Compiler evaluation of explicit null-check vs. null-coalescing operator?

五迷三道 提交于 2020-01-03 16:24:51
问题 Consider the following code, which uses two slightly different methods to check _instance and assign it when not already set. class InstantiationTest { private Object _instance; public void Method1() { if(_instance == null) { _instance = new Object(); } } public void Method2() { _instance = _instance ?? new Object(); } } Either VS or Resharper keeps underlining my explicit null checks, and prompting me to refactor using the null-coalescing operator. I wondered whether the compiler is smart

Finding a grammar is not LL(1) without using classical methods and transforming it to LL(1)

故事扮演 提交于 2019-12-31 06:04:47
问题 Let's say i have this grammar: S -> A C x | u B A A -> z A y | S u | ε B -> C x | y B u C -> B w B | w A This grammar is obviously not LL(1), which i can find constructing the parsing table. But is there any way i can prove that this grammar is not LL(1) without using the classical methods i.e. without constructing the parsing table or finding any conflicts? Also how can i convert this grammar to LL(1)? I think i have to use both epsilon-derivation elimination and left recursion elimination

Finding a grammar is not LL(1) without using classical methods and transforming it to LL(1)

时光总嘲笑我的痴心妄想 提交于 2019-12-31 06:04:06
问题 Let's say i have this grammar: S -> A C x | u B A A -> z A y | S u | ε B -> C x | y B u C -> B w B | w A This grammar is obviously not LL(1), which i can find constructing the parsing table. But is there any way i can prove that this grammar is not LL(1) without using the classical methods i.e. without constructing the parsing table or finding any conflicts? Also how can i convert this grammar to LL(1)? I think i have to use both epsilon-derivation elimination and left recursion elimination

Is performance of “less/greater than than” better than “less/greater than or equal to”

旧街凉风 提交于 2019-12-24 04:25:09
问题 Is it computationally more performant to compare less/greater than over less/greater than or equal to ? Intuitively one could think that less/greater than is marginally better. Can a compiler use some trick to make the comparisons seem the same? A compiler could eliminate e.g. less than or equal to with less than by incrementing the bound by one but if the bound is "alive" then this cannot be done. 回答1: On virtually every modern CPU, there are compare/jumpless and compare/jumplessequal