-
Notifications
You must be signed in to change notification settings - Fork 0
/
Reader_main.cpp
60 lines (53 loc) · 1.62 KB
/
Reader_main.cpp
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
#include<iostream>
#include<cstdlib>
#include "Token.hpp"
#include "Reader.hpp"
Token readDependencyLine( Reader * reader )
{
Token target = reader->getToken();
if( target.isEOF() )
return target;
if( ! target.isName() ) {
std::cout << "The first token of a dependency line should be a name-token.\n";
exit(1);
}
std::cout << "Target is: " << target.getName() << std::endl;
Token colon = reader->getToken();
if( ! colon.isColon() ) {
std::cout << "Missing colon character on the dependency line.\n";
exit(1);
}
std::cout << "The following file-names depend on the above target.\n";
Token token;
do {
token = reader->getToken();
if( token.isName() )
std::cout << token.getName() << std::endl;
} while( token.isName() ) ;
if( ! token.isEOL() ) {
std::cout << "Dependency line contains a non-name token.\n";
exit(1);
}
return token;
}
int main(int argc, const char *argv[])
{
if( argc != 2 ) {
std::cout << "usage: " << argv[0] << " name-of-input-make-file-to-tokenize.\n";
return 1;
}
std::cout << "Using makefile, " << argv[1] << ".\n";
Reader *reader = new Reader(argv[1]);
while( true ) {
Token token = readDependencyLine(reader);
if( token.isEOF() )
return 0;
token = reader->getToken();
if( ! token.isCommand() ) {
std::cout << "No command found after dependency line.\n";
exit(1);
}
std::cout << "The command is: " << token.getCommand() << std::endl;
}
return 0;
}