simplec 1.0d1 - demonstration of compiler construction

This is free software. See enclosed LICENSE file for full licensing terms.

simplec demonstrates the use of yacc (bison) and lex (flex) to construct a basic compiler using C and C++.

Download Link: simplec-1.0.tar.gz

-Andrew Tomazos <andrew@tomazos.com>

The grammar of the simplec language is as follows:

CompilationUnit:
	(Statement ';')+   # a compilation unit conists of
					   # semi-colon seperated statements

Statement:
	LocalVarDecl       # declare a variable: int a;
	Assignment		   # assign a variable: a = b;
	ScanStmt		   # read input into variable: scan a;
	PrintStmt          # print out a variable: print a;

LocalVarDecl:
	"int" Identifier
	
PrintStmt:
	"print" Identifier

ScanStmt:
	"scan" Identifier

Assignment:
	Identifier "=" Expression

Expression:
	Identifier
	Number
	"(" Expression ")"
	Expression Operator Expression
	"-" Expression					# negation

Operator:
	"+" | "-" | "*" | "/"

To create the compiler, call make:

	$ cd simplec-1.0
	$ make

This will compile everything into an executable called "simplec" and then will perform a test. Ideally you should see "test passed".

To use the resulting "simplec", write a program with the above grammar. (See "test_program" for an example). Save it to a file "my_program" and then execute it as follows:

	$ simplec my_program

Standard input is used for scan statements, standard output is used for print statements. They can be redirected.

To execute the included test manually do the following:

	$ simplec test_program < test_input > test_output
	$ diff test_output test_expected

Have fun,
Andrew.

Up to Andrew Tomazos Home Page