compiler-construction

Why can't C++ compiler know a pointer is pointing to a derived class?

别来无恙 提交于 2020-06-16 19:18:50
问题 I've just started learning about OOP in C++. I was wondering why is the virtual keyword needed to instruct the compiler to do late binding ? Why can't the compiler know at compile time that the pointer is pointing to a derived class ? class A { public: int f() { return 'A';} }; class B : public A { public: int f() { return 'B';} }; int main() { A* pa; B b; pa = &b; cout << pa->f() << endl; } 回答1: Regarding not knowing at compile time, it is often the case the behavior is only known at runtime

What is the most efficient way to create a lexer?

偶尔善良 提交于 2020-06-11 09:45:07
问题 I am currently trying to learn how to create my own lexical analyser, by hand. I had been using Flex (along with Bison) a lot to practice and learn how it works internally, but I am currently seeing at least 3 different solutions to develop my own. Using a list of REs, going through each and when one matches, simply return the associated token (see python docs about REs) Creating a DFA from REs (as does Flex for example: based on REs, create a big state machine) Creating my own 'state machine

What is the most efficient way to create a lexer?

偶尔善良 提交于 2020-06-11 09:45:01
问题 I am currently trying to learn how to create my own lexical analyser, by hand. I had been using Flex (along with Bison) a lot to practice and learn how it works internally, but I am currently seeing at least 3 different solutions to develop my own. Using a list of REs, going through each and when one matches, simply return the associated token (see python docs about REs) Creating a DFA from REs (as does Flex for example: based on REs, create a big state machine) Creating my own 'state machine

C++ references and pointers at the compiler level

会有一股神秘感。 提交于 2020-06-09 10:27:32
问题 I'm trying to learn how C++ compilers handle references and pointers, in preparation for a compiler class that I'm taking next semester. I'm specifically interested in how compilers handle references in C++. The standard specifies that a reference is an "alias," but I don't know exactly what that means at the compiler level. I have two theories: A non-reference variable has an entry in the symbol table. When a reference to that variable is created, the compiler simply creates another lexeme

How can I create an executable .exe PE file manually?

北城余情 提交于 2020-06-09 07:56:39
问题 All texts on how to create a compiler stop after explaining lexers and parsers. They don't explain how to create the machine code. I want to understand the end-to-end process. Currently what I understand is that, the Windows exe file formats are called Portable Executable. I read about the headers it has and am yet to find a resource which explains this easily. My next issue is, I don't see any resource which explains how machine code is stored in the file. Is it like 32-bit fixed length

Why are “Executable files” operating system dependent?

荒凉一梦 提交于 2020-06-07 09:21:08
问题 I understand that each CPU/architecture has it's own instruction set, therefore a program(binary) written for a specific CPU cannot run on another. But what i don't really understand is why an executable file (binary like .exe for instance) cannot run on Linux but can run on windows even on the very same machine. This is a basic question, and the answer i'm expecting is that .exe and other binary formats are probably not Raw machine instructions but they contain some data that is operating

Why are “Executable files” operating system dependent?

帅比萌擦擦* 提交于 2020-06-07 09:19:46
问题 I understand that each CPU/architecture has it's own instruction set, therefore a program(binary) written for a specific CPU cannot run on another. But what i don't really understand is why an executable file (binary like .exe for instance) cannot run on Linux but can run on windows even on the very same machine. This is a basic question, and the answer i'm expecting is that .exe and other binary formats are probably not Raw machine instructions but they contain some data that is operating

What is the best way to translate Z3's AST into ASM code? [closed]

怎甘沉沦 提交于 2020-05-17 06:05:21
问题 Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 2 days ago . There is an example: mov edi, dword ptr [0x7fc70000] add edi, 0x11 sub edi, 0x33F0B753 After Z3 simplification I have got (memory 0x7FC70000 is symbolized): bvadd (_ bv3423553726 32) MEM_0x7FC70000 Now I need to convert Z3 into ASM to get result like this: mov edi, 0xCC0F48BE add edi,

Dot file not genearting for -view-isel-dags option

浪尽此生 提交于 2020-05-14 09:12:09
问题 While trying to see the SelectionDag nodes generated during the instruction selection phase using LLVM (built from sources with debug mode enabled), I am using the below command which is not creating Graphviz DOT file. llc -view-isel-dags sum.bc Instead it is creating sum.s file. Is there something I'm missing here? sum.c int sum(int x, int y) { return x+y; } sum.bc $ clang -emit-llvm sum.c -c -o sum.bc LLVM information $ llc -help-hidden | grep 'view-isel' -view-isel-dags - Pop up a window

Algorithm for computing FIRST and FOLLOW sets for context-free grammars [closed]

主宰稳场 提交于 2020-05-11 06:40:30
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago . I need an algorithm to computing FIRST and FOLLOW sets for a grammar. Is there a simple algorithm or simple code for computing these? 回答1: The standard algorithm for computing FIRST and FOLLOW sets is discussed in most compiler textbooks and books on parsing algorithms. I would be