c++ - Undefined reference to the function -
it seems can't compile project because of linking error, can't find it. have parser class methods scanner class used. , complier marks every entry of function scanner's public section (get_token(), get_line(), scanner(const char ), ~scanner()) in parser.h or parser.cpp linking error ("undefined reference scanner::"). please, me problem, because have no idea might've caused it. here code. parser.h:
#ifndef parser_h_included #define parser_h_included #include "scanner.h" #include <iostream> class parser { scanner s; token cur_token; void next_token(); void parse_p_expr(); void parse_term(); void parse_statements(); void parse_statement_id(); void parse_children(); void parse_children_term(); public: parser(const char *); }; #endif // parser_h_included
scanner.h:
#ifndef scanner_h_included #define scanner_h_included #include <fstream> #include <string> #include "token.h" class scanner { enum type_of_state { h, id, string, operation }; type_of_state state; static const char *reserved_words[]; static const char *operations[]; std::string buf; size_t line; int c; file *f; void add(); void clear(); void get(); int search(std::string, const char **); void unget(); public: token get_token(); size_t get_line(); scanner(const char *); ~scanner(); }; #endif // scanner_h_included
and scanner.cpp:
#include "scanner.h" const char *scanner::reserved_words[] = { "loop", "else", "when", "print", "println", "die", 0 }; const char *scanner::operations[] = { "::", "<-", "||", 0 }; void scanner::add() { buf += c; } void scanner::clear() { buf = ""; } void scanner::get() { c = fgetc(f); } int scanner::search(std::string buf, const char **list) { int = 0; while (list[i]) { if (buf == list[i]) return + 1; ++i; } return 0; } void scanner::unget() { ungetc(c, f); } size_t scanner::get_line() { return line; } scanner::scanner(const char *text) { f = fopen(text, "r"); if (f == 0) throw scanner_exception(wrong_filename); line = 1; state = h; clear(); get(); } scanner::~scanner() { fclose(f); } token scanner::get_token() { state = h; int i; { switch(state) { case h: if (c == '\n') { get(); ++line; } else if (c == ' ' || c == '\r' || c == '\t') { get(); } else if (isalpha(c)) { clear(); add(); get(); state = id; } else if (c == '"') { clear(); get(); state = string; } else if (c == ':' || c == '<' || c == '|') { clear(); add(); get(); state = operation; } else if (c == '(') { get(); return token(token::lbracket); } else if (c == ')') { get(); return token(token::rbracket); } else if (c == ';') { get(); return token(token::semicolon); } else if (c == '@') { return token(token::end); } else throw scanner_exception(c, line, "unexpected symbol"); break; case id: if (isalpha(c) || isdigit(c) || c == '_') { add(); get(); } else if (i = search(buf, reserved_words)) { return token((token::type_of_token) i, buf); } else return token(token::id, buf); break; case string: if (c == '\n' || c == '@') { throw scanner_exception(c, line, "unexpected end of string"); } if (c != '"') { add(); get(); } else { get(); return token(token::string, buf); } break; case operation: add(); if (i = search(buf, operations)) { get(); return token((token::type_of_token) (i + token::colon)); } else if (buf[0] == ':') { unget(); return token(token::colon); } else throw scanner_exception(c, line, "unexpected symbol"); break; } } while (true); }
Comments
Post a Comment