compiler-theory

Phases of a compiler?

丶灬走出姿态 提交于 2019-12-22 08:10:58
问题 At which phase of the compilation are keywords of a programming language recognized? I am sort of confused between The lexical analysis. The parsing of the program. I once wrote a lexer in C using regular expressions but it recognised the main() in int main(void) also as a keyword. On these lines I think that we have to build a parse tree to recognize keywords. 回答1: I had to build a simple compiler this year as a project for which i used Java . The recognition of keywords was made on lexical

Phases of a compiler?

爱⌒轻易说出口 提交于 2019-12-22 08:09:27
问题 At which phase of the compilation are keywords of a programming language recognized? I am sort of confused between The lexical analysis. The parsing of the program. I once wrote a lexer in C using regular expressions but it recognised the main() in int main(void) also as a keyword. On these lines I think that we have to build a parse tree to recognize keywords. 回答1: I had to build a simple compiler this year as a project for which i used Java . The recognition of keywords was made on lexical

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

橙三吉。 提交于 2019-12-21 04:13:36
问题 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? 回答1: Compiler

Learning Resources on Parsers, Interpreters, and Compilers [closed]

五迷三道 提交于 2019-12-17 03:23:12
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . I've been wanting to play around with writing my own language for a while now (ostensibly for the learning experience) and as such need to be relatively grounded in the construction of Parsers, Interpreters, and Compilers. So: Does anyone know of any good resources on constructing Parsers, Interpreters, and

How can a program compiled to machine language run on different machines?

我们两清 提交于 2019-12-10 13:57:02
问题 In school we've been taught that compilers compile a computer program to machine language. We've also been taught that the machine language consists of direct instructions to the hardware. Then how can the same compiled program run on several computer configurations with different hardware? 回答1: Depends what you mean by 'different hardware' if it is the same processor (or same family eg Intel x86) then the machine code instructions are the same. If the extra hardware is different peripherals

Indentation control while developing a small python like language

纵饮孤独 提交于 2019-12-09 06:52:41
问题 I'm developing a small python like language using flex, byacc (for lexical and parsing) and C++, but i have a few questions regarding scope control. just as python it uses white spaces (or tabs) for indentation, not only that but i want to implement index breaking like for instance if you type "break 2" inside a while loop that's inside another while loop it would not only break from the last one but from the first loop as well (hence the number 2 after break) and so on. example: while 1

I'm attempting to write a .NET compiler using System.Reflection.Emit how do I do type resolution?

社会主义新天地 提交于 2019-12-07 15:53:55
问题 I've got a strategy for resolving types from referenced dlls. I'm stuck on trying to resolve types that are defined in the assembly that is being compiled. I'm using the System.Reflection.Emit apis with no 3rd party libraries. For instance: class A {} class B { public A AnInstanceOfA {get; private set;} } What's the best way to resolve B's reference of A? What about this: class A { B AnInstanceOfB {get; set;} } class B { A AnInstanceOfA {get; set;} } where the classes contain instances of

What are GCC's passes and invoked programs?

假如想象 提交于 2019-12-07 11:07:20
问题 It came up in another question: What are the programs and parts called by gcc (particularly when compiling C or C++ ) so that someone might engineer some scheme of intercepting and altering the flow for various custom coding purposes? 回答1: The compiler binaries are the "compiler driver" (i.e. gcc ), and the compiler itself which also doubles as a preprocessor ( cc1 or cc1plus ). It also invokes the assembler ( as ), and the linker ( ld ). Additionally there's a tool called collect2 that

What are GCC's passes and invoked programs?

大城市里の小女人 提交于 2019-12-05 12:26:48
It came up in another question : What are the programs and parts called by gcc (particularly when compiling C or C++ ) so that someone might engineer some scheme of intercepting and altering the flow for various custom coding purposes? The compiler binaries are the "compiler driver" (i.e. gcc ), and the compiler itself which also doubles as a preprocessor ( cc1 or cc1plus ). It also invokes the assembler ( as ), and the linker ( ld ). Additionally there's a tool called collect2 that assists during the link process in some cases. If you want to see what the intermediate states and invocations

Advantages of compilers for functional languages over compilers for imperative languages

China☆狼群 提交于 2019-12-04 08:28:48
问题 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