Compare commits
16
Commits
433ee2bb2e
...
lab2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
79a96aea77 | ||
|
|
ab4afb48e7 | ||
|
|
b15ae562fd | ||
|
|
0329ed8326 | ||
|
|
4c26353876 | ||
|
|
360628d65c | ||
|
|
e837671d15 | ||
|
|
10e0a487ab | ||
|
|
1a258cd051 | ||
|
|
f430b3616a | ||
|
|
ddcf261af7 | ||
|
|
89335fbdc6 | ||
|
|
1b4693029f | ||
|
|
e8c2293b50 | ||
|
|
0d39290709 | ||
|
|
84d28d3845 |
+1
-1
@@ -1,6 +1,6 @@
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
|
||||
SET(CMAKE_CXX_FLAGS_DEBUG "-g")
|
||||
SET(CMAKE_CXX_FLAGS_DEBUG "-g -Wall -Wextra -Wpedantic")
|
||||
|
||||
project(pzks)
|
||||
|
||||
|
||||
@@ -4,3 +4,6 @@
|
||||
#define PRINT_DISABLE_PREFIXES 1
|
||||
|
||||
#define MAX_TOKEN_STRING_LEN 256
|
||||
|
||||
#define LAB2_EXCLUDE_COMPTIME_OP_WRITES 1
|
||||
#define LAB2_PREVENT_NON_FOLDED_DIV_BY_ZERO 1
|
||||
|
||||
+54
-3
@@ -52,6 +52,7 @@ public:
|
||||
}
|
||||
|
||||
explicit TokenValue(void)
|
||||
: s(std::shared_ptr<std::string>())
|
||||
{
|
||||
}
|
||||
|
||||
@@ -144,6 +145,7 @@ public:
|
||||
switch (t)
|
||||
{
|
||||
case VAR:
|
||||
new(&v.s) std::shared_ptr<std::string>;
|
||||
v.s = other.v.s;
|
||||
break;
|
||||
case CONST:
|
||||
@@ -174,7 +176,6 @@ public:
|
||||
return v.s;
|
||||
case CONST:
|
||||
{
|
||||
char buffer[128] = {0};
|
||||
return std::make_shared<std::string>((std::ostringstream() << v.d).str());
|
||||
}
|
||||
case OPERATOR:
|
||||
@@ -186,8 +187,6 @@ public:
|
||||
|
||||
std::shared_ptr<std::string> to_math_str(void) const
|
||||
{
|
||||
char buffer[128] = {0};
|
||||
|
||||
switch (t)
|
||||
{
|
||||
case VAR:
|
||||
@@ -277,6 +276,58 @@ public:
|
||||
return "Invalid operator";
|
||||
}
|
||||
}
|
||||
|
||||
int negative_operator(void) const
|
||||
{
|
||||
if (t != OPERATOR)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (v.o == SUB || v.o == DIV);
|
||||
}
|
||||
|
||||
static int is_negative(Operator o)
|
||||
{
|
||||
return (o == SUB || o == DIV);
|
||||
}
|
||||
|
||||
int is_math_op(void) const
|
||||
{
|
||||
if (t != OPERATOR)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (v.o)
|
||||
{
|
||||
case OPA:
|
||||
case CPA:
|
||||
return 0;
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
int is_opa(void) const
|
||||
{
|
||||
if (t != OPERATOR)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return v.o == OPA;
|
||||
}
|
||||
|
||||
int is_cpa(void) const
|
||||
{
|
||||
if (t != OPERATOR)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return v.o == CPA;
|
||||
}
|
||||
};
|
||||
|
||||
struct Operation
|
||||
|
||||
+1
-3
@@ -6,9 +6,7 @@
|
||||
namespace Syntax
|
||||
{
|
||||
|
||||
void pre_process(std::vector<Expression::Token>& tv);
|
||||
int check_syntax(const std::vector<Expression::Token>& tv);
|
||||
void post_process(std::vector<Expression::Token>& tv);
|
||||
int prepare_token_vector(std::vector<Expression::Token>& tv);
|
||||
std::vector<Expression::Operation> build_op_vector(const std::vector<Expression::Token>& tv);
|
||||
Expression::TreeNode ov_to_tree(const std::vector<Expression::Token> tv, const std::vector<Expression::Operation>& ov);
|
||||
void print_op_tree(const std::vector<Expression::Token> tv, const std::vector<Expression::Operation>& ov);
|
||||
|
||||
+1
-5
@@ -10,15 +10,11 @@ int main(int argc, char **argv)
|
||||
|
||||
std::vector<Expression::Token> tv = Parser::tokenize_input(argv[1]);
|
||||
|
||||
Syntax::pre_process(tv);
|
||||
|
||||
if (Syntax::check_syntax(tv))
|
||||
if (Syntax::prepare_token_vector(tv))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
Syntax::post_process(tv);
|
||||
|
||||
std::vector<Expression::Operation> ov = Syntax::build_op_vector(tv);
|
||||
|
||||
Expression::TreeNode root = Syntax::ov_to_tree(tv, ov);
|
||||
|
||||
+1
-5
@@ -35,8 +35,6 @@ class Parser
|
||||
|
||||
int switch_state(enum State e)
|
||||
{
|
||||
pr_debug("Leaving " << state_str(s) << ", entering " << state_str(e));
|
||||
|
||||
int cumulative_backtrack = 0;
|
||||
|
||||
switch (s)
|
||||
@@ -79,8 +77,6 @@ class Parser
|
||||
|
||||
s = e;
|
||||
|
||||
pr_debug("Cumulative backtrack is " << cumulative_backtrack);
|
||||
|
||||
return cumulative_backtrack;
|
||||
}
|
||||
|
||||
@@ -415,7 +411,7 @@ void print_math_vector(const std::vector<Expression::Token>& tv, const std::vect
|
||||
|
||||
if (tv.size())
|
||||
{
|
||||
if (highlight_locations[highlight_locations.size()-1] == tv.size() - 1)
|
||||
if (highlight_locations[highlight_locations.size()-1] == (long) (tv.size() - 1))
|
||||
{
|
||||
std::cout << "\033[31m" << *tv[tv.size() - 1].to_math_str() << "\033[0m\n";
|
||||
}
|
||||
|
||||
+985
-506
File diff suppressed because it is too large
Load Diff
+4
-1
@@ -99,7 +99,10 @@ TEST(tree_proper_test_1)
|
||||
TEST(tree_proper_test_2)
|
||||
{
|
||||
std::vector<Expression::Token> o = Parser::tokenize_input("(1**5 * (1-2-3-4-5-6-7-8))");
|
||||
Syntax::post_process(o);
|
||||
if (Syntax::prepare_token_vector(o))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
std::vector<Expression::Operation> ov = Syntax::build_op_vector(o);
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user