예제 #1
0
  @Override
  public int yylex() throws IOException {
    for (; ; ) {
      PPDefs.Token<Symbol> ppt;
      do ppt = m_prepr.nextToken();
      while (ppt.code() == Code.NEWLINE || ppt.code() == Code.WHITESPACE);

      m_startPos = new Position(ppt.fileName, ppt.line1, ppt.col1);
      m_endPos =
          new Position(ppt.fileName2 != null ? ppt.fileName2 : ppt.fileName, ppt.line2, ppt.col2);

      Code code = ppt.code();
      // m_yylval = null;
      m_yylval = code;

      switch (code) {
        case IDENT:
          {
            Symbol sym = ppt.symbol();
            Code kw = sym.keyword;
            if (kw != null) {
              code = kw;
              m_yylval = code;
            } else {
              if (sym.topDecl != null && sym.topDecl.sclass == Types.SClass.TYPEDEF) {
                code = Code.TYPENAME;
                m_yylval = sym.topDecl;
              } else m_yylval = sym;
            }
          }
          break;

        case EOF:
          return CParser.Lexer.EOF;

        case CHAR_CONST:
          code = Code.INT_NUMBER;
          m_yylval = ppt.getCharConstValue();
          break;

        case INT_NUMBER:
          m_yylval = ppt.getIntConstValue();
          break;

        case REAL_NUMBER:
          m_yylval = ppt.getRealConst();
          break;

        case STRING_CONST:
          m_yylval = ppt.getStringConstValue();
          break;

        case WIDE_CHAR_CONST:
        case WIDE_STRING_CONST:
          m_reporter.error(ppt, "Wide characters not supported");
          continue;

        default:
          int ord = ppt.code().ordinal();
          if (ord >= Code.HASH.ordinal()) {
            m_reporter.error(ppt, "Unrecognized symbol '%s'", ppt.outputString());
            continue;
          }
          break;
      }

      return code.ordinal() + 257;
    }
  }
예제 #2
0
 public final void close() {
   m_prepr.close();
 }