-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShell.h
75 lines (58 loc) · 2 KB
/
Shell.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#ifndef _Shell_h_
#define _Shell_h_
/** @file Shell.h
* Definition of class Shell.
*/
#include <iostream> // std::istream
#include "Sequence.h" // class Sequence
#include "Token.h" // class Token
/** @class Shell
* This class is the main command line interpreter.
*/
class Shell
{
private:
std::istream & input; // The input stream to be read
Token * tp; // The current token during parsing
public:
/// Construct a shell that will execute commands
/// entered via the given istream.
/// @param input The input stream to read
Shell(std::istream& input); // initialize
/// The main function of the shell.
/// It will prompt the user for a command;
/// Then it calls the internal 'parse()' method
/// to parse the input line, building a matching
/// Sequence datastructure;
/// Then it calls the internal 'execute()' command
/// to have the commandline executed.
/// This cycle is repeated until end of input
/// or some error occurs.
void main();
protected:
// Note: this section was only made protected
// so doxygen will add it to the documentation
/// Parses one line of input.
/// It builds a sequence of pipelines.
/// @return The sequence of pipelines to execute
/// @note This is a, slightly modified,
/// <a target='info'
/// href='http://en.wikipedia.org/wiki/Recursive_descent_parser'>recursive-descent parser</a>.
Sequence *parse();
/// Executes the a pipeline-sequence build by 'parse()'.
/// @param sequence The sequence of pipelines to execute.
/// @return The final exit status of the command.
void execute( Sequence *sequence );
// The LL(1) recursived-descend parser functions
void parseSequence(Sequence *sp);
void parsePipeline(Pipeline *pp);
void parseCommand(Command *cp);
bool parseIORedirection(Command *cp);
void parseInput(Command *cp);
void parseOutput(Command *cp);
void parseAppend(Command *cp);
void proceed();
// TODO: Add any other methods you need
};
// vim:ai:aw:ts=4:sw=4:
#endif /*_Shell_h_*/