Skip to content

Commit ae0d74c

Browse files
committed
More hints
1 parent 146e4a5 commit ae0d74c

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

src/lexer/lexer.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,22 @@ const std::vector<Token*> Lexer::makeTokens() {
6060
}
6161
continue;
6262
} else if (currentChar == '(') {
63+
if (idx > 0 && tokens.size() > 0 && (*expr)[idx-1] != ' ') {
64+
TokenType t = tokens[tokens.size()-1]->type;
65+
if (t == TokenType::INPUT) {
66+
throw PSC::LexerError(line, column, "Unexpected '('\n'INTPUT' is statement(not a function) used as 'INPUT <var>' where <var> is a variable to store the input");
67+
} else if (t == TokenType::OUTPUT) {
68+
throw PSC::LexerError(line, column, "Unexpected '('\n'OUTPUT' is statement(not a function) used as 'OUTPUT <value>' or 'OUTPUT <value1>, <value2>, ...'");
69+
} else if (t == TokenType::OPENFILE) {
70+
throw PSC::LexerError(line, column, "Unexpected '('\n'OPENFILE' is statement(not a function) used as 'OPENFILE <filename> FOR <mode>'");
71+
} else if (t == TokenType::READFILE) {
72+
throw PSC::LexerError(line, column, "Unexpected '('\n'READFILE' is statement(not a function) used as 'READFILE <filename>, <var>'");
73+
} else if (t == TokenType::WRITEFILE) {
74+
throw PSC::LexerError(line, column, "Unexpected '('\n'WRITEFILE' is statement(not a function) used as 'WRITEFILE <filename>, <line>'");
75+
} else if (t == TokenType::CLOSEFILE) {
76+
throw PSC::LexerError(line, column, "Unexpected '('\n'CLOSEFILE' is statement(not a function) used as 'CLOSEFILE <filename>'");
77+
}
78+
}
6379
tokens.emplace_back(new Token(TokenType::LPAREN, line, column));
6480
} else if (currentChar == ')') {
6581
tokens.emplace_back(new Token(TokenType::RPAREN, line, column));
@@ -70,7 +86,7 @@ const std::vector<Token*> Lexer::makeTokens() {
7086
} else if (currentChar == '=') {
7187
advance();
7288
if (idx >= expr->size() || currentChar != '=') {
73-
tokens.emplace_back(new Token(TokenType::EQUALS, line, column));
89+
tokens.emplace_back(new Token(TokenType::EQUALS, line, column - 1));
7490
continue;
7591
} else {
7692
throw PSC::LexerError(line, column - 1, "Invalid token '=='\nIf you want to check for equality, use single '=' instead");

src/nodes/base.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66
#include "nodes/nodeResult.h"
77

88
class Node {
9-
protected:
9+
public:
1010
const Token &token;
1111

12-
public:
1312
Node(const Token &token);
1413

1514
virtual ~Node() = default;
@@ -22,21 +21,19 @@ class Node {
2221
};
2322

2423
class UnaryNode : public Node {
25-
protected:
26-
Node &node;
27-
2824
public:
25+
Node &node;
26+
2927
UnaryNode(const Token &token, Node &node);
3028

3129
std::string toStr() const override;
3230
};
3331

3432
class BinaryNode : public Node {
35-
protected:
33+
public:
3634
Node &left;
3735
Node &right;
3836

39-
public:
4037
BinaryNode(const Token &token, Node &left, Node &right);
4138

4239
std::string toStr() const override;

src/parser/parser.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ PSC::Block *Parser::parseBlock(BlockType blockType) {
9191
node = parseFunction();
9292
} else {
9393
node = parseExpression();
94+
ComparisonNode *cn = dynamic_cast<ComparisonNode*>(node);
95+
if (cn != nullptr) {
96+
AccessNode *an = dynamic_cast<AccessNode*>(&(cn->left));
97+
if (an != nullptr) {
98+
std::cout << "Warning on line " << cn->token.line << " column " << cn->token.column << ": Comparison result is ignored. Use '<-' instead of '=' if you wanted to assign." << std::endl;
99+
}
100+
}
94101
}
95102

96103
block->addNode(node);

0 commit comments

Comments
 (0)