File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -7,9 +7,8 @@ var count 99
77
88for i 0 10 inc
99 for j 10 0 dec
10- echo .
11- # sum neg_j_minus_one -1 $j
12- # sum low 10 $neg_j_minus_one
10+ sum neg_j_minus_one -1 $j
11+ sum low 10 $neg_j_minus_one
1312# mul high $i 10
1413# sum value $high $low
1514# if_lte $value $count
Original file line number Diff line number Diff line change 8787#define REMOVE_METADATA(name) ScriptInstance::removeMetadata(name)
8888
8989// Writes a standard command error message with the command name and line number.
90- #define ERROR(msg) std::cerr << std::endl << "ERROR: '" << COMMAND << "' " << msg << " : " << SOURCE; std::exit(1);
90+ #define ERROR(msg) { std::cerr << std::endl << "ERROR: '" << COMMAND << "' " << msg << " : " << SOURCE; std::exit(1);}
Original file line number Diff line number Diff line change 11#include < command>
22#include < no_op.h>
33
4+ /*
5+ NAME
6+ comments - register comment tokens as no-op commands
7+
8+ SYNOPSIS
9+ # <text>
10+ // <text>
11+ /// <text>
12+
13+ DESCRIPTION
14+ Treats comment-prefixed lines as valid commands that do nothing when
15+ executed.
16+ */
417
518namespace
619{
Original file line number Diff line number Diff line change 11#include < command>
22
3+ /*
4+ NAME
5+ echo - write text to standard output
6+
7+ SYNOPSIS
8+ echo <text>
9+
10+ DESCRIPTION
11+ Expands variables in the provided text and writes the result without
12+ appending a trailing newline.
13+ */
314REGISTER_COMMAND
415{
516 auto output = args;
Original file line number Diff line number Diff line change 11#include < command>
22
3+ /*
4+ NAME
5+ end_for - jump back to the matching for loop
6+
7+ SYNOPSIS
8+ end_for
9+
10+ DESCRIPTION
11+ Uses loop metadata recorded by for to continue iteration or fall through
12+ when the loop is complete.
13+ */
314REGISTER_COMMAND
415{
516 try
Original file line number Diff line number Diff line change 11#include < command>
22
3+ /*
4+ NAME
5+ endl - write a newline to standard output
6+
7+ SYNOPSIS
8+ endl
9+
10+ DESCRIPTION
11+ Flushes a single line ending to standard output.
12+ */
313REGISTER_COMMAND
414{
515 std::cout << std::endl;
616 std::cout.flush ();
7- };
17+ };
Original file line number Diff line number Diff line change 11#include < command>
22#include < findMatch.h>
33
4+ /*
5+ NAME
6+ for - execute a counted loop
7+
8+ SYNOPSIS
9+ for <loop_var> <start> <end> <unary_func>
10+
11+ DESCRIPTION
12+ Iterates from <start> toward the exclusive <end> bound using unary_func,
13+ which must currently be inc or dec. The current value is stored in
14+ <loop_var> for the body of the loop.
15+ */
416REGISTER_COMMAND
517{
618 auto splitArgs = utils::split (args);
Original file line number Diff line number Diff line change 22#include < format>
33#include < split.h>
44
5+ /*
6+ NAME
7+ ret - return from the current script frame
8+
9+ SYNOPSIS
10+ ret <value>
11+
12+ DESCRIPTION
13+ Returns control to the previous stack frame with the given integer status.
14+ If there is no previous frame, the process exits with that status code.
15+ */
516REGISTER_COMMAND
617{
718 try
Original file line number Diff line number Diff line change 11#include < command>
22#include < no_op.h>
33
4+ /*
5+ NAME
6+ scope - register brace tokens as no-op commands
7+
8+ SYNOPSIS
9+ {
10+ }
11+
12+ DESCRIPTION
13+ Treats brace-only lines as valid commands that do nothing when executed.
14+ */
415
516namespace
617{
Original file line number Diff line number Diff line change 1+ #include < command>
2+
3+ /*
4+ NAME
5+ sum - add two integers and store the result
6+
7+ SYNOPSIS
8+ sum <output> <a> <b>
9+
10+ DESCRIPTION
11+ Expands variables in the numeric inputs, adds the two integer values, and
12+ stores the result in <output>.
13+ */
14+ REGISTER_COMMAND
15+ {
16+ auto vars = args;
17+ DEREFERENCE (vars);
18+ const auto & splitVars = utils::split (vars);
19+
20+ if (splitVars.size () != 3 )
21+ ERROR (" requires 3 arguments <output> <a> <b>" );
22+
23+ try
24+ {
25+ const int a = std::stoi (splitVars[1 ].c_str ());
26+ const int b = std::stoi (splitVars[2 ].c_str ());
27+ SET_VARIABLE (splitVars[0 ], std::to_string (a + b));
28+ }
29+ catch (std::exception& e)
30+ {
31+ ERROR (" Input values must be integers" );
32+ }
33+ };
You can’t perform that action at this time.
0 commit comments