0
$\begingroup$

Given a grammar for a space delimited list of words:

S     -> word { space word }
word  -> [a-zA-Z]+
space -> [ \t]+

And given the input "Hello World", what token would a peek() operation return?

$\endgroup$
  • 1
    $\begingroup$ Where did you come across this operation? Can you cite the source and the context in which it was used? Did the source define it? I'm not sure there is a standard, accepted meaning for it -- I suspect it might be up to the document where you saw that to define what they meant by that. $\endgroup$ – D.W. Apr 20 '18 at 6:08
  • $\begingroup$ I have seen two answers: 1. Return the current token ("Hello") without advancing the input stream and 2. return the next token ("World") without advancing the input stream. I want to know which definition is most common in compilers. $\endgroup$ – Zippers Apr 20 '18 at 13:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.