Question: Need some assistance with the token portion. If you could explain it in better terms I would appreciate it . Other info provided for some

Need some assistance with the token portion. If you could explain it in better terms I would appreciate it. Other info provided for some context, but the token portion is what I need help understanding. The token template looks like, just swap greedy with strict for the other one:
template
token_info get_next_token_greedy(ITERATOR begin, ITERATOR end, T delim)
Iterator Algorithms - Statistics and Output
In algos.h, you will need to implement all of the templated functions that were declared in algos.decl.h.
range_sum Iterate over the range provided, add up the elements, and return the sum. This is required to work with iterator
ranges containing any type that can be meaningfully added into a double.
range_avg Iterate over the range provided, add up and count the elements, then calculate and return the average (mean)
as a double.
range_minval Iterate over the range provided, keeping track of the minimum value found. Return that minimum value.
Calling this on an empty range is undefined behavior, so dont worry about handling it.
range_maxval Iterate over the range provided, keeping track of the maximum value found. Return that maximum value.
Calling this on an empty range is undefined behavior, so dont worry about handling it.
range_count Iterate over the range provided, counting the number of elements that occur within the range. Return that count.
token_info This a struct (If youre not familiar with structs, think of them as classes but with everything public by default).
It will be used by the get_next_token_* functions to track where successive calls left off so they can continue until the end.
t_begin - Your functions will be responsible for setting this iterator to point to the beginning of the token found.
t_end - Your functions will be responsible for setting this iterator to point right after the last element of the token found.
t_next - Your functions will be responsible for setting this iterator to point the beginning of the next token, or to then
actual end of the range if there are no further tokens.
begin()- Returns an iterator to the beginning of the token that was found. This is useful because it allows you to use
the range-based for loop on this to iterate over the sub-range represented.
end()- Returns the iterator representing the end of the half-open range representing the token that was found.
get_next_token_strict ( begin, end, delim ), get_next_token_greedy ( begin, end, delim ) These functions
will start at begin and iterate until it either reaches the end iterator, or finds an element in the range that has the value delim.
Your function will be responsible for setting the members of the token_info returned appropriately. The t_begin member
will be set to the iterator representing the beginning of the token, and the t_end member will be set to the location immediately
past the end of the token, or to end if we reach the end of the input range.
The t_next member of the token_info struct returned must point to the beginning of the next token, or to the end of the
range if no more tokens are to be found. How this is determined will be the main difference between the strict and greedy
versions.
begin - Where to begin the search for a delimiter.
end - The end of the range to search. If we reach this, there are no more elements to form tokens with.
delim - the delimiter value, when it is found in the range, it is used to indicate that one token has ended
Strict vs. Greedy For the strict version, every delimiter begins a new token, and a delimiter found immediately after
another delimiter will indicate the presence of a zero-length token. This is useful for situations like tab- or comma-separated
values files, where you want the delimiter to start a new field and would actually like to be able to leave fields blank.
For the greedy version, once a delimiter is found, the next token starts at the next position that is not a delimiter. That
means that if we have several delimiters in a row, they are eaten and do not indicate empty tokens. One time this can be
useful is in handling for whitespace in strings when you dont want the number of spaces to matter, which is the case when
parsing HTML or similar languages.
// Let's do an example tokenizing of integers using 0 as the delimiter
source sequence: {100200300000560789}
strict token 0: {100200300}
strict token 1: {}// empty
strict token 2: {}// empty
strict token 3: {56}
strict token 4: {789}
greedy token 0: {100200300}
greedy token 1: {56}
greedy token 2: {789}
Thanks!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!