Introduce a C Compiler ucc

D

dreamAnders

ucc is an ANSI C Compiler. Its code size is about 15,000 lines.
The lexer, parser and code generator are all hand-written.
The code structure is very clear and straightforward. And there is an
interesting value numbering algorithm.
It also has a document explaining the internal implementation.
If you are interested at this compiler, you can download it from
http://sourceforge.net/projects/ucc, which will help you to master the
C language.
 
V

vippstar

ucc is an ANSI C Compiler. Its code size is about 15,000 lines.
The lexer, parser and code generator are all hand-written.
The code structure is very clear and straightforward. And there is an
interesting value numbering algorithm.
It also has a document explaining the internal implementation.
If you are interested at this compiler, you can download it fromhttp://sourceforge.net/projects/ucc, which will help you to master the
C language.

Your implementation of assert in ucc/ucl/linux/include/assert.h is not
ANSI C, (or ISO C) as it evaluates it's parameter more than once if
NDEBUG is not defined.
Example: assert(printf("hello world\n")); would call print twice.

I suggest you rewrite _assert (and also rename to _Assert) to return
void, and make the check twice there.
 
R

Robert Gamble

ucc is an ANSI C Compiler. Its code size is about 15,000 lines.
The lexer, parser and code generator are all hand-written.
The code structure is very clear and straightforward. And there is an
interesting value numbering algorithm.
It also has a document explaining the internal implementation.
If you are interested at this compiler, you can download it fromhttp://sourceforge.net/projects/ucc, which will help you to master the
C language.

At about 1 comment per 1000 lines of code it may be difficult to get
this adopted for "research and instructional use".
 
D

dreamAnders

Your implementation of assert in ucc/ucl/linux/include/assert.h is not
ANSI C, (or ISO C) as it evaluates it's parameter more than once if
NDEBUG is not defined.
Example: assert(printf("hello world\n")); would call print twice.

I suggest you rewrite _assert (and also rename to _Assert) to return
void, and make the check twice there.

No, It will not evaluate its parameter more than once.

#define assert(e) ((void)((e)||_assert(#e, __FILE__, __LINE__)))

please notice that the second e's appearance, it is '#e'
 
D

dreamAnders

yes, I accept this . Nearly no comments. I wanted to write this code
in a self-explanatory way. And I provide an internal implementation
document, hope that will help developers understanding the code.
 
D

Dan

dreamAnders said:
ucc is an ANSI C Compiler. Its code size is about 15,000 lines.
The lexer, parser and code generator are all hand-written.
The code structure is very clear and straightforward. And there is an
interesting value numbering algorithm.
It also has a document explaining the internal implementation.
If you are interested at this compiler, you can download it from
http://sourceforge.net/projects/ucc, which will help you to master the
C language.

Can it compile itself?
 
G

Gene

Can it compile itself?

From User's Manual:

(3) run make test, this will test if ucc can compile itself and run
successfully.
The command performs the following operations:
1) use ucc to build ucl, the output is named as ucl1
2) backup ucl under /usr/local/lib/ucc, copy ucl1 to this
directory and rename it to ucl
3) use ucc to build ucl again, the output is named as ucl2
4) run cmp /b ucl1 ucl2, these two files should be identical
 
R

Rui Maciel

ucc is an ANSI C Compiler. Its code size is about 15,000 lines. The
lexer, parser and code generator are all hand-written. The code
structure is very clear and straightforward. And there is an interesting
value numbering algorithm. It also has a document explaining the
internal implementation. If you are interested at this compiler, you can
download it from http://sourceforge.net/projects/ucc, which will help
you to master the C language.

Do you have a site dedicated to your project?


Rui Maciel
 
B

Bart

ucc is an ANSI C Compiler. Its code size is about 15,000 lines.
The lexer, parser and code generator are all hand-written.
The code structure is very clear and straightforward. And there is an
interesting value numbering algorithm.
It also has a document explaining the internal implementation.
If you are interested at this compiler, you can download it fromhttp://sourceforge.net/projects/ucc, which will help you to master the
C language.

As I understand it, this is just a bare compiler source code?

There are no binaries, so another compiler is needed to get started.

There appear to be no standard header files or library files,
presumably you are relying on these things from another compiler?
 
N

noagbodjivictor

ucc is an ANSI C Compiler. Its code size is about 15,000 lines.
The lexer, parser and code generator are all hand-written.
The code structure is very clear and straightforward. And there is an
interesting value numbering algorithm.
It also has a document explaining the internal implementation.
If you are interested at this compiler, you can download it fromhttp://sourceforge.net/projects/ucc, which will help you to master the
C language.

Congratulations. I hope this project will evolve quickly.
 
N

noagbodjivictor

Congratulations. I hope this project will evolve quickly.

Also, I don't really like the fact that one must have Ms Studio to
compile the compiler :) Can't you distribute binaries?
 
I

Ian Collins

dreamAnders said:
ucc is an ANSI C Compiler. Its code size is about 15,000 lines.
The lexer, parser and code generator are all hand-written.
The code structure is very clear and straightforward. And there is an
interesting value numbering algorithm.
It also has a document explaining the internal implementation.
If you are interested at this compiler, you can download it from
http://sourceforge.net/projects/ucc, which will help you to master the
C language.

Your files all have DOS line endings, not good for a cross platform project.
 
I

Ian Collins

Ian said:
Your files all have DOS line endings, not good for a cross platform project.
I see you also used unnamed unions in structs, which isn't standard.

You really should use standard C for a standard C compiler!
 
R

Richard Tobin

You really should use standard C for a standard C compiler!

Why? Would it be wrong to write a C compiler in, say, Lisp? The
considerations for what language or dialect to use for a C compiler
are no stricter than for any other project. In fact, they're less
strict, since so long as you support the extensions you use you can be
sure that there's a compiler that will compile it for the platforms
you support.

-- Richard
 
I

Ian Collins

Richard said:
Why? Would it be wrong to write a C compiler in, say, Lisp? The
considerations for what language or dialect to use for a C compiler
are no stricter than for any other project. In fact, they're less
strict, since so long as you support the extensions you use you can be
sure that there's a compiler that will compile it for the platforms
you support.
Why? Because one of the claims for the source was it "will help you to
master the C language."

Maybe that should read "will help you to master the gcc language." :)
 
R

Rui Maciel

Why? Would it be wrong to write a C compiler in, say, Lisp?

I believe that you've entirely missed the point. What was pointed out was
that the use of a non-standard extensions, which not only goes against
the objective that you set yourself to accomplish but also needlessly
screws things up for those who want to build it with any compiler that
doesn't support those non-standard extensions.


Rui Maciel
 
R

Richard Tobin

Ian Collins said:
Why? Because one of the claims for the source was it "will help you to
master the C language."

Fair enough, but you said something far more general:

-- Richard
 
D

dreamAnders

Also, I don't really like the fact that one must have Ms Studio to
compile the compiler :) Can't you distribute binaries?

Thanks. I am afraid that ucc is a stand-alone compiler. On Windows, It
rely on VC'header
files, library files, the preprocessor,assembler and linker. On Linux,
It rely on gcc
for that. So If I distribute binaries, users will find it cannot work.

I hope the project will evolve quickly. I need more help.
 
D

dreamAnders

Your files all have DOS line endings, not good for a cross platform project.

Thank you for your suggestion.

And yes, ucc supports anonymous union. Personally, I like anonymous
union so much,
and most compilers support it. So I want to support it too.
 
D

dreamAnders

Also, I don't really like the fact that one must have Ms Studio to
compile the compiler :) Can't you distribute binaries?

Thanks. I am afraid that ucc is not a stand-alone compiler. On
Windows, It
rely on VC'header files, library files, the preprocessor,assembler and
linker. On Linux, It rely on gcc for that. So If I distribute
binaries, users will find it cannot work.

I hope the project will evolve quickly. I need more help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top