compiler-theory

Is there a way to compile C++ to C Code?

邮差的信 提交于 2019-12-03 15:15:32
问题 I have a program which is configured by the user by using C++ classes and the same class should be used to configure a program which can only use a subset of C99 (Open CL Language). So my question is: Is there a way to compile C++ to C-Code? Open Source would be great! 回答1: The C++ FAQ has a list of possibilities: Is it possible to convert C++ to C?. In short, it says that you can't expect this to give you particularly readable code. Think of the complexities involved; multiple inheritance,

What language features are required in a programming language to make a compiler?

僤鯓⒐⒋嵵緔 提交于 2019-12-03 13:10:32
Programming languages seem to go through several stages. Firstly, someone dreams up a new language, Foo Language. The compiler/interpreter is written in another language, usually C or some other low level language. At some point, FooL matures and grows, and eventually someone, somewhere will write a compiler and/or interpreter for FooL in FooL itself. My question is this: What is the minimal subset of language features such that someone could implement that language in itself? Marek Compiler can be written even using a Turing machine - a Universal Turing Machine is basically a compiler

Removing Left Recursion in ANTLR

◇◆丶佛笑我妖孽 提交于 2019-12-03 12:51:06
问题 As is explained in Removing left recursion , there are two ways to remove the left recursion. Modify the original grammar to remove the left recursion using some procedure Write the grammar originally not to have the left recursion What people normally use for removing (not having) the left recursion with ANTLR? I've used flex/bison for parser, but I need to use ANTLR. The only thing I'm concerned about using ANTLR (or LL parser in genearal) is left recursion removal. In practical sense, how

Efficient way to recursively calculate dominator tree?

瘦欲@ 提交于 2019-12-03 11:31:31
问题 I'm using the Lengauer and Tarjan algorithm with path compression to calculate the dominator tree for a graph where there are millions of nodes. The algorithm is quite complex and I have to admit I haven't taken the time to fully understand it, I'm just using it. Now I have a need to calculate the dominator trees of the direct children of the root node and possibly recurse down the graph to a certain depth repeating this operation. I.e. when I calculate the dominator tree for a child of the

Is there a way to compile C++ to C Code?

允我心安 提交于 2019-12-03 05:01:00
I have a program which is configured by the user by using C++ classes and the same class should be used to configure a program which can only use a subset of C99 (Open CL Language). So my question is: Is there a way to compile C++ to C-Code? Open Source would be great! Oliver Charlesworth The C++ FAQ has a list of possibilities: Is it possible to convert C++ to C? . In short, it says that you can't expect this to give you particularly readable code. Think of the complexities involved; multiple inheritance, virtual-function resolution, templates, operator overloading, etc., etc. There's no

Efficient way to recursively calculate dominator tree?

筅森魡賤 提交于 2019-12-03 01:52:38
I'm using the Lengauer and Tarjan algorithm with path compression to calculate the dominator tree for a graph where there are millions of nodes. The algorithm is quite complex and I have to admit I haven't taken the time to fully understand it, I'm just using it. Now I have a need to calculate the dominator trees of the direct children of the root node and possibly recurse down the graph to a certain depth repeating this operation. I.e. when I calculate the dominator tree for a child of the root node I want to pretend that the root node has been removed from the graph. My question is whether

Advantages of compilers for functional languages over compilers for imperative languages

旧时模样 提交于 2019-12-02 23:30:33
As a follow up to this question What are the advantages of built-in immutability of F# over C#? --am I correct in assuming that the F# compiler can make certain optimizations knowing that it's dealing with largely immutable code? I mean even if a developer writes "Functional C#" the compiler wouldn't know all of the immutability that the developer had tried to code in so that it couldn't make the same optimizations, right? In general would the compiler of a functional language be able to make optimizations that would not be possible with an imperative language--even one written with as much

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

烈酒焚心 提交于 2019-12-02 10:22:49
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 but its a bit tricky and as many times i've tried i couldn't transform it to LL(1). Thank you in advance

LR1 Parser and Epsilon

点点圈 提交于 2019-12-01 22:06:35
问题 I'm trying to understand how LR1 Parsers work but I came up with a strange problem: What if the grammar contains Epsilons? For instance: if I have the grammar: S -> A A -> a A | B B -> a It's clear how to start: S -> .A A -> .a A A -> .B ... and so on but I don't know how to do it for such a grammar: S -> A A -> a A a | \epsilon Is it correct to do: S -> .A A -> .a A a ( A -> .\epsilon ) And then make this State in the DFA accepting? Any help would really be appreciated! 回答1: Yes, exactly

Register allocation and spilling, the easy way?

天涯浪子 提交于 2019-11-29 20:22:24
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 to read too much literature. Efficiency -- it needs to be better than the current method, which is: