Skip to content

Commit

Permalink
changed rpn list to hold error column/length instead of token
Browse files Browse the repository at this point in the history
there was no reason for the RPN list to have the error token
changed ErrorItem constructor to take rpn list instead of token/message
removed unnecessary blank line after error in test code
also fixed expected results files to remove unnecessary blank lines
  • Loading branch information
thunder422 committed Apr 27, 2013
1 parent 666b15b commit fdb7982
Show file tree
Hide file tree
Showing 24 changed files with 43 additions and 390 deletions.
11 changes: 5 additions & 6 deletions errorlist.cpp
Expand Up @@ -23,18 +23,17 @@
// 2013-04-10 initial version

#include "errorlist.h"
#include "token.h"
#include "rpnlist.h"


// constructor function to set error item
ErrorItem::ErrorItem(Type type, int lineNumber, Token *token,
const QString &message)
ErrorItem::ErrorItem(Type type, int lineNumber, RpnList *rpnList)
{
m_type = type;
m_lineNumber = lineNumber;
m_column = token->column();
m_length = token->length();
m_message = message;
m_column = rpnList->errorColumn();
m_length = rpnList->errorLength();
m_message = rpnList->errorMessage();
}


Expand Down
4 changes: 2 additions & 2 deletions errorlist.h
Expand Up @@ -28,7 +28,7 @@
#include <QList>
#include <QString>

class Token;
class RpnList;

// class for holding details for an error of a program line
class ErrorItem
Expand All @@ -39,7 +39,7 @@ class ErrorItem
Translator,
Encoder
};
ErrorItem(Type type, int lineNumber, Token *token, const QString &message);
ErrorItem(Type type, int lineNumber, RpnList *rpnList);
int lineNumber(void) const
{
return m_lineNumber;
Expand Down
11 changes: 4 additions & 7 deletions programmodel.cpp
Expand Up @@ -60,9 +60,8 @@ QVariant ProgramModel::data(const QModelIndex &index, int role) const
}
else // translate error occurred
{
Token *token = rpnList->errorToken();
return QString("ERROR %1:%2 %3").arg(token->column())
.arg(token->length()).arg(rpnList->errorMessage());
return QString("ERROR %1:%2 %3").arg(rpnList->errorColumn())
.arg(rpnList->errorLength()).arg(rpnList->errorMessage());
}
}
}
Expand Down Expand Up @@ -197,8 +196,7 @@ void ProgramModel::setError(int lineNumber, LineInfo &lineInfo,
{
// replace current error
m_errors.replace(lineInfo.errIndex, ErrorItem(ErrorItem::Translator,
lineNumber, lineInfo.rpnList->errorToken(),
lineInfo.rpnList->errorMessage()));
lineNumber, lineInfo.rpnList));
}

// find location in error list for line number
Expand All @@ -208,8 +206,7 @@ void ProgramModel::setError(int lineNumber, LineInfo &lineInfo,
{
// insert new error into error list
m_errors.insert(errIndex, ErrorItem(ErrorItem::Translator,
lineNumber, lineInfo.rpnList->errorToken(),
lineInfo.rpnList->errorMessage()));
lineNumber, lineInfo.rpnList));

lineInfo.errIndex = errIndex++;
}
Expand Down
7 changes: 3 additions & 4 deletions rpnlist.cpp
Expand Up @@ -28,7 +28,6 @@
RpnList::~RpnList(void)
{
clear();
delete m_errorToken;
}


Expand Down Expand Up @@ -105,8 +104,8 @@ bool RpnList::operator==(const RpnList &other) const
}
if (hasError())
{
return m_errorToken->column() == other.m_errorToken->column()
&& m_errorToken->length() == other.m_errorToken->length()
return m_errorColumn == other.m_errorColumn
&& m_errorLength == other.m_errorLength
&& m_errorMessage == other.m_errorMessage;
}
if (count() != other.count())
Expand All @@ -124,4 +123,4 @@ bool RpnList::operator==(const RpnList &other) const
}


// end: rpn_list.cpp
// end: rpnlist.cpp
23 changes: 14 additions & 9 deletions rpnlist.h
Expand Up @@ -108,7 +108,7 @@ class RpnItem
class RpnList : public QList<RpnItem *>
{
public:
RpnList(void) : m_errorToken(NULL) {}
RpnList(void) : m_errorColumn(-1), m_errorLength(-1) {}
~RpnList(void);
void clear(void);
QString text(void);
Expand All @@ -118,18 +118,22 @@ class RpnList : public QList<RpnItem *>
return !(*this == other);
}

void setErrorToken(Token *errorToken)
void setError(Token *errorToken)
{
delete m_errorToken;
m_errorToken = errorToken;
m_errorColumn = errorToken->column();
m_errorLength = errorToken->length();
}
Token *errorToken(void) const
bool hasError(void) const
{
return m_errorToken;
return m_errorColumn != -1;
}
bool hasError(void) const
int errorColumn(void) const
{
return m_errorColumn;
}
int errorLength(void) const
{
return m_errorToken != NULL;
return m_errorLength;
}

void setErrorMessage(QString errorMessage)
Expand All @@ -142,7 +146,8 @@ class RpnList : public QList<RpnItem *>
}

private:
Token *m_errorToken; // token when error occurred
int m_errorColumn; // column of error that occurred
int m_errorLength; // length of error that occurred
QString m_errorMessage; // message of error that occurred
};

Expand Down
2 changes: 0 additions & 2 deletions test/expression2.txt
Expand Up @@ -101,8 +101,6 @@ Output: A B C D + * ^')' E +
Input: (A + B
^-- expected operator or closing parentheses


Input: A + B)
^-- expected operator or end-of-expression


10 changes: 0 additions & 10 deletions test/expression3.txt
Expand Up @@ -11,40 +11,30 @@ Output: X<ref> Y I Neg J + * I<ref> FNZ([I<ref>] B([X<ref>,*,FNZ(] INT( NUM$ VAL
Input: INT(A+B
^-- expected operator or closing parentheses


Input: B,F+G
^-- expected operator or end-of-statement


Input: Arr(B,,C)
^-- expected expression


Input: MID$(,,C)
^-- expected string expression


Input: MID$(A,,C)
^-- expected string expression


Input: MID$(A$,,C)
^-- expected numeric expression


Input: MID$(A$,B$,C)
^^-- expected numeric expression


Input: MID$(A$,B,,C)
^-- expected numeric expression


Input: MID$(A$,B,C$)
^^-- expected numeric expression


Input: MID$(A$,B,C,)
^-- expected operator or closing parentheses


6 changes: 0 additions & 6 deletions test/expression4.txt
Expand Up @@ -20,24 +20,18 @@ Output: A 1.23 STR$( VAL([STR$(] =
Input: MID$(A$)
^-- expected operator or comma


Input: MID$(A$,1,2,3)
^-- expected operator or closing parentheses


Input: INSTR(A$)
^-- expected operator or comma


Input: INSTR(A$,B$,C,D)
^-- expected operator or closing parentheses


Input: ASC(A$,B,C)
^-- expected operator or closing parentheses


Input: INT(1.23,A)
^-- expected operator or closing parentheses


10 changes: 0 additions & 10 deletions test/translator01.txt
Expand Up @@ -53,40 +53,30 @@ Output: B<ref> C<ref> A(<ref>[B<ref>,C<ref>] E<ref> D(<ref>[E<ref>] F INT( G<ref
Input: A=B,C=4
^-- expected operator or end-of-statement


Input: A=B+C,4
^-- expected operator or end-of-statement


Input: A(B+C,(D,E)=F
^-- expected operator or closing parentheses


Input: A(B+C,(D=E)=(F,G)
^-- expected operator or closing parentheses


Input: A,B+C
^-- expected equal or comma for assignment


Input: 3=A
^-- expected item for assignment


Input: A,3,B=4
^-- expected double variable


Input: (A=B)
^-- expected command


Input: A,B,(C)=4
^-- expected double variable


Input: A+B
^-- expected equal or comma for assignment


11 changes: 0 additions & 11 deletions test/translator02.txt
Expand Up @@ -53,44 +53,33 @@ Output: Z<ref> A% B C D ^ * +%1 Assign
Input: Z = A$ + B
^-- expected string expression


Input: Z = A$ + B%
^^-- expected string expression


Input: Z = A + B$
^^-- expected numeric expression


Input: Z = A% + B$
^^-- expected numeric expression


Input: Z$ = A$ - B$
^^-- expected numeric expression


Input: Z$ = MID$(A$,B$,1)
^^-- expected numeric expression


Input: Z$ = MID$(A$,2,C$)
^^-- expected numeric expression


Input: Z$ = MID$(A,2,3)
^-- expected string expression


Input: Z$ = MID$(A$,2,3) + B
^-- expected string expression


Input: Z = B + MID$(A$,2,3)
^^^^^^^^^^^^-- expected numeric expression


Input: Z = A + (B$ + C$)
^^^^^^^^^-- expected numeric expression


20 changes: 0 additions & 20 deletions test/translator03.txt
Expand Up @@ -29,80 +29,60 @@ Output: A$<ref> B$<ref> C$<ref> "Test" AssignList$["Test"]
Input: A$ = B$ = C$ = "Test"
^^^^^^-- expected numeric expression


Input: Z, Y = A$ + B%
^^-- expected string expression


Input: Z, Y = A$ + B$
^^^^^^^-- expected numeric expression


Input: A,B%,C = 1.0
^^-- expected double variable


Input: A,B,C% = 1.0
^^-- expected double variable


Input: A%,B,C = 1.0
^-- expected integer variable


Input: A,"T",B = 1
^^^-- expected double variable


Input: A = "T" = B = 1
^-- expected string expression


Input: A,B,C = STR$(1)
^^^^^^^-- expected numeric expression


Input: A,B,C$ = STR$(1)
^^-- expected double variable


Input: A,B,C$ = 1
^^-- expected double variable


Input: A,B$,C = 1
^^-- expected double variable


Input: A,B,1 = 1
^-- expected double variable


Input: A,B%,1 = 1
^^-- expected double variable


Input: 1,A,B% = 1
^-- expected item for assignment


Input: A%,B,C% = 1
^-- expected integer variable


Input: A%,B$,C% = 1
^^-- expected integer variable


Input: A$,B$,C% = 1
^^-- expected string item for assignment


Input: A$,B$,C$ = 1
^-- expected string expression


Input: Z = A$ + B * C
^^^^^-- expected string expression


0 comments on commit fdb7982

Please sign in to comment.