GNU   davin.50webs.com/research
Bringing to you notes for the ages

Main Menu Research Projects Photo Album Curriculum Vitae The Greatest Artists
Email Address Computer Games Web Design Java Training Wheels The Fly (A Story)
Political Activism Bob Dylan Quotes+ My Life Story Smoking Cessation Other Links
Debugging Macros String Class I Linked List System I Java for C Programmers Naming Convention
String Class II How I use m4 Strings III Symmetrical I/O Linked Lists II
Run-Time Type Info Virtual Methods An Array System Science & Religion Submodes
Nested Packages Memory Leaks Garbage Collection Internet & Poverty What is Knowledge?
Limits of Evolution Emacs Additions Function Plotter Romantic Love The Next Big Thing
Science Fiction Faster Compilation Theory of Morality Elisp Scoping Elisp Advice
S.O.G.M. Pattern Safe Properties School Bullying Charisma Control Life and Death
Splitting Java Multiple Ctors Religious Beliefs Conversation 1 Conversation 2
J.T.W. Language Emacs Additions II Build Counter Relation Plotter Lisp++ Language
Memory Leaks II Super Constructors CRUD Implementation Order a Website Form There Is An Afterlife
More Occam's Razor C to Java Translator Theory of Morality II


A C to Java translator New Free Stuff

Under Construction
This page is under construction.

Abstract

This article presents a C to Java translator. Note that this research article has been abandoned by me as it is proved too difficult for me to execute.

1. Introduction

This C to Java translator is known by its shorter abbreviation: c2java. You can download the Java code for the c2java translator. This code is subject to the GNU General Public License. To build Java code from a C source file, first execute these commands from the folder that you downloaded c2java-1.21-20170702-140337.tar.gz to:


tar -xvf c2java-1.21-20170702-140337.tar.gz
cd c2java-1.21

Before you build the c2java translator, you might consider setting c2java-1.21/com/davinpearson/ByteCodeInterpreter.java’s variable debug variable to false (for no debug information). The Makefile takes one argument STUMP and for a C file such as A0.c the Makefile invocation should be without the .c extension like so:

make default STUMP=A0
  
This will build, in order:
  1. A0.cpp is the code after running the C pre-processor on A0.c
  2. A0.cpp2 is the code after culling the system #include directives from A0.cpp
  3. A0.glued is the code after gluing adjacent strings in A0.cpp2 to one another.
  4. A0.c2j is the byte-code for interpreting.
  5. Then the byte code interpreter com.davinpearson.ByteCodeInterpreter is run on A0.glued and A0.c2j.

To invoke the byte code interpreter separately, issue the following Makefile target from the folder c2java-1.21:

make clean com/davinpearson/ByteCodeInterpreter.jrun ARGS=A0
  

To simply build the byte code file A0.c2j and the glued file A0.glued, issue the following Makefile target: from the folder c2java-1.21:

make clean A0.c2j
  

If you are not touching the files c2java-1.21/*.java, c2java-1.21/com/davinpearson/*.java, c2java-1.21/com/davinpearson/expr/*.java and c2java-1.21/com/davinpearson/stmt/*.java then the Makefile invocation can be without the ‘‘clean’’ target like so:

make com/davinpearson/ByteCodeInterpreter.jrun ARGS=A0
  
and
make A0.c2j

respectively.

2. Running the test files

To build c2java-1.21/A*.c (all of the tester module C source files) into c2java, simply issue the following Makefile commands from the folder c2java-1.21:


make jbuild
make jbuild2

The first command builds files A0.c, A1.c, A2.c ... A29.c. The second command builds files A30.c, A31.c, A32.c ... A59.c. To build and execute a C source file such as A0.c using the C compiler and linker, issue the following Makefile command from the folder c2java-1.21:

make A0.crun
  

Note that you will need to uncomment the lines that say ‘‘//#define strobe(x)’’ for the code to compile. These lines should be commented out if you want to build a Java interpreter for the C code. To build and execute all of the tester module C source files like A*.c using the C compiler and linker, issue the following Makefile command from the folder c2java-1.21:

make cbuild
  

3. Include files

The package c2java now supports include files, but not linking across multiple object files. You must #include all of your code from the main file being compiled. Figure 1 of the following diagram shows the situation using a C compiler and linker and Figure 2 of the following diagram shows the situation with c2java:



c2java file inclusion


In the above diagram, you have three source code files: a.c, b.c and c.c. They are compiled to produce the object files a.o, b.o and c.o, before linking them together to produce an executable called for argument's sake foo.exe. Also there are three header files a.h, b.h and c.h. On the right hand side of the above diagram the C source files have been renamed from *.c to *.ch and the three source files are #included by a file called for argument's sake global.c. The c2java translator is then run on global.c to produce output files global.glued and global.c2j suitable for interpretation by the Java byte code interpreter com.davinpearson.ByteCodeInterpreter.

4. Supported libc functions

Currently the only built-in functions from the built-in C standard library libc you can call are as follows:

Other functions will be added as time progresses.

5. Limitations of c2java



Back to Research Projects
This page has the following hit count:
| Main Menu | Research Projects | Photo Album | Curriculum Vitae | The Greatest Artists |
| Email Address | Computer Games | Web Design | Java Training Wheels | The Fly (A Story) |
| Political Activism | Bob Dylan Quotes+ | My Life Story | Smoking Cessation | Other Links |
| Debugging Macros | String Class I | Linked List System I | Java for C Programmers | Naming Convention |
| String Class II | How I use m4 | Strings III | Symmetrical I/O | Linked Lists II |
| Run-Time Type Info | Virtual Methods | An Array System | Science & Religion | Submodes |
| Nested Packages | Memory Leaks | Garbage Collection | Internet & Poverty | What is Knowledge? |
| Limits of Evolution | Emacs Additions | Function Plotter | Romantic Love | The Next Big Thing |
| Science Fiction | Faster Compilation | Theory of Morality | Elisp Scoping | Elisp Advice |
| S.O.G.M. Pattern | Safe Properties | School Bullying | Charisma Control | Life and Death |
| Splitting Java | Multiple Ctors | Religious Beliefs | Conversation 1 | Conversation 2 |
| J.T.W. Language | Emacs Additions II | Build Counter | Relation Plotter | Lisp++ Language |
| Memory Leaks II | Super Constructors | CRUD Implementation | Order a Website Form | There Is An Afterlife |
| More Occam's Razor | C to Java Translator | Theory of Morality II
Last modified: Thu Jan 16 19:42:50 NZDT 2020
Best viewed at 800x600 or above resolution.
© Copyright 1999-2020 Davin Pearson.
Please report any broken links to