Restucture the whole project!
Every header file is now in the includes folder: easier to find, and easier to include For example: we don't need to include some shit like that: "../../includes/local.h" with aweful relative paths By the way, local.h wasn't explicit at all, so lot of code has moved to a more explicit file: Token.[h|cpp] and so on... I STRONGLY RECOMMAND READING THE LOGS FOR THIS COMMIT!
This commit is contained in:
parent
04a80e8ec5
commit
6381f30b06
|
@ -7,7 +7,9 @@
|
|||
# -g --> debug Informationen erzeugen
|
||||
# -o --> name des output-files
|
||||
|
||||
FLAGS=-g -Wall -Werror -ansi -pedantic
|
||||
INCLUDES = ../includes
|
||||
|
||||
FLAGS=-g -Wall -Werror -ansi -pedantic -I$(INCLUDES)
|
||||
|
||||
makeTestAutomat: AutomatTarget TestAutomatTarget
|
||||
g++ $(FLAGS) debug/Automat.o debug/TestAutomat.o -o debug/AutomatTest
|
||||
|
@ -19,12 +21,12 @@ makeTestAutomat: AutomatTarget TestAutomatTarget
|
|||
# -c --> compilieren
|
||||
# -Wall --> alle meldungen erzeugen
|
||||
|
||||
AutomatTarget : src/Automat.cpp src/Automat.h
|
||||
AutomatTarget : src/Automat.cpp $(INCLUDES)/Automat.h
|
||||
g++ $(FLAGS) -c src/Automat.cpp -o debug/Automat.o
|
||||
|
||||
|
||||
# TestAutomat.o ist abhängig von src/TestAutomat.cpp und src/Automat.h
|
||||
TestAutomatTarget : src/TestAutomat.cpp src/Automat.h
|
||||
TestAutomatTarget : src/TestAutomat.cpp $(INCLUDES)/Automat.h
|
||||
g++ $(FLAGS) -c -Wall src/TestAutomat.cpp -o debug/TestAutomat.o
|
||||
|
||||
|
||||
|
@ -46,7 +48,7 @@ AutomatLib: AutomatLibTarget
|
|||
|
||||
|
||||
# compilieren des Files Automat.cpp zu Automat.o mit dem Flag -fPIC (Position Independant Code)
|
||||
AutomatLibTarget : src/Automat.cpp src/Automat.h
|
||||
AutomatLibTarget : src/Automat.cpp $(INCLUDES)/Automat.h
|
||||
g++ $(FLAGS) -c -fPIC src/Automat.cpp -o lib/Automat.o
|
||||
|
||||
|
||||
|
|
|
@ -11,8 +11,7 @@
|
|||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "../../includes/local.h"
|
||||
#include "Automat.h"
|
||||
#include <Automat.h>
|
||||
|
||||
void printTokenType(TokenType t)
|
||||
{
|
||||
|
|
|
@ -9,7 +9,9 @@ LIBDIR = lib
|
|||
|
||||
SHAREDLIB = ../sharedlib
|
||||
|
||||
FLAGS=-g -Wall -Werror -ansi -pedantic
|
||||
INCLUDES = ../includes
|
||||
|
||||
FLAGS=-g -Wall -Werror -ansi -pedantic -I$(INCLUDES)
|
||||
|
||||
#
|
||||
# Targets zum Bauen des Tests
|
||||
|
@ -23,11 +25,11 @@ makeTestBuffer: BufferTarget TestBufferTarget
|
|||
|
||||
# compilieren der Source-files
|
||||
# Buffer.o ist abhaengig von Buffer.cpp und Buffer.h
|
||||
BufferTarget : $(SRCDIR)/Buffer.cpp $(SRCDIR)/Buffer.h
|
||||
BufferTarget : $(SRCDIR)/Buffer.cpp $(INCLUDES)/Buffer.h
|
||||
g++ $(FLAGS) -c -o $(OBJDIR)/Buffer.o $(SRCDIR)/Buffer.cpp
|
||||
|
||||
#TestBuffer.o ist abhaengig von TestBuffer.cpp und Buffer.h
|
||||
TestBufferTarget : $(SRCDIR)/TestBuffer.cpp $(SRCDIR)/Buffer.h
|
||||
TestBufferTarget : $(SRCDIR)/TestBuffer.cpp $(INCLUDES)/Buffer.h
|
||||
@echo "g++ $*.cpp"
|
||||
g++ $(FLAGS) -c -o $(OBJDIR)/TestBuffer.o $(SRCDIR)/TestBuffer.cpp
|
||||
|
||||
|
@ -50,7 +52,7 @@ BufferLib: BufferLibTarget
|
|||
g++ -shared -o $(SHAREDLIB)/libBuffer.so $(LIBDIR)/Buffer.o
|
||||
|
||||
|
||||
BufferLibTarget : $(SRCDIR)/Buffer.cpp $(SRCDIR)/Buffer.h
|
||||
BufferLibTarget : $(SRCDIR)/Buffer.cpp $(INCLUDES)/Buffer.h
|
||||
g++ $(FLAGS) -c -fPIC -o $(LIBDIR)/Buffer.o $(SRCDIR)/Buffer.cpp
|
||||
|
||||
|
||||
|
|
Binary file not shown.
|
@ -10,7 +10,9 @@ LIBDIR = lib
|
|||
|
||||
SHAREDLIB = ../sharedlib
|
||||
|
||||
FLAGS=-g -Wall -Werror -ansi -pedantic
|
||||
INCLUDES = ../includes
|
||||
|
||||
FLAGS=-g -Wall -Werror -ansi -pedantic -I$(INCLUDES)
|
||||
|
||||
## hier alle Object Files eintragen
|
||||
## darauf achten, dass letzte Zeile ohne "\" eingetragen wird
|
||||
|
@ -54,7 +56,7 @@ makeTestParser: $(OBJS)
|
|||
list: $(SRCDIR)/list.cpp $(SRCDIR)/TestList.cpp
|
||||
g++ $(FLAGS) $^ -o $(BINDIR)/ListTest
|
||||
|
||||
listLib: $(SRCDIR)/list.cpp $(SRCDIR)/TestList.cpp
|
||||
listLib: $(SRCDIR)/list.cpp
|
||||
g++ $(FLAGS) -fPIC $^ -shared -o $(SHAREDLIB)/libList.so
|
||||
|
||||
run:
|
||||
|
|
|
@ -8,7 +8,8 @@
|
|||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include "Parser.h"
|
||||
#include <Parser.h>
|
||||
#include <TList.h>
|
||||
|
||||
|
||||
void printTokenType( TokenType t );
|
||||
|
@ -44,7 +45,7 @@ bool Parser::decls()
|
|||
}
|
||||
it = l->head();
|
||||
while (it != NULL) {
|
||||
printTokenType ( (TokenType)(((Token*)it->v)->getTokenType()) );
|
||||
printTokenType ( (it->t->getTokenType()) );
|
||||
it = it->n;
|
||||
}
|
||||
if (l->getSize() >= max || (finished = !decl(l))) {
|
||||
|
@ -77,83 +78,3 @@ bool Parser::array(List *l)
|
|||
|
||||
|
||||
|
||||
void printTokenType( TokenType t )
|
||||
{
|
||||
std::cout << t << std::endl;
|
||||
switch(t) {
|
||||
case T_PLUS:
|
||||
std::cout << "Token Plus \n";
|
||||
break;
|
||||
case T_MINUS:
|
||||
std::cout << "Token Minus \n";
|
||||
break;
|
||||
case T_DIVIDE:
|
||||
std::cout << "Token Divide \n";
|
||||
break;
|
||||
case T_MULTI:
|
||||
std::cout << "Token Multi \n";
|
||||
break;
|
||||
case T_LESSTHAN:
|
||||
std::cout << "Token LessThan \n";
|
||||
break;
|
||||
case T_MORETHAN:
|
||||
std::cout << "Token MoreThan \n";
|
||||
break;
|
||||
case T_ASSIGN:
|
||||
std::cout << "Token Assign \n";
|
||||
break;
|
||||
case T_EQUAL:
|
||||
std::cout << "Token Equal \n";
|
||||
break;
|
||||
case T_UNEQUAL:
|
||||
std::cout << "Token Unequal \n";
|
||||
break;
|
||||
case T_EXCLAMATION:
|
||||
std::cout << "Token Exclamation \n";
|
||||
break;
|
||||
case T_AND:
|
||||
std::cout << "Token And \n";
|
||||
break;
|
||||
case T_SEMICOLON:
|
||||
std::cout << "Token Semicolon \n";
|
||||
break;
|
||||
case T_LPARENT:
|
||||
std::cout << "Token LPar \n";
|
||||
break;
|
||||
case T_RPARENT:
|
||||
std::cout << "Token RPar \n";
|
||||
break;
|
||||
case T_LBRACKET:
|
||||
std::cout << "Token LBrack \n";
|
||||
break;
|
||||
case T_RBRACKET:
|
||||
std::cout << "Token RBrack \n";
|
||||
break;
|
||||
case T_LBRACE:
|
||||
std::cout << "Token LBrace \n";
|
||||
break;
|
||||
case T_RBRACE:
|
||||
std::cout << "Token RBrace \n";
|
||||
break;
|
||||
case T_INTEGER:
|
||||
std::cout << "Token Integer \n";
|
||||
break;
|
||||
case T_IF:
|
||||
std::cout << "Token If \n";
|
||||
break;
|
||||
case T_WHILE:
|
||||
std::cout << "Token While \n";
|
||||
break;
|
||||
case T_IDENTIFIER:
|
||||
std::cout << "Token Identifier \n";
|
||||
break;
|
||||
case T_END:
|
||||
std::cout << "Token End \n";
|
||||
break;
|
||||
default:
|
||||
std::cout << "Token Unknown \n";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
#include <iostream>
|
||||
#include <stdlib.h>
|
||||
#include "list.h"
|
||||
#include <TList.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include "Parser.h"
|
||||
#include "../../includes/local.h"
|
||||
#include <Parser.h>
|
||||
#include <Token.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#include "list.h"
|
||||
#include <TList.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
@ -20,10 +20,10 @@ int List::getSize()
|
|||
return m_size;
|
||||
}
|
||||
|
||||
void List::add(void *data)
|
||||
void List::add(Token *data)
|
||||
{
|
||||
LItem *i = (LItem*) malloc(sizeof(LItem));
|
||||
i->v = data;
|
||||
i->t = data;
|
||||
i->n = m_head;
|
||||
i->p = NULL;
|
||||
if (m_head != NULL) {
|
||||
|
@ -36,10 +36,10 @@ void List::add(void *data)
|
|||
m_size++;
|
||||
}
|
||||
|
||||
void List::push(void *data)
|
||||
void List::push(Token *data)
|
||||
{
|
||||
LItem *i = (LItem*) malloc(sizeof(LItem));
|
||||
i->v = data;
|
||||
i->t = data;
|
||||
i->n = NULL;
|
||||
i->p = m_tail;
|
||||
if (m_tail != NULL) {
|
||||
|
@ -52,12 +52,12 @@ void List::push(void *data)
|
|||
m_size++;
|
||||
}
|
||||
|
||||
void *List::rem()
|
||||
Token *List::rem()
|
||||
{
|
||||
LItem *i = m_head;
|
||||
void *d = NULL;
|
||||
Token *d = NULL;
|
||||
if (m_head != NULL) {
|
||||
d = i->v;
|
||||
d = i->t;
|
||||
if (m_head->n != NULL)
|
||||
m_head->n->p = NULL;
|
||||
m_head = m_head->n;
|
||||
|
@ -67,12 +67,12 @@ void *List::rem()
|
|||
return d;
|
||||
}
|
||||
|
||||
void *List::pop()
|
||||
Token *List::pop()
|
||||
{
|
||||
LItem *i = m_tail;
|
||||
void *d = NULL;
|
||||
Token *d = NULL;
|
||||
if (m_tail != NULL) {
|
||||
d = i->v;
|
||||
d = i->t;
|
||||
if (m_tail->p != NULL)
|
||||
m_tail->p->n = NULL;
|
||||
m_tail = m_tail->p;
|
||||
|
@ -84,8 +84,8 @@ void *List::pop()
|
|||
|
||||
void List::clean()
|
||||
{
|
||||
void *d = NULL;
|
||||
Token *d = NULL;
|
||||
while ((d = rem()) != NULL)
|
||||
free(d);
|
||||
delete d;
|
||||
m_head = m_tail = NULL;
|
||||
}
|
||||
|
|
|
@ -7,25 +7,22 @@ BINDIR = debug
|
|||
|
||||
LIBDIR = lib
|
||||
|
||||
|
||||
SHAREDLIB = ../sharedlib
|
||||
|
||||
FLAGS=-g -Wall -Werror -ansi -pedantic
|
||||
INCLUDES = ../includes
|
||||
|
||||
FLAGS=-g -Wall -Werror -ansi -pedantic -I$(INCLUDES)
|
||||
|
||||
## hier alle Object Files eintragen
|
||||
## darauf achten, dass letzte Zeile ohne "\" eingetragen wird
|
||||
|
||||
OBJS = $(OBJDIR)/Scanner.o \
|
||||
$(OBJDIR)/TestScanner.o
|
||||
$(OBJDIR)/TestScanner.o \
|
||||
$(OBJDIR)/Token.o
|
||||
|
||||
#$(OBJDIR)/xx1.o \
|
||||
#$(OBJDIR)/xxn.o
|
||||
|
||||
OBJSFORSCANNERLIB = \
|
||||
$(LIBDIR)/Scanner.o
|
||||
|
||||
|
||||
|
||||
# Variante mit wenig Makefile-Kenntnissen
|
||||
|
||||
# linken der Object-files under shared libraries
|
||||
|
@ -71,21 +68,3 @@ cleanScanner:
|
|||
$(MAKE) makeTestScanner
|
||||
|
||||
|
||||
|
||||
## erstellen der shared library
|
||||
|
||||
# erst wichtig fuer den Parser Teil
|
||||
#
|
||||
ScannerLib:$(OBJSFORSCANNERLIB)
|
||||
g++ -shared -o $(SHAREDLIB)/libScanner.so $^
|
||||
#
|
||||
#
|
||||
#$(LIBDIR)/%.o : $(SRCDIR)/%.cpp
|
||||
## @mkdir -p `dirname $(OBJDIR)/$*.o`
|
||||
# @echo "g++ $*.cpp"
|
||||
# g++ -g -c -fPIC -o $@ $<
|
||||
|
||||
ScannerLibTarget : $(SRCDIR)/Scanner.cpp $(SRCDIR)/Scanner.h
|
||||
g++ $(FLAGS) -c -fPIC -o $(LIBDIR)/Scanner.o $(SRCDIR)/Scanner.cpp
|
||||
|
||||
|
||||
|
|
|
@ -8,107 +8,8 @@
|
|||
* Author: mino
|
||||
*/
|
||||
|
||||
#include "Scanner.h"
|
||||
|
||||
/*
|
||||
===========================================================================
|
||||
|
||||
TOKEN
|
||||
|
||||
===========================================================================
|
||||
*/
|
||||
|
||||
/*
|
||||
* **************************
|
||||
* Constructor and destructor
|
||||
* **************************
|
||||
*/
|
||||
|
||||
Token::Token( TokenType ttype, int row, int column, symtabkey_t key, int value )
|
||||
{
|
||||
this->ttype = ttype;
|
||||
this->row = row;
|
||||
this->column = column;
|
||||
|
||||
if( ttype == T_IDENTIFIER ) {
|
||||
this->key = key;
|
||||
} else {
|
||||
this->key = NULL; // special keycode showing invalid key
|
||||
// seems obvious at first, but a key can also be something
|
||||
// different, for example an integer, and if we change the
|
||||
// key, we must accommodate for it it here. <- way
|
||||
// too long comment btw ...
|
||||
}
|
||||
|
||||
if( ttype == T_INTEGER || ttype == T_UNKNOWN ) {
|
||||
this->value = value;
|
||||
} else {
|
||||
this->value = 0; // not needed, but my tourette forced me ;)
|
||||
}
|
||||
}
|
||||
|
||||
Token::~Token()
|
||||
{
|
||||
// TODO we do not support deletion of symtabentries
|
||||
// so the token just dies, and the symtabentry dies
|
||||
// on its own when the symboltable dies ...
|
||||
}
|
||||
|
||||
/*
|
||||
* **************************
|
||||
* Getters (public functions)
|
||||
* **************************
|
||||
*/
|
||||
|
||||
TokenType Token::getTokenType( void ) const
|
||||
{
|
||||
return ttype;
|
||||
}
|
||||
|
||||
int Token::getRow( void ) const
|
||||
{
|
||||
return row;
|
||||
}
|
||||
|
||||
int Token::getColumn( void ) const
|
||||
{
|
||||
return column;
|
||||
}
|
||||
|
||||
symtabkey_t Token::getKey( void ) const
|
||||
{
|
||||
return key;
|
||||
}
|
||||
|
||||
int Token::getValue( void ) const
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
void Token::setTokenType( TokenType ttype )
|
||||
{
|
||||
this->ttype = ttype;
|
||||
}
|
||||
|
||||
void Token::setRow( int row )
|
||||
{
|
||||
this->row = row;
|
||||
}
|
||||
|
||||
void Token::setColumn( int column )
|
||||
{
|
||||
this->column = column;
|
||||
}
|
||||
|
||||
void Token::setKey( symtabkey_t key )
|
||||
{
|
||||
this->key = key;
|
||||
}
|
||||
|
||||
void Token::setValue( int value )
|
||||
{
|
||||
this->value = value;
|
||||
}
|
||||
#include <Scanner.h>
|
||||
#include <Token.h>
|
||||
|
||||
/*
|
||||
===========================================================================
|
||||
|
|
|
@ -1,76 +0,0 @@
|
|||
/*
|
||||
* Scanner.h
|
||||
*
|
||||
* Created on: Sep 26, 2012
|
||||
* Author: knad0001
|
||||
* Class and overall file:
|
||||
* Created on: Apr 19, 2014
|
||||
* Author: mino
|
||||
*/
|
||||
|
||||
#ifndef SCANNER_H_
|
||||
#define SCANNER_H_
|
||||
|
||||
#include <stdlib.h> // for strtol
|
||||
#include <cerrno> // for errno on integer checks
|
||||
#include <climits>
|
||||
#include <cctype>
|
||||
#include <iostream>
|
||||
|
||||
#include "../../Buffer/src/Buffer.h"
|
||||
#include "../../Automat/src/Automat.h"
|
||||
#include "../../Symboltable/src/Symboltable.h"
|
||||
#include "../../includes/local.h"
|
||||
|
||||
/*
|
||||
*
|
||||
* Token class
|
||||
*
|
||||
*/
|
||||
class Token
|
||||
{
|
||||
public:
|
||||
Token( TokenType ttype, int row, int column, symtabkey_t key, int value );
|
||||
virtual ~Token();
|
||||
TokenType getTokenType( void ) const;
|
||||
int getRow( void ) const;
|
||||
int getColumn( void ) const;
|
||||
symtabkey_t getKey( void ) const;
|
||||
int getValue( void ) const;
|
||||
void setTokenType( TokenType ttype );
|
||||
void setRow( int row );
|
||||
void setColumn( int column );
|
||||
void setKey( symtabkey_t key );
|
||||
void setValue( int value );
|
||||
|
||||
private:
|
||||
TokenType ttype;
|
||||
int row;
|
||||
int column;
|
||||
symtabkey_t key; // for fast lookup into symboltable
|
||||
int value; // if it is integer, the value is stored here
|
||||
};
|
||||
|
||||
/*
|
||||
*
|
||||
* Scanner class
|
||||
*
|
||||
*/
|
||||
class Scanner
|
||||
{
|
||||
public:
|
||||
Scanner( char *filepath, Symboltable *symtab );
|
||||
virtual ~Scanner();
|
||||
Token *nextToken( void );
|
||||
|
||||
private:
|
||||
Buffer *buffer;
|
||||
Automat *automat;
|
||||
Symboltable *symtab;
|
||||
|
||||
Token *createToken( TokenType ttype, int row, int column, char *lexem );
|
||||
void skipComment( bool multiline );
|
||||
};
|
||||
|
||||
#endif /* SCANNER_H_ */
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
#include "Scanner.h"
|
||||
#include "../../includes/local.h"
|
||||
#include <Scanner.h>
|
||||
#include <Token.h>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
|
@ -73,6 +73,9 @@ void printTokenType( TokenType t, ofstream *outputFile )
|
|||
case T_WHILE:
|
||||
*outputFile << "Token While ";
|
||||
break;
|
||||
case T_INT:
|
||||
*outputFile << "Token Int ";
|
||||
break;
|
||||
case T_IDENTIFIER:
|
||||
*outputFile << "Token Identifier ";
|
||||
break;
|
||||
|
|
187
Scanner/src/Token.cpp
Normal file
187
Scanner/src/Token.cpp
Normal file
|
@ -0,0 +1,187 @@
|
|||
#include <Token.h>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
/*
|
||||
===========================================================================
|
||||
|
||||
TOKEN
|
||||
|
||||
===========================================================================
|
||||
*/
|
||||
|
||||
/*
|
||||
* **************************
|
||||
* Constructor and destructor
|
||||
* **************************
|
||||
*/
|
||||
|
||||
Token::Token( TokenType ttype, int row, int column, symtabkey_t key, int value )
|
||||
{
|
||||
this->ttype = ttype;
|
||||
this->row = row;
|
||||
this->column = column;
|
||||
|
||||
if( ttype == T_IDENTIFIER ) {
|
||||
this->key = key;
|
||||
} else {
|
||||
this->key = NULL; // special keycode showing invalid key
|
||||
// seems obvious at first, but a key can also be something
|
||||
// different, for example an integer, and if we change the
|
||||
// key, we must accommodate for it it here. <- way
|
||||
// too long comment btw ...
|
||||
}
|
||||
|
||||
if( ttype == T_INTEGER || ttype == T_UNKNOWN ) {
|
||||
this->value = value;
|
||||
} else {
|
||||
this->value = 0; // not needed, but my tourette forced me ;)
|
||||
}
|
||||
}
|
||||
|
||||
Token::~Token()
|
||||
{
|
||||
// TODO we do not support deletion of symtabentries
|
||||
// so the token just dies, and the symtabentry dies
|
||||
// on its own when the symboltable dies ...
|
||||
}
|
||||
|
||||
/*
|
||||
* **************************
|
||||
* Getters (public functions)
|
||||
* **************************
|
||||
*/
|
||||
|
||||
TokenType Token::getTokenType( void ) const
|
||||
{
|
||||
return ttype;
|
||||
}
|
||||
|
||||
int Token::getRow( void ) const
|
||||
{
|
||||
return row;
|
||||
}
|
||||
|
||||
int Token::getColumn( void ) const
|
||||
{
|
||||
return column;
|
||||
}
|
||||
|
||||
symtabkey_t Token::getKey( void ) const
|
||||
{
|
||||
return key;
|
||||
}
|
||||
|
||||
int Token::getValue( void ) const
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
void Token::setTokenType( TokenType ttype )
|
||||
{
|
||||
this->ttype = ttype;
|
||||
}
|
||||
|
||||
void Token::setRow( int row )
|
||||
{
|
||||
this->row = row;
|
||||
}
|
||||
|
||||
void Token::setColumn( int column )
|
||||
{
|
||||
this->column = column;
|
||||
}
|
||||
|
||||
void Token::setKey( symtabkey_t key )
|
||||
{
|
||||
this->key = key;
|
||||
}
|
||||
|
||||
void Token::setValue( int value )
|
||||
{
|
||||
this->value = value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void printTokenType( TokenType t )
|
||||
{
|
||||
std::cout << t << std::endl;
|
||||
switch(t) {
|
||||
case T_PLUS:
|
||||
std::cout << "Token Plus \n";
|
||||
break;
|
||||
case T_MINUS:
|
||||
std::cout << "Token Minus \n";
|
||||
break;
|
||||
case T_DIVIDE:
|
||||
std::cout << "Token Divide \n";
|
||||
break;
|
||||
case T_MULTI:
|
||||
std::cout << "Token Multi \n";
|
||||
break;
|
||||
case T_LESSTHAN:
|
||||
std::cout << "Token LessThan \n";
|
||||
break;
|
||||
case T_MORETHAN:
|
||||
std::cout << "Token MoreThan \n";
|
||||
break;
|
||||
case T_ASSIGN:
|
||||
std::cout << "Token Assign \n";
|
||||
break;
|
||||
case T_EQUAL:
|
||||
std::cout << "Token Equal \n";
|
||||
break;
|
||||
case T_UNEQUAL:
|
||||
std::cout << "Token Unequal \n";
|
||||
break;
|
||||
case T_EXCLAMATION:
|
||||
std::cout << "Token Exclamation \n";
|
||||
break;
|
||||
case T_AND:
|
||||
std::cout << "Token And \n";
|
||||
break;
|
||||
case T_SEMICOLON:
|
||||
std::cout << "Token Semicolon \n";
|
||||
break;
|
||||
case T_LPARENT:
|
||||
std::cout << "Token LPar \n";
|
||||
break;
|
||||
case T_RPARENT:
|
||||
std::cout << "Token RPar \n";
|
||||
break;
|
||||
case T_LBRACKET:
|
||||
std::cout << "Token LBrack \n";
|
||||
break;
|
||||
case T_RBRACKET:
|
||||
std::cout << "Token RBrack \n";
|
||||
break;
|
||||
case T_LBRACE:
|
||||
std::cout << "Token LBrace \n";
|
||||
break;
|
||||
case T_RBRACE:
|
||||
std::cout << "Token RBrace \n";
|
||||
break;
|
||||
case T_INTEGER:
|
||||
std::cout << "Token Integer \n";
|
||||
break;
|
||||
case T_IF:
|
||||
std::cout << "Token If \n";
|
||||
break;
|
||||
case T_WHILE:
|
||||
std::cout << "Token While \n";
|
||||
break;
|
||||
case T_INT:
|
||||
std::cout << "Token Int \n";
|
||||
break;
|
||||
case T_IDENTIFIER:
|
||||
std::cout << "Token Identifier \n";
|
||||
break;
|
||||
case T_END:
|
||||
std::cout << "Token End \n";
|
||||
break;
|
||||
default:
|
||||
std::cout << "Token Unknown \n";
|
||||
break;
|
||||
}
|
||||
}
|
|
@ -9,7 +9,9 @@ LIBDIR = lib
|
|||
|
||||
SHAREDLIB = ../sharedlib
|
||||
|
||||
FLAGS=-g -Wall -Werror -ansi -pedantic
|
||||
INCLUDES = ../includes
|
||||
|
||||
FLAGS=-g -Wall -Werror -ansi -pedantic -I$(INCLUDES)
|
||||
|
||||
## hier alle Object Files eintragen
|
||||
## darauf achten, dass letzte Zeile ohne "\" eingetragen wird
|
||||
|
@ -41,7 +43,7 @@ OBJSFORSYMBOLTABLELIB = \
|
|||
# g++ -g -c -Wall -o $(OBJDIR)/Symboltable.o $(SRCDIR)/Symboltable.cpp
|
||||
#
|
||||
#
|
||||
#$(OBJDIR)/TestSymboltable.o : $(SRCDIR)/TestSymboltable.cpp $(SRCDIR)/Symboltable.h
|
||||
#$(OBJDIR)/TestSymboltable.o : $(SRCDIR)/TestSymboltable.cpp $(INCLUDES)/Symboltable.h
|
||||
# @echo "g++ $*.cpp"
|
||||
# g++ -g -c -Wall -o $(OBJDIR)/TestSymboltable.o $(SRCDIR)/TestSymboltable.cpp
|
||||
#
|
||||
|
@ -97,6 +99,6 @@ $(LIBDIR)/%.o : $(SRCDIR)/%.cpp
|
|||
@echo "g++ $*.cpp"
|
||||
g++ $(FLAGS) -c -fPIC -o $@ $<
|
||||
|
||||
SymboltableLibTarget : $(SRCDIR)/Symboltable.cpp $(SRCDIR)/Symboltable.h
|
||||
SymboltableLibTarget : $(SRCDIR)/Symboltable.cpp $(INCLUDES)/Symboltable.h
|
||||
g++ $(FLAGS) -c -fPIC -o $(LIBDIR)/Symboltable.o $(SRCDIR)/Symboltable.cpp
|
||||
|
||||
|
|
|
@ -213,7 +213,6 @@ void Symboltable::initSymbols( void ) // Insert the keywords
|
|||
insert( (char*)"int" )->getInfo()->setType(T_INT);
|
||||
insert( (char*)"IF" )->getInfo()->setType(T_IF);
|
||||
insert( (char*)"WHILE" )->getInfo()->setType(T_WHILE);
|
||||
insert( (char*)"troll");
|
||||
}
|
||||
|
||||
symtabkey_t Symboltable::insert( char *lexem )
|
||||
|
|
|
@ -12,7 +12,26 @@
|
|||
#ifndef Automat_H_
|
||||
#define Automat_H_
|
||||
|
||||
#include "../../includes/local.h"
|
||||
#include <Token.h>
|
||||
|
||||
|
||||
enum State { // Used for matrix index. Don't change the numbers!
|
||||
S_START = 0,
|
||||
S_IDENTIFIER,
|
||||
S_INTEGER,
|
||||
S_SIGN,
|
||||
S_EQ,
|
||||
S_D_EQ,
|
||||
S_T_EQ,
|
||||
S_EQ_DIFF,
|
||||
S_EQ_DIFF_EQ,
|
||||
S_SLASH,
|
||||
S_COM,
|
||||
S_COM_M,
|
||||
S_END,
|
||||
S_ERROR,
|
||||
NR_OF_STATE
|
||||
};
|
||||
|
||||
enum CharType { // Used for matrix index. Don't change the numbers!
|
||||
C_SIGN = 0,
|
|
@ -7,7 +7,6 @@
|
|||
#ifndef BUFFER_H_
|
||||
#define BUFFER_H_
|
||||
|
||||
#include "../../includes/local.h"
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
|
@ -34,4 +33,6 @@ private:
|
|||
int lexemRow; //row where lexem begins
|
||||
};
|
||||
|
||||
#define EOF_ENCODING -1
|
||||
|
||||
#endif /* BUFFER_H_ */
|
|
@ -6,9 +6,9 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "../../includes/local.h"
|
||||
#include "../../Scanner/src/Scanner.h"
|
||||
#include "list.h"
|
||||
#include <Token.h>
|
||||
#include <Scanner.h>
|
||||
#include <TList.h>
|
||||
|
||||
class Parser {
|
||||
public:
|
47
includes/Scanner.h
Normal file
47
includes/Scanner.h
Normal file
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Scanner.h
|
||||
*
|
||||
* Created on: Sep 26, 2012
|
||||
* Author: knad0001
|
||||
* Class and overall file:
|
||||
* Created on: Apr 19, 2014
|
||||
* Author: mino
|
||||
*/
|
||||
|
||||
#ifndef SCANNER_H_
|
||||
#define SCANNER_H_
|
||||
|
||||
#include <stdlib.h> // for strtol
|
||||
#include <cerrno> // for errno on integer checks
|
||||
#include <climits>
|
||||
#include <cctype>
|
||||
#include <iostream>
|
||||
|
||||
#include <Token.h>
|
||||
#include <Buffer.h>
|
||||
#include <Automat.h>
|
||||
#include <Symboltable.h>
|
||||
|
||||
/*
|
||||
*
|
||||
* Scanner class
|
||||
*
|
||||
*/
|
||||
class Scanner
|
||||
{
|
||||
public:
|
||||
Scanner( char *filepath, Symboltable *symtab );
|
||||
virtual ~Scanner();
|
||||
Token *nextToken( void );
|
||||
|
||||
private:
|
||||
Buffer *buffer;
|
||||
Automat *automat;
|
||||
Symboltable *symtab;
|
||||
|
||||
Token *createToken( TokenType ttype, int row, int column, char *lexem );
|
||||
void skipComment( bool multiline );
|
||||
};
|
||||
|
||||
#endif /* SCANNER_H_ */
|
||||
|
|
@ -15,13 +15,16 @@
|
|||
#include <string>
|
||||
#include <cstring>
|
||||
|
||||
#include "../../includes/local.h"
|
||||
#include <Token.h>
|
||||
|
||||
#define PAGE_SIZE 4096
|
||||
#define STRINGTAB_BUFSIZE 8192
|
||||
|
||||
#define NUM_BUCKETS 256
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* StringTab class
|
||||
|
@ -100,5 +103,7 @@ class Symboltable
|
|||
void initSymbols( void );
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* SYMBOLTABLE_H_ */
|
||||
|
|
@ -1,7 +1,12 @@
|
|||
#ifndef _LIST_H
|
||||
#define _LIST_H
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <Token.h>
|
||||
|
||||
struct LItem {
|
||||
void *v;
|
||||
Token *t;
|
||||
LItem *n;
|
||||
LItem *p;
|
||||
};
|
||||
|
@ -12,10 +17,10 @@ class List {
|
|||
LItem *head();
|
||||
LItem *tail();
|
||||
int getSize();
|
||||
void push(void *data);
|
||||
void *pop();
|
||||
void add(void *data);
|
||||
void *rem();
|
||||
void push(Token *data);
|
||||
Token *pop();
|
||||
void add(Token *data);
|
||||
Token *rem();
|
||||
void clean();
|
||||
|
||||
private:
|
||||
|
@ -24,3 +29,4 @@ class List {
|
|||
int m_size;
|
||||
};
|
||||
|
||||
#endif
|
70
includes/Token.h
Normal file
70
includes/Token.h
Normal file
|
@ -0,0 +1,70 @@
|
|||
|
||||
#ifndef TOKEN_H
|
||||
#define TOKEN_H
|
||||
|
||||
typedef class SymtabEntry *symtabkey_t;
|
||||
|
||||
enum TokenType {
|
||||
T_PLUS,
|
||||
T_MINUS,
|
||||
T_DIVIDE,
|
||||
T_MULTI,
|
||||
T_LESSTHAN,
|
||||
T_MORETHAN,
|
||||
T_ASSIGN,
|
||||
T_EQUAL,
|
||||
T_UNEQUAL,
|
||||
T_EXCLAMATION,
|
||||
T_AND,
|
||||
T_SEMICOLON,
|
||||
T_LPARENT,
|
||||
T_RPARENT,
|
||||
T_LBRACKET,
|
||||
T_RBRACKET,
|
||||
T_LBRACE,
|
||||
T_RBRACE,
|
||||
T_INTEGER,
|
||||
T_IF,
|
||||
T_WHILE,
|
||||
T_INT,
|
||||
T_IDENTIFIER,
|
||||
T_COM,
|
||||
T_COM_M,
|
||||
T_END,
|
||||
T_UNKNOWN,
|
||||
NR_OF_TOKEN_TYPE
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* Token class
|
||||
*
|
||||
*/
|
||||
class Token
|
||||
{
|
||||
public:
|
||||
Token( TokenType ttype, int row, int column, symtabkey_t key, int value );
|
||||
virtual ~Token();
|
||||
TokenType getTokenType( void ) const;
|
||||
int getRow( void ) const;
|
||||
int getColumn( void ) const;
|
||||
symtabkey_t getKey( void ) const;
|
||||
int getValue( void ) const;
|
||||
void setTokenType( TokenType ttype );
|
||||
void setRow( int row );
|
||||
void setColumn( int column );
|
||||
void setKey( symtabkey_t key );
|
||||
void setValue( int value );
|
||||
|
||||
private:
|
||||
TokenType ttype;
|
||||
int row;
|
||||
int column;
|
||||
symtabkey_t key; // for fast lookup into symboltable
|
||||
int value; // if it is integer, the value is stored here
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
|
@ -1,58 +0,0 @@
|
|||
|
||||
#ifndef LOCAL_H
|
||||
#define LOCAL_H
|
||||
|
||||
enum State { // Used for matrix index. Don't change the numbers!
|
||||
S_START = 0,
|
||||
S_IDENTIFIER,
|
||||
S_INTEGER,
|
||||
S_SIGN,
|
||||
S_EQ,
|
||||
S_D_EQ,
|
||||
S_T_EQ,
|
||||
S_EQ_DIFF,
|
||||
S_EQ_DIFF_EQ,
|
||||
S_SLASH,
|
||||
S_COM,
|
||||
S_COM_M,
|
||||
S_END,
|
||||
S_ERROR,
|
||||
NR_OF_STATE
|
||||
};
|
||||
|
||||
enum TokenType {
|
||||
T_PLUS,
|
||||
T_MINUS,
|
||||
T_DIVIDE,
|
||||
T_MULTI,
|
||||
T_LESSTHAN,
|
||||
T_MORETHAN,
|
||||
T_ASSIGN,
|
||||
T_EQUAL,
|
||||
T_UNEQUAL,
|
||||
T_EXCLAMATION,
|
||||
T_AND,
|
||||
T_SEMICOLON,
|
||||
T_LPARENT,
|
||||
T_RPARENT,
|
||||
T_LBRACKET,
|
||||
T_RBRACKET,
|
||||
T_LBRACE,
|
||||
T_RBRACE,
|
||||
T_INTEGER,
|
||||
T_IF,
|
||||
T_WHILE,
|
||||
T_INT,
|
||||
T_IDENTIFIER,
|
||||
T_COM,
|
||||
T_COM_M,
|
||||
T_END,
|
||||
T_UNKNOWN,
|
||||
NR_OF_TOKEN_TYPE
|
||||
};
|
||||
|
||||
typedef class SymtabEntry *symtabkey_t;
|
||||
|
||||
#define EOF_ENCODING -1
|
||||
|
||||
#endif
|
5
makefile
5
makefile
|
@ -13,6 +13,8 @@ SCANNERDIR = Scanner
|
|||
|
||||
SHAREDLIB = sharedlib
|
||||
|
||||
INCLUDES = includes
|
||||
|
||||
|
||||
all: empty-dirs automatLib bufferLib symboltableLib scanner
|
||||
@echo "target all"
|
||||
|
@ -29,6 +31,9 @@ clean:
|
|||
rm -rf $(SYMBOLTABLEDIR)/lib/*
|
||||
rm -rf $(SHAREDLIB)/*
|
||||
rm -rf $(SCANNERDIR)/debug/*
|
||||
rm -rf $(AUTOMATDIR)/debug/*
|
||||
rm -rf $(BUFFERDIR)/debug/*
|
||||
rm -rf $(SYMBOLTABLEDIR)/debug/*
|
||||
|
||||
empty-dirs:
|
||||
test -d $(AUTOMATDIR)/lib || mkdir $(AUTOMATDIR)/lib
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
pX=3+4;
|
||||
int pX=3+4;
|
||||
/* eine einfache Aufgabe !! */
|
||||
?y === X / (X - 4);
|
||||
Z = if((3 + 4 - 6);
|
||||
while (if (4000_})while2;
|
||||
Resultat = / X y %/* lol
|
||||
int Resultat = / X y %/* lol
|
||||
plop
|
||||
trolczvzeef ==qda&é&e// /* */while
|
||||
42 //if (lol == fake)
|
||||
|
|
Loading…
Reference in a new issue