Skip to content

The muNode class is a hierarchical structure implemented in C++, designed to work with the muParser library. This class is particularly useful for reading and processing text files that contain conditions, expressions, variables, commands, while loops and more.

Notifications You must be signed in to change notification settings

krcwrhvgyxzqelljes/muNode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

muNode Class with muParser Integration

The muNode class is a hierarchical structure implemented in C++, designed to work with the muParser library. This class is particularly useful for reading and processing text files that contain conditions, expressions, variables, commands, while loops and more.

The muParser library is a lightweight and fast C++ mathematical expression parser. It is designed to perform mathematical computations and evaluations of complex mathematical expressions efficiently. Here's a detailed

The muNode class integrates the muParser library to achieve a comprehensive and robust interpreter for the text files. It combines hierarchical structure management with powerful mathematical expression and condition evaluation capabilities provided by muParser. This integration allows the muNode class to function as a program interpreter capable of executing complicated tasks specified in the input text files.

Dependencies

Features

  • Hierarchical Structure: Nodes can have parent and child nodes.
  • Expression Evaluation: Evaluate mathematical expressions using the muParser library.
  • Condition Evaluation: Evaluate conditions to control the flow of execution.
  • Variable Handling: Add and manage variables in the muParser instance associated with the node.
  • Command Retrieval: Retrieve the command associated with the node.
  • Debugging: Print nodes.
  • Node Navigation: Navigate through nodes using functions like getNextNode(), getPreviousNode(), and more.

Example from main()

sample text file "file.txt" generated by the muText class:

    std::string str = "# this is a comment line\n";
    str += "$x=0\n";
    str += "$y=0\n";
    str += "$z=0\n";
    str += "G0 X0 Y0 Z0\n";
    str += "<subroutine.txt>\n";
    str += "while(x<2){\n";
    str += "    x=x+1\n";
    str += "    G0 X[x] Y[y] Z1\n";
    str += "    while(y<2){\n";
    str += "        y=y+1\n";
    str += "        G2 X[x] Y[y] Z3\n";
    str += "        <subroutine.txt>\n";
    str += "        while( z<2 ){\n";
    str += "            z=z+1\n";
    str += "            G3 X[x] Y[y] Z[z]\n";
    str += "        }\n";
    str += "    }\n";
    str += "}\n";
    str += "G0 X0 Y0 Z0\n";
    str += "M30\n";

sample subroutine file "subroutine.txt" generated by the muText class:

    std::string str = "M3\n";
    str += "G0 X1.5 Y1.5 Z8.0\n";
    str += "G0 X[x] Y[y] Z10\n";
    str += "G1 X[x+5] Y[y+5] Z25\n";
    str += "M5\n";

execute file in main()

#include "munode.h"
#include "mutext.h"

int main() {
	mu::Parser parser;
	std::map<std::string, double*> varmap;
	
	muText().create_sample_file();
	muText().create_sample_subroutine_file();
	
	muNode *node=muText().read_file_into_nodes_text("file.txt");
	muText().process_nodes(node,varmap);
	muText().process_nodes_nr(node);
	muText().print_varmap(varmap);
	
	muText().set_varmap_to_parser(varmap,parser);
	muText().print_parser_varmap(parser);
	
	node->printhierarchy(0);
	
	muNode* N = node;
	while(N->isValid(N)){ 
    	N= N->getNextNodeByCondition(parser);
    	N->printNode(parser);
	}
	return 0;
}

output variables, node hierarchy, and node execution by condition flow :

📜 Initial Variable Map:
	Key: x, Value: 0
	Key: y, Value: 0
	Key: z, Value: 0

🔍 Parser Variable Map:
	Key: x, Value: 0
	Key: y, Value: 0
	Key: z, Value: 0

🌳 Node Hierarchy:
└── Node 0, Condition: , Expression: , Text: Topology file node.
    ├── Node 1, Condition: , Expression: , Text: # this is a comment line 
    ├── Node 2, Condition: , Expression: , Text: $x=0 
    ├── Node 3, Condition: , Expression: , Text: $y=0 
    ├── Node 4, Condition: , Expression: , Text: $z=0 
    ├── Node 5, Condition: , Expression: , Text: G0 X0 Y0 Z0 
    ├── Node 6, Condition: , Expression: , Text: <subroutine.txt> 
    │   ├── Node 7, Condition: , Expression: , Text: Topology file node.
    │   │   ├── Node 8, Condition: , Expression: , Text: M3 
    │   │   ├── Node 9, Condition: , Expression: , Text: G0 X1.5 Y1.5 Z8.0 
    │   │   ├── Node 10, Condition: , Expression: , Text: G0 X[x] Y[y] Z10 
    │   │   ├── Node 11, Condition: , Expression: , Text: G1 X[x+5] Y[y+5] Z25 
    │   │   └── Node 12, Condition: , Expression: , Text: M5 
    ├── Node 13, Condition: x<2, Expression: x=x+1, Text: while(x<2){ x=x+1 
    │   ├── Node 14, Condition: , Expression: , Text: G0 X[x] Y[y] Z1 
    │   ├── Node 15, Condition: y<2, Expression: y=y+1, Text: while(y<2){ y=y+1 
    │   │   ├── Node 16, Condition: , Expression: , Text: G2 X[x] Y[y] Z3 
    │   │   ├── Node 17, Condition: , Expression: , Text: <subroutine.txt> 
    │   │   │   ├── Node 18, Condition: , Expression: , Text: Topology file node.
    │   │   │   │   ├── Node 19, Condition: , Expression: , Text: M3 
    │   │   │   │   ├── Node 20, Condition: , Expression: , Text: G0 X1.5 Y1.5 Z8.0 
    │   │   │   │   ├── Node 21, Condition: , Expression: , Text: G0 X[x] Y[y] Z10 
    │   │   │   │   ├── Node 22, Condition: , Expression: , Text: G1 X[x+5] Y[y+5] Z25 
    │   │   │   │   └── Node 23, Condition: , Expression: , Text: M5 
    │   │   │   └── Node 24, Condition: z<2, Expression: z=z+1, Text: while( z<2 ){ z=z+1 
    │   │   │       └── Node 25, Condition: , Expression: , Text: G3 X[x] Y[y] Z[z] } } } 
    ├── Node 26, Condition: , Expression: , Text: G0 X0 Y0 Z0 
    └── Node 27, Condition: , Expression: , Text: M30 

🚀 Node Execution by Condition Flow:
	name:Node 1	command:
	name:Node 2	command:
	name:Node 3	command:
	name:Node 4	command:
	name:Node 5	command:G0 X0 Y0 Z0 
	name:Node 6	command:<subroutine.txt> 
	name:Node 7	command:Topology file node.
	name:Node 8	command:M3 
	name:Node 9	command:G0 X1.5 Y1.5 Z8.0 
	name:Node 10	command:G0 X0.000 Y0.000 Z10 
	name:Node 11	command:G1 X5.000 Y5.000 Z25 
	name:Node 12	command:M5 
	name:Node 13	command:
	name:Node 14	command:G0 X1.000 Y0.000 Z1 
	name:Node 15	command:
	name:Node 16	command:G2 X1.000 Y1.000 Z3 
	name:Node 17	command:<subroutine.txt> 
	name:Node 18	command:Topology file node.
	name:Node 19	command:M3 
	name:Node 20	command:G0 X1.5 Y1.5 Z8.0 
	name:Node 21	command:G0 X1.000 Y1.000 Z10 
	name:Node 22	command:G1 X6.000 Y6.000 Z25 
	name:Node 23	command:M5 
	name:Node 24	command:
	name:Node 25	command:G3 X1.000 Y1.000 Z1.000    
	name:Node 24	command:
	name:Node 25	command:G3 X1.000 Y1.000 Z2.000    
	name:Node 24	command:
	name:Node 15	command:
	name:Node 16	command:G2 X1.000 Y2.000 Z3 
	name:Node 17	command:<subroutine.txt> 
	name:Node 18	command:Topology file node.
	name:Node 19	command:M3 
	name:Node 20	command:G0 X1.5 Y1.5 Z8.0 
	name:Node 21	command:G0 X1.000 Y2.000 Z10 
	name:Node 22	command:G1 X6.000 Y7.000 Z25 
	name:Node 23	command:M5 
	name:Node 24	command:
	name:Node 15	command:
	name:Node 13	command:
	name:Node 14	command:G0 X2.000 Y2.000 Z1 
	name:Node 15	command:
	name:Node 13	command:
	name:Node 26	command:G0 X0 Y0 Z0 
	name:Node 27	command:M30 

About

The muNode class is a hierarchical structure implemented in C++, designed to work with the muParser library. This class is particularly useful for reading and processing text files that contain conditions, expressions, variables, commands, while loops and more.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published