Skip to content

Syntax tree#6

Closed
Alena-pa wants to merge 8 commits intomainfrom
SyntaxTree
Closed

Syntax tree#6
Alena-pa wants to merge 8 commits intomainfrom
SyntaxTree

Conversation

@Alena-pa
Copy link
Copy Markdown
Owner

No description provided.

Copy link
Copy Markdown

@yurii-litvinov yurii-litvinov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Какой-то хаос в репозитории, стоит навести порядок ASAP

const char* value;
} NodeValue;

typedef struct Node {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно было NodeValue сделать просто typedef-ом на char*

NodeValue value;
struct Node* leftChild;
struct Node* rightChild;
} Node;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Кстати, определений структур не надо в .h


Node* createNode(NodeValue *value) {
Node* node = calloc(1, sizeof(Node));
node->value = *value;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Надо проверять результат calloc


skipWhitespaceAndBrackets(string, indexOfString);

if (isdigit(string[*indexOfString])) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Так может быть плохо с отрицательными числами

if (string[*indexOfString] == '+' || string[*indexOfString] == '-' || string[*indexOfString] == '*' || string[*indexOfString] == '/') {
char operationToCount = string[*indexOfString];
Node* node = createNode(operationToCount);
indexOfString++;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это инкремент указателя, а не значения, так что должно было страшно падать при обращении к нему ниже :)

struct Node* rightChild;
} Node;

NodeValue createValue(const char* value);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нужны комментарии

bool testCreateNode() {
NodeValue value = createValue("1");
Node* node = createNode(value);
return (strcmp(node->value.value, "1") == 0 && node->leftChild == NULL && node->rightChild == NULL);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Надо удалять за собой память

return number;
}

Node* modifyString(const char* string, int* indexOfString) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Почему функция, строящая дерево разбора по строке, называется так странно? Она даже никак не модифицирует строку :)

}

bool allTests() {
return (testCreateNode && testCalculation && testTreeBuilding);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тесты не вызываются, поэтому и не падает, хотя должно

#include "Tests.h"

int main(void) {
if (!allTests) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ну и тут не вызываются

@Alena-pa Alena-pa closed this Feb 17, 2025
@Alena-pa Alena-pa deleted the SyntaxTree branch February 17, 2025 20:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants