Exemple #1
0
 private void expect(int type)
 {
     lastToken = ts.advance();
     if (lastToken.type != type)
     {
         throw new Exception("Expected type " + token2str[type] + " but received type " + token2str[lastToken.type]);
     }
 }
Exemple #2
0
        public virtual PToken advance()
        {
            PToken ans = nextToken;

            if (tokenTrace)
            {
                Console.WriteLine(ans.ToString());
            }

            // Call yylex to get the next token for use by peek()
            var type = scanner.yylex();

            if (type == 7 || type == 8 || type == 9)  // These are token classes (identifiers and numbers),
                                                      // text of token is needed for semantics
            {
                nextToken = new PToken(type, scanner.yytext);
            }
            else
            {
                nextToken = new PToken(type);
            }
            return(ans);
        }