1 /* |
1 /* |
2 Copyright (c) 2013-2014, Santeri Piippo |
2 Copyright (c) 2014, Santeri Piippo |
3 All rights reserved. |
3 All rights reserved. |
4 |
4 |
5 Redistribution and use in source and binary forms, with or without |
5 Redistribution and use in source and binary forms, with or without |
6 modification, are permitted provided that the following conditions are met: |
6 modification, are permitted provided that the following conditions are met: |
7 |
7 |
53 lexer(); |
53 lexer(); |
54 ~lexer(); |
54 ~lexer(); |
55 |
55 |
56 void process_file (string file_name); |
56 void process_file (string file_name); |
57 bool get_next (e_token req = tk_any); |
57 bool get_next (e_token req = tk_any); |
58 void must_get_next (e_token tok); |
58 void must_get_next (e_token tok = tk_any); |
59 void must_get_any_of (const list<e_token>& toks); |
59 void must_get_any_of (const list<e_token>& toks); |
60 int get_one_symbol (const string_list& syms); |
60 int get_one_symbol (const string_list& syms); |
61 void must_be (e_token tok); |
61 void must_be (e_token tok); |
62 bool peek_next (token* tk = null); |
62 bool peek_next (token* tk = null); |
63 |
63 |
|
64 inline bool has_valid_token() const |
|
65 { |
|
66 return (is_at_end() == false && m_token_position != m_tokens.begin()); |
|
67 } |
|
68 |
64 inline token* get_token() const |
69 inline token* get_token() const |
65 { |
70 { |
66 assert (is_at_end() == false); |
71 assert (has_valid_token() == true); |
67 return & (*m_token_position); |
72 return &(*m_token_position); |
68 } |
73 } |
69 |
74 |
70 inline bool is_at_end() const |
75 inline bool is_at_end() const |
71 { |
76 { |
72 return m_token_position == m_tokens.end(); |
77 return m_token_position == m_tokens.end(); |
73 } |
78 } |
74 |
79 |
75 inline token get_token_type() const |
80 inline e_token get_token_type() const |
76 { |
81 { |
77 return get_token()->type; |
82 return get_token()->type; |
78 } |
83 } |
79 |
84 |
80 // If @tok is given, describes the token. If not, describes @tok_type. |
85 // If @tok is given, describes the token. If not, describes @tok_type. |