Skip to content

Q-Taro/CompilerCompiler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CompilerCompiler

Self Extendable Compiler Compiler

comcom.h is header file , and it contains main() func. t0.def is the definition of THIS Compiler Compiler. t3.out.c is the C source code of THIS Compiler Compiler.


How to use this software.

$ gcc t3.out.c
$ ./a.out t0.def t4.out.c
then, t4.out.c is generated. t4.out.c is exactly same as t3.out.c .

What is t3.out.c

a.out generated from t3.out.c is a Compiler Compier. So, you can use this a.out as a yacc/bison.

You can also generate a new Compiler by this a.out.

One of the souce code of the a.out is t0.def. t0.def is the definition of the self extendable compiler compiler. So, the a.out can generate the same source code of a.out by using t0.def .
1. t0.def is the definition of the self extendable compiler compiler.
2. The executable code from the t0.def is a.out.
3. a.out is a compiler compiler like a yacc/bison.
4. a.out can generate a C source code by using t0.def.
5. And that C code is the source code of a.out !!
6. You can design a new Compiler by using a.out.

Example "THIS IS A PEN Analyzer"

"THIS IS A PEN Analyzer" can analyze a text file contains "THIS IS A PEN" text string or not.

The definition of this analyzer is sample.def.

START(SAMPLE)
SAMPLE : THIS IS "A" PEN {
		call(1);
		call(2);
		call(3);
		print("finish!"); 
	}
;
THIS	: "THIS" 	{ print("-this-"); }
	| "THAT"	{ print("-that-"); }
;

IS	: "IS" 		{ print("-is-");}
	| "ARE"		{ print("-are-");}
;
PEN	: "PEN" 	{ print("-pen-");}
	| "PENCIL"	{ print("-pencil-");}
;

END
$ ./a.out sample.def sample.c
$ gcc -o sample sample.c

Now, you should make a definition file .

$ cat user.txt
THIS IS A PENCIL

$ ./sample user.txt user.out
$ cat user.out
-this--is--pen-finish!

Enjoy.

About

Self Extendable Compiler Compiler

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages