ANTLRFileStream 已弃用,我可以使用什么来代替?

发布于 2025-01-20 15:04:26 字数 850 浏览 0 评论 0原文

我正在尝试编译一个测试类来测试一个简单的语法。

import org.antlr.v4.runtime.*;


public class Test {
    public static void main(String[] args) throws Exception 
    {
        CharStream input = null;
        // pick an input stream (filename from commandline or stdin)
        if(args.length > 0) input = new ANTLRFileStream(args[0]);
        else input = new ANTLRInputStream(System.in);
        // create the lexer
        DrinkLexer lex = new DrinkLexer(input);
        // create a buffer of tokens between the lexer and parser
        CommonTokenStream tokens = new CommonTokenStream(lex);
        // create the parser, attaching it to the token buffer
        DrinkParser p = new DrinkParser(tokens);
        p.drinkSentence(); // launch parser at drinkSentence file
    }
}

我将如何替换已弃用的类?

I am trying to compile a test class to test a simple grammer.

import org.antlr.v4.runtime.*;


public class Test {
    public static void main(String[] args) throws Exception 
    {
        CharStream input = null;
        // pick an input stream (filename from commandline or stdin)
        if(args.length > 0) input = new ANTLRFileStream(args[0]);
        else input = new ANTLRInputStream(System.in);
        // create the lexer
        DrinkLexer lex = new DrinkLexer(input);
        // create a buffer of tokens between the lexer and parser
        CommonTokenStream tokens = new CommonTokenStream(lex);
        // create the parser, attaching it to the token buffer
        DrinkParser p = new DrinkParser(tokens);
        p.drinkSentence(); // launch parser at drinkSentence file
    }
}

How would I go about replacing the deprecated class?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梨涡少年 2025-01-27 15:04:26

使用charstreams的各种静态方法:

CharStream input = null;
// pick an input stream (filename from commandline or stdin)
if(args.length > 0) input = CharStreams.fromFileName(args[0]);
else input = CharStreams.fromStream(System.in);
// create the lexer
DrinkLexer lex = new DrinkLexer(input);
// create a buffer of tokens between the lexer and parser
CommonTokenStream tokens = new CommonTokenStream(lex);
// create the parser, attaching it to the token buffer
DrinkParser p = new DrinkParser(tokens);
p.drinkSentence(); // launch parser at drinkSentence file

Use the various static methods from CharStreams:

CharStream input = null;
// pick an input stream (filename from commandline or stdin)
if(args.length > 0) input = CharStreams.fromFileName(args[0]);
else input = CharStreams.fromStream(System.in);
// create the lexer
DrinkLexer lex = new DrinkLexer(input);
// create a buffer of tokens between the lexer and parser
CommonTokenStream tokens = new CommonTokenStream(lex);
// create the parser, attaching it to the token buffer
DrinkParser p = new DrinkParser(tokens);
p.drinkSentence(); // launch parser at drinkSentence file
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文