CUP 解析器生成器 JavaCUP

码农软件 · 软件分类 · 语法解析工具 · 2019-12-12 13:57:53

软件介绍

JavaCUP 是 Java 语言实现的 CUP 解析器生成器。

示例代码:

// Simple Example Scanner Class 
// scanner.java
import java_cup.runtime.*;
import java.io.*;
//import sym;

public class scanner implements java_cup.runtime.Scanner {
  /* single lookahead character */
  protected static int next_char;
  // since cup v11 we use SymbolFactories rather than Symbols
  private SymbolFactory sf = new DefaultSymbolFactory();
  private static FileReader fileReader;
  public scanner(FileReader fr){
      this.fileReader=fr;
  }
  /* advance input by one character */
  protected static void  advance()
    throws java.io.IOException
    { next_char = fileReader.read(); }

  /* initialize the scanner */
  public static void init()
    throws java.io.IOException
    { advance(); }

  /* recognize and return the next complete token */
  public Symbol next_token()
    throws java.io.IOException
    {
      for (;;)
        switch (next_char)
      {
        case '0': case '1': case '2': case '3': case '4': 
        case '5': case '6': case '7': case '8': case '9': 
          /* parse a decimal integer */
          int i_val = 0;
          do {
            i_val = i_val * 10 + (next_char - '0');
            advance();
          } while (next_char >= '0' && next_char <= '9');
        return sf.newSymbol("NUMBER",sym.NUMBER, new Integer(i_val));

        case ';': advance(); return sf.newSymbol("SEMI",sym.SEMI);
        case '+': advance(); return sf.newSymbol("PLUS",sym.PLUS);
        case '-': advance(); return sf.newSymbol("MINUS",sym.MINUS);
        case '*': advance(); return sf.newSymbol("TIMES",sym.TIMES);
        case '/': advance(); return sf.newSymbol("DIVIDE",sym.DIVIDE);
        case '%': advance(); return sf.newSymbol("MOD",sym.MOD);
        case '(': advance(); return sf.newSymbol("LPAREN",sym.LPAREN);
        case ')': advance(); return sf.newSymbol("RPAREN",sym.RPAREN);

        case -1: return sf.newSymbol("EOF",sym.EOF);

        default: 
          /* in this simple scanner we just ignore everything else */
          advance();
        break;
      }
    }
};

 

本文地址:https://codercto.com/soft/d/20988.html

Writing Apache Modules with Perl and C

Writing Apache Modules with Perl and C

Lincoln Stein、Doug MacEachern / O'Reilly Media, Inc. / 1999-03 / USD 39.95

Apache is the most popular Web server on the Internet because it is free, reliable, and extensible. The availability of the source code and the modular design of Apache makes it possible to extend Web......一起来看看 《Writing Apache Modules with Perl and C》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

随机密码生成器
随机密码生成器

多种字符组合密码