Invalid operand to binary expression

How do i fix this?? I need to create a lexical analyzer, however i keep receiving "invalid operands to binary expression" at lines 71 62 59

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

//
//  main.cpp
//  Proj 2
//
//  Created by ---------- on 10/20/16.
//  Copyright © 2016 -----------. All rights reserved.
//

#include <iostream>
#include <fstream>
#include <string>
#include <map>
using namespace std;

#include "p2lex.h"

int linenum = 1;

void usage(const string& cmd, const string& msg )
{
    cout << msg<< endl;
    cout<<"Usage is: " << cmd << "[-v] filename" <<endl;
}

int main(int argc, char * argv[])
{
    istream *f = &cin;
    
    ifstream infile;
    
    bool verboseMode = false;
    
    for(int i = 1; i < argc; i++)
    {
        if(i ==1 && string(argv[i]) == "-v")
            verboseMode = true;
        else{
            if (f != &cin) {
                usage(argv[0], "too many arguments");
                return 1;
            }
            
            infile.open(argv[i]);
            if(infile.is_open())
                f= &infile;
            else{
                usage(argv[0], "Cannot open" + string(argv[i]));
                return 1;
            }
        }
    }
    
    map<TokenType, int> tokencount;
   map<string, int> lexemeCount;
    
    Token tok;
    
    while( (tok = getToken(f)) != TokenType::DONE && tok != TokenType::ERR )
    {
        tokencount[tok.getTok()]++;
        if( tok == TokenType::ID || tok == TokenType::STR || tok == TokenType::INT )
        {
            lexemeCount[tok.getLexeme()]++;
        }
        
        if( verboseMode )
            cout << tok << endl;
    }
    
    if( tok == TokenType::ERR ) {
        cout << tok << endl;
        return 1;
    }
    
Last edited on
Without the declarations of Token and TokenType, its hard to tell. My guess is that TokenType::ERR (or whatever) is not a Token, or that Token does not have an operator== overload.
Topic archived. No new replies allowed.