207 lines
5.8 KiB
Plaintext
207 lines
5.8 KiB
Plaintext
|
|
/*
|
|
===========================================================================
|
|
|
|
MAKEFILE STUFF
|
|
|
|
===========================================================================
|
|
*/
|
|
|
|
Das Projekt wurde in 4 Teilprojekte aufgeteilt:
|
|
|
|
- Automat
|
|
- Buffer
|
|
- Symboltabelle
|
|
|
|
- Scanner
|
|
|
|
|
|
Jedes Teilprojekt hat die Verzeichnisstruktur:
|
|
- debug enthaelt Objektfiles zum Testen
|
|
- lib enthaelt Objektfiles zum Erstellen der shared library des Teilprojekts
|
|
- src enthaelt den Source-Code
|
|
|
|
jedes Teilprojekt enthaelt ein eigenes Makefile und eine eigene Main-Klasse, um die Funktionalitaet zu testen.
|
|
|
|
Level: ohne Makefile Kenntnisse
|
|
Im Makefile im Teilprojekt Automat sind alle Schritte zum Compilieren und Linken ausfuehrlich aufgelistet.
|
|
|
|
|
|
Level: wenig Makefile-Kenntnisse
|
|
Im Makefile im Teilprojekt Buffer werden die benoetigten Verzeichnisse ueber Variablen definiert.
|
|
|
|
|
|
Level: gute Makefile-Kenntnisse
|
|
Im Makefile im Teilprojekt Symboltabelle und Scanner wird auch die Liste der Abhaengigkeiten ueber Variablen deklariert
|
|
Aufbau des Makefiles:
|
|
Definition der Variablen
|
|
Targets zum Bauen des Tests
|
|
Targets zum Erstellen der shared library
|
|
|
|
|
|
|
|
Das Makefile im obersten Projekt-Verzeichnis loescht alle shared libraries und erstellt alle neu.
|
|
|
|
|
|
In der View "Make Targets" erscheinen die Targets der einzelnen Makefiles, die dann mit einem Doppelklick ausgefuehrt werden können.
|
|
|
|
|
|
Aufbau der Targets
|
|
|
|
# target: dependencies
|
|
# [tab] system_command
|
|
|
|
|
|
# Compilation commands:
|
|
# classA.o: classA.cpp
|
|
# [tab] g++ -c classA.cpp -o classA.o
|
|
|
|
# classB.o: classB.cpp
|
|
# [tab] g++ -c classB.cpp -o classB.o
|
|
|
|
|
|
# Link command:
|
|
# my_program: classA.o classB.o
|
|
# [tab] c++ classA.o classB.o -o my_program
|
|
|
|
# options:
|
|
# -c Kompilieren ohne zu linken.
|
|
# -g debugging infos erzeugen
|
|
# -o file object-file file erzeugen
|
|
#
|
|
# -fPIC position independant code wichtig für shared library
|
|
|
|
Zum Ausfuehren der Programme muss der LD_LIBRARY_PATH noch folgendermaßen gesetzt werden:
|
|
m Eclipse workspace unter Project --> Properties --> Run / Debug Settings --> Environment --> Select --> LD_LIBRARY_PATH --> ok
|
|
|
|
den Eintrag LD_LIBRARY_PATH auswählen --> edit
|
|
den Pfad zum Verzeichnis der shared library an das Ende anhängen, trennen mit ;
|
|
|
|
|
|
http://www.sethi.org/classes/cet375/lab_notes/lab_04_makefile_and_compilation.html
|
|
|
|
http://mrbook.org/tutorials/make/
|
|
|
|
|
|
|
|
/*
|
|
===========================================================================
|
|
|
|
INTERFACE DESIGN
|
|
|
|
===========================================================================
|
|
*/
|
|
|
|
Scanner
|
|
=======
|
|
|
|
Task:
|
|
|
|
Communicates with all parties to produce a token on each step.
|
|
It is the major interface to parser.
|
|
|
|
Interface IN:
|
|
|
|
token Scanner::nextToken() // returns a token with all neccessary info to the parser until EOF
|
|
|
|
Interface OUT:
|
|
|
|
char Buffer::getChar( void ) // buffer returns next char
|
|
void Buffer::ungetChar( int len ) // buffer ungets char for amount of len
|
|
char *Buffer::getLexem( void ) // buffer returns pointer to current lexem (null terminated, c_string style TODO see end of this file for more)
|
|
int Buffer::getColumn( void ) // buffer returns current column
|
|
int Buffer::getLine( void ) // buffer returns current line
|
|
void Buffer::setNewLexem( void ) // informs buffer that a new lexem is about to be scanned
|
|
bool Automaton::readChar( char ch ) // bool indicates the scanner that the automaton has recognized a token and it can be caught by the scanner
|
|
tokentype Automaton::getTokenType( void ) // returns last recognized tokentype to scanner
|
|
int Automaton::getBack( void ) // returns back variable which indicates to scanner how many chars it needs to instruct buffer to ungetChar()
|
|
|
|
Buffer
|
|
======
|
|
|
|
Task:
|
|
|
|
Service provider to Scanner. Concerned with reading in and buffering input
|
|
file and lexem info. It records current parsed lexem, its column and row info.
|
|
It also indicates EOF. Is controlled by scanner.
|
|
|
|
Interface IN:
|
|
|
|
char Buffer::getChar( void ) // buffer returns next char
|
|
void Buffer::ungetChar( int len ) // buffer ungets char for amount of len
|
|
char *Buffer::getLexem( void ) // buffer returns pointer to current lexem (null terminated, c_string style TODO see end of this file for more)
|
|
int Buffer::getColumn( void ) // buffer returns current Column
|
|
int Buffer::getRow( void ) // buffer returns current row
|
|
void Buffer::setNewLexem( void ) // informs buffer that a new lexem is about to be scanned
|
|
|
|
Interface OUT:
|
|
|
|
<none>, maybe the low-level read functions to OS, when constructor is called
|
|
and it reads in the input file.
|
|
|
|
Automaton
|
|
=========
|
|
|
|
Task:
|
|
|
|
Service provider to Scanner. Accepts lexemes from source language as defined in
|
|
SysprogI.pdf page 41. Indicates which tokentype a lexeme belongs to and outputs
|
|
last recognized token type to scanner.
|
|
|
|
Interface IN:
|
|
|
|
bool Automaton::readChar( char ch ) // bool indicates the scanner that the automaton has recognized a token and it can be caught by the scanner
|
|
tokentype Automaton::getTokenType( void ) // returns last recognized tokentype to scanner
|
|
int Automaton::getBack( void ) // returns back variable which indicates to scanner how many chars it needs to instruct buffer to ungetChar()
|
|
|
|
Interface OUT:
|
|
|
|
<none>
|
|
|
|
Symboltable
|
|
===========
|
|
|
|
Task:
|
|
|
|
Service provider to Scanner. Store every variable with each one's value and
|
|
can return it when asked by the scanner
|
|
|
|
Interface IN:
|
|
|
|
void Symboltable::setIdentifier(string name, int value)
|
|
bool Symboltable::identifierExists(string name)
|
|
int Symboltable::getValue(string name)
|
|
|
|
Interface OUT:
|
|
|
|
int Symboltable::hash([string|int|...] seed) // TODO choose the seed
|
|
|
|
|
|
Coding Conventions:
|
|
===================
|
|
|
|
int function
|
|
{
|
|
if() {
|
|
} else {
|
|
}
|
|
|
|
for() {
|
|
}
|
|
|
|
while() {
|
|
}
|
|
}
|
|
|
|
// tab = 4 spaces
|
|
// text width = 80
|
|
|
|
TODO
|
|
====
|
|
|
|
- ask if we are allowed to use #include <string>, if so we might change buffer interface from * char to string
|
|
(see page 2)
|
|
- symboltable
|
|
- public header for parser
|
|
|