compiler-construction

Abstract Method in Non Abstract Class

≡放荡痞女 提交于 2021-02-04 09:18:24
问题 I want to know the reason behind the design of restricting Abstract Methods in Non Abstract Class (in C#). I understand that the class instance won't have the definition and thus they wont be callable, but when static methods are defined,they are excluded from the instance too. Why abstract methods are not handled that way, any specific reason for the same? They could be allowed in concrete class and the deriving class can be forced to implement methods, basically that is what, is done in

Eclipse CDT Inclusion problems

白昼怎懂夜的黑 提交于 2021-01-29 20:07:56
问题 I just installed Eclipse CDT. Now, Eclipse works fine for me with Java, but it's not working at all with C. I'm trying to write a simple Hello World program, and I've even loaded the Hello World ANSI premade project. However, regardless of what I do, I get a "Unresolved Inclusion: _ " error on all my #include. I've looked around for half an hour trying to figure out why, installed MiniGW and tried a ton of different configurations. Can someone tell me how to fix this? I'm guessing it's

Remove needless assembler statements from g++ output

橙三吉。 提交于 2021-01-29 14:31:16
问题 I am investigating some problem with a local binary. I've noticed that g++ creates a lot of ASM output that seems unnecessary to me. Example with -O0 : Derived::Derived(): pushq %rbp movq %rsp, %rbp subq $16, %rsp <--- just need 8 bytes for the movq to -8(%rbp), why -16? movq %rdi, -8(%rbp) movq -8(%rbp), %rax movq %rax, %rdi <--- now we have moved rdi onto itself. call Base::Base() leaq 16+vtable for Derived(%rip), %rdx movq -8(%rbp), %rax <--- effectively %edi, does not point into this area

Ply shift/reduce conflicts: dangling else and empty productions

笑着哭i 提交于 2021-01-29 08:46:34
问题 I had lots of conflicts, most of them were due to operators and relational operators which had different precedences. But I still face some conflicts that I don't really know how to tackle them. some of them are below. I suspect that maybe I should do epsilon elimination for stmtlist but to be honest I'm not sure about it. state 70: state 70 (27) block -> LCB varlist . stmtlist RCB (25) varlist -> varlist . vardec (28) stmtlist -> . stmt (29) stmtlist -> . stmtlist stmt (30) stmtlist -> . (15

Efficient use of boolean true and false in C++?

对着背影说爱祢 提交于 2021-01-28 21:43:53
问题 Would any compiler experts be able to comment on the efficient use of boolean values? Specifically, is the compiler able to optimize a std::vector<boolean> to use minimal memory? Is there an equivalent data structure that would? Back in the day, there were languages that had compilers that could compress an array of booleans to a representation of just one bit per boolean value. Perhaps the best that could be done for C++ is to use std::vector<char> to store the boolean values for minimal

Efficient use of boolean true and false in C++?

廉价感情. 提交于 2021-01-28 21:06:39
问题 Would any compiler experts be able to comment on the efficient use of boolean values? Specifically, is the compiler able to optimize a std::vector<boolean> to use minimal memory? Is there an equivalent data structure that would? Back in the day, there were languages that had compilers that could compress an array of booleans to a representation of just one bit per boolean value. Perhaps the best that could be done for C++ is to use std::vector<char> to store the boolean values for minimal

How to reduce parser stack or 'unshift' the current token depending on what follows?

江枫思渺然 提交于 2021-01-28 17:43:30
问题 Given the following language described as: formally: (identifier operator identifier+)* in plain English: zero or more operations written as an identifier (the lvalue), then an operator, then one or more identifiers (the rvalue) An example of a sequence of operations in that language would be, given the arbitrary operator @ : A @ B C X @ Y Whitespace is not significant and it may also be written more clearly as: A @ B C X @ Y How would you parse this with a yacc-like LALR parser ? What I

Get compiler generated delegate for an event

别来无恙 提交于 2021-01-28 14:49:48
问题 I need to know what handlers are subsribed to the CollectionChanged event of the ObservableCollection class. The only solution I found would be to use Delegate.GetInvocationList() on the delegate of the event. The problem is, I can't get Reflection to find the compiler generated delegate. AFAIK the delegate has the same name as the event. I used the following piece of code: PropertyInfo notifyCollectionChangedDelegate = collection.GetType().GetProperty("CollectionChanged", BindingFlags

how to write a Python debugger/editor

本小妞迷上赌 提交于 2021-01-28 08:53:59
问题 Sorry for the kind of general question. More details about what I want: I want the user to be able to write some Python code and execute it. Once there is an exception which is not handled, I want the debugger to pause the execution, show information about the current state/environment/stack/exception and make it possible to edit the code . I only want to have the special code block editable where the exception occurred and nothing else (for now). I.e. if it occurred inside a for loop, I only

How to read multiple lines of input in lex and yacc?

落爺英雄遲暮 提交于 2021-01-28 02:10:20
问题 I want the output as: a=3 mov a,3 a=fs mov b,fs b=32 mov b,32 Program for 3 address intermediate code generation - the lex file written for lexical analysis reads the input from command line and passes tokens: %{ #include "y.tab.h" #include "string.h" #include <math.h> %} %% [a-zA-Z]+ { yylval.var=(char *)malloc(sizeof(char *)); strcpy(yylval.var,yytext); return ID;} "=" return EQUALS; [0-9]+ {yylval.num=atoi(yytext);return DIGIT;} %% The corresponding yacc file: %{ #include "stdio.h"