compiler

How to code a compiler in C?

I am coding a compiler in C, and I have read all about compilers in the Dragon book. But I am finding it really hard to implement, and I have no clue as to where to start. Even when it comes to lexer part, so would love to know a step by step method on the basis of code writing to write a compiler in C!! What would you suggest I do nex...

Is this valid C++?

struct SomeStruct { int a; int b; }; SomeStruct someFn( int init ) { SomeStruct ret = { init, init }; //... return ret; } void someFn2( SomeStruct* pStruct ) { // .. } int main( ) { someFn2( &someFn(32) ); return 0; } ...

Using bison to parse list of elements

Hello, I'm writing a compiler for a shading engine and every worked fine until I reached the statements parsing part. I used an abstract syntax tree defined with classes to do all the work (to simplify typechecking and intermediate code generation).. so I have an ancestor class ASTNode and all descending classes like ASTFloat, ASTExpres...

Is there some place on the internet where I can run my Java program?

A program I am working on takes forever to complete (~3days, everytime). Is there some place on the internet where I can leave the code, some robot might run it for me and I can come back and collect the results? Some online judge that offers this capability? [I am not talking abt optimisations here.] ...

Does Solaris cc embed in an executable differing info for different compiles ?

G'day, This has been asked before for VC++ but I am interested in the answer for Solaris. I'm compiling and linking the following trivial C code: #include <stdio.h> int main() { printf("Hello world!\n"); return 0; } using the command: cc -o hello1 hello.c and doing this a couple of times to get executables hello2 and hel...

pointer arithmetic and the C# compiler

For the purpose of learning I recently looked at an existing assembly (using Reflector) that uses Win32 WriteFile. The implementation is: Write(IntPtr handleFile, void* bufferData, uint length){ void* buffer = bufferData while (length > 0) { uint wrtn; if (!WriteFile(handle, buffer, len, out wrtn, IntPtr.Zero)) { // Do some e...

Java Compilation date, like C __DATE__

I need to automate getting the compilation date in a specific format into one Java Source file, like the C compilers DATE define, How? ...

Why does the compiler find this ambiguous?

In my base class I have a generic method (ideally this would be a property, but you can't have generic properties) and a non-generic property, both with the same name: protected static T CurrentUserId<T>() { ... } protected static string CurrentUserId { get { ... } } However, when I come to use either of them ...

Can likely/unlikely macros be used in user-space code?

I came across these 2 macros in Linux kernel code. I know they are instructions to compiler (gcc) for optimizations in case of branching. My question is, can we use these macros in user space code? Will it give any optimization? Any example will be very helpful. ...

Compiler Magic: Why?

I just noticed that given the following code: if (x.ID > 0 && !x.IsCool) the Microsoft C# 3.0 (VS2008 SP1) compiler will optimize it to this: if (!((x.Id <= 0) || x. IsCool)) This is on Debug build without Optimization enabled. Why does the compiler do that? Is it faster in terms of execution? I used Reflector to find that out (I ...

C/C++ compiler feedback optimization

Has anyone seen any real world numbers for different programs which are using the feedback optimization that C/C++ compilres offer to support the branch prediction, cache preloading functions etc. I searched for it and amazingly not even the popular interpreter development groups seem to have checked the effect. And increasing ruby,py...

Visual studio 2005: is there a compiler option to initialize all stack-based variables to zero?

This question HAS had to be asked before, so it kills me to ask it again, but I can't find it for all of my google and searching stackoverflow. I'm porting a bunch of linux code to windows, and a good chunk of it makes the assumption that everything is automatically initialized to zero or null. int whatever; char* something; ...and...

Best open source project for learning about high-level domain-level compiler language?

I have tried to look for an open source project to learn about language domain level compiler to generate several languages such as Java , .Net platforms. For example, If I make my own grammars (it can be XML, XSD, or any type of grammar), after compiling it, it produces to java and .NET (c#) language files. any suggestion I appreciat...

Why are number suffixes necessary?

The C# language (and other languages I'm sure) require suffixes at the end of numeric literals. These suffixes indicate the type of the literal. For example, 5m is a decimal, 5f is a floating point number. My question is: are these suffixes really necessary, or is it possible to infer the type of a literal from its context? For example...

is there a way to look at the preprocessor expanded file in C

Hi i want to know how could we look at the c file after it has been expanded by the preprocessor before compilation with all the macro values put in the code inside the function where ever they are used. in there a way to do it? ...

Compiler optimization: Java bytecode

I'm currently writing a toy compiler targeting Java bytecode in the translation. I would like to know if there is some kind of catalog, maybe a summary, of various simple peephole optimizations that can be made in the emitted bytecode before writing the .class file. I actually am aware of some libraries that have this functionality, but...

How would you interpret this Compiler/Grammar homework question?

I'm working on my compiler homework and I have the following question: Consider the following grammar: lexp -> number : (op lexp-seq) op -> + | - | * lexp-seq -> lexp-seq lexp | lexp This grammar can be thought of as representing simple integer arithmetic expressions in LISP=like prefix form. For example the expression 34-3*4...

does argument in printf get located in memory?

in c, when I write: printf("result %d ",72 & 184); Does "72 & 184" get a a block in memory (for example 72 takes 4 bytes, 184 takes 4 bytes?...) ...

C++ compiler question- resolving name of a class member

When the compiler sees this code: SomeClass foo; int x = foo.bar; What is the process it goes about in retrieving the value of bar? I.e. does it look at some data structure representing the class definition? If so is this data structure generated at compile time or runtime? ...

Writing compilers ... what's right and what's wrong?

Okay, in my quest to figure out the necessary stuff to write a compiler, I've reached a bit of a roadblock. It seems that every technology or tool that I find has some opposition somewhere. I use Bison and Flex right now but I'm getting the feeling that this method is outdated. Is this true? Is this a good forward-compatible way to p...