Improve array function, and some shit in Makefiles
This commit is contained in:
parent
5c88af4cb6
commit
5931642177
Binary file not shown.
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -14,6 +14,7 @@ struct LItem {
|
|||
class List {
|
||||
public:
|
||||
List();
|
||||
~List();
|
||||
LItem *head();
|
||||
LItem *tail();
|
||||
int getSize();
|
||||
|
|
|
@ -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
makefile
5
makefile
|
@ -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…
Reference in a new issue