Browse Source

Improve array function, and some shit in Makefiles

remotes/origin/master
Skia 6 years ago
parent
commit
5931642177
9 changed files with 59 additions and 16 deletions
  1. BIN
      Parser/debug/ParserTest
  2. +2
    -2
      Parser/makefile
  3. +37
    -12
      Parser/src/Parser.cpp
  4. +5
    -0
      Parser/src/TList.cpp
  5. +6
    -0
      Scanner/src/Token.cpp
  6. +2
    -2
      includes/Parser.h
  7. +1
    -0
      includes/TList.h
  8. +1
    -0
      includes/Token.h
  9. +5
    -0
      makefile

BIN
Parser/debug/ParserTest View File


+ 2
- 2
Parser/makefile View File

@@ -50,8 +50,8 @@ all: listLib parser


#Variante mit guten Kenntnissen
parser: $(OBJS)
g++ $(FLAGS) $^ -L../sharedlib -lList -lScanner -o $(BINDIR)/ParserTest
parser: listLib $(OBJS)
g++ $(FLAGS) $(OBJS) -L../sharedlib -lList -lScanner -o $(BINDIR)/ParserTest


list: $(SRCDIR)/TList.cpp $(SRCDIR)/TestList.cpp


+ 37
- 12
Parser/src/Parser.cpp View File

@@ -25,9 +25,13 @@ bool Parser::parse()
return prog();
}

void Parser::error(Token *t)
void Parser::error(Token *t = NULL, char *msg = (char*)"Troll")
{
// Error
std::cout << "Error: Unexpected Token ";
t->pInfo(std::cout);
std::cout << std::endl;
delete t;
exit(EXIT_FAILURE);
}

bool Parser::prog()
@@ -49,15 +53,14 @@ bool Parser::decls()
while (l->getSize() < max && (t = this->sc->nextToken())->getTokenType() != T_SEMICOLON) {
l->push(t);
}
std::cout << "List: " << std::endl;
std::cout << std::endl << "List: " << std::endl;
it = l->head();
while (it != NULL) {
it->t->pType(std::cout);
std::cout << t << std::endl;
std::cout << std::endl;
it = it->n;
}
if (l->getSize() >= max) {
l->clean();
delete l;
return false;
}
@@ -84,14 +87,36 @@ bool Parser::decl(List *l) //XXX: memleak because we don't free what we rem/pop
return false;
}

bool Parser::array(List *l) //XXX: memleak because we don't free what we rem/pop
// IDEA: array returns the size of the array, to build the tree
int Parser::array(List *l)
{
if (l->rem()->getTokenType() == T_LBRACKET
&& l->rem()->getTokenType() == T_INTEGER
&& l->rem()->getTokenType() == T_RBRACKET)
return true;
else // ERROR UNEXPECTED TOKEN
return false;
int value = 0;
Token *lb = l->rem(),
*in = l->rem(),
*rb = l->rem();
if (lb->getTokenType() == T_LBRACKET) {
if (in->getTokenType() == T_INTEGER) {
if (rb->getTokenType() == T_RBRACKET) {
value = in->getValue();
} else {
delete lb;
delete in;
error(rb);
}
} else {
delete lb;
delete rb;
error(in);
}
} else {
delete rb;
delete in;
error(lb);
}
delete lb;
delete in;
delete rb;
return value;
}




+ 5
- 0
Parser/src/TList.cpp View File

@@ -12,6 +12,11 @@

List::List(): m_head(NULL), m_tail(NULL), m_size(0) {}

List::~List()
{
this->clean();
}

LItem *List::head()
{
return m_head;


+ 6
- 0
Scanner/src/Token.cpp View File

@@ -183,6 +183,12 @@ void Token::pType(std::ostream &s) const
}
}

void Token::pInfo(std::ostream &s) const
{
this->pType(s);
s << " (Row " << this->row << ", Col " << this->column << ")" << std::endl;
}

std::ostream &operator<<( std::ostream &s, Token const* t)
{
t->pType(s);


+ 2
- 2
includes/Parser.h View File

@@ -17,12 +17,12 @@ class Parser {


private:
void error(Token *t);
void error(Token *t, char *msg);

bool prog();
bool decls();
bool decl(List *l);
bool array(List *l);
int array(List *l);
bool statments(List *l);
bool statment(List *l);
bool exp(List *l);


+ 1
- 0
includes/TList.h View File

@@ -14,6 +14,7 @@ struct LItem {
class List {
public:
List();
~List();
LItem *head();
LItem *tail();
int getSize();


+ 1
- 0
includes/Token.h View File

@@ -59,6 +59,7 @@ class Token
void setKey( symtabkey_t key );
void setValue( int value );
void pType(std::ostream &s) const;
void pInfo(std::ostream &s) const;

private:
TokenType ttype;


+ 5
- 0
makefile View File

@@ -11,6 +11,8 @@ SYMBOLTABLEDIR = Symboltable

SCANNERDIR = Scanner

PARSERDIR = Parser

SHAREDLIB = sharedlib

INCLUDES = includes
@@ -48,6 +50,9 @@ empty-dirs:
test -d $(SHAREDLIB) || mkdir $(SHAREDLIB)


parser:
$(MAKE) -C $(PARSERDIR) parser

scanner:
$(MAKE) -C $(SCANNERDIR) makeTestScanner



Loading…
Cancel
Save