The first argument to get Next Token is a reference to an is tream that the function should read from. The second argument to get Next Token is a reference to an integer that contains the current line number. get Next Token should update this integer every time it reads a newline. get Next Token returns a Lex. A lex is a class that contains a Token, a string for the lexeme, and the line number that the Token was found on
A header file, lex.h, will be provided for you. It contains a declaration for the Lex class, and a
declaration for all of the Token values. You MUST use the header file that is provided. You may
NOT change it.
The lexical rules of the language are as follows:
1. The language has identifiers, which are defined to be a letter followed by zero or more letters or numbers. This will be the Token ID.
2. The language has integer constants, which are defined to be one or more digits. This will be the Token INT.
3. The language has string constants, which are a double-quoted sequence of characters, all on the same line. This will be the Token STR.
4. A string constant can include escape sequences: a backslash followed by a character. The sequence \n should be interpreted as a newline. The sequence \\ should be interpreted as a backslash. All other escapes should simply be interpreted as the character after the backslash.
5. The language has reserved the keywords print, let, if, loop, begin, end. They will be Tokens PRINT LET IF LOOP BEGIN END.
6. The language has several operators. They are + - * / ! ( ) which will be Tokens PLUS MINUS STAR SLASH BANG LPAREN RPAREN
7. The language recognizes a semicolon as the token SC
8. A comment is all characters from // to the end of the line; it is ignored and is not returned
as a token. NOTE that a // in the middle of an STR is NOT a comment!
Get Free Quote!
318 Experts Online