Assembler.java 文件源码

java
阅读 30 收藏 0 点赞 0 评论 0

项目:Simulizer 作者:
/**
 * Performs the first stage of assembling a program. But stops once it
 * determines whether the program is valid or not. This is useful when only
 * the validity of the program needs to be known.
 * @param input the program string to assemble
 * @return any problems with the program (empty list if program valid)
 */
public static List<Problem> checkForProblems(String input) {
    StoreProblemLogger log = new StoreProblemLogger();

    input += '\n'; // to parse correctly, must end with a newline

    SimpLexer lexer = new SimpLexer(new ANTLRInputStream(input));
    SimpParser parser = new SimpParser(new CommonTokenStream(lexer));

    // prevent outputting to the console
    lexer.removeErrorListeners();
    parser.removeErrorListeners();

    // try to parse a program from the input
    SimpParser.ProgramContext tree = parser.program();

    ProgramExtractor extractor = new ProgramExtractor(log);
    ParseTreeWalker.DEFAULT.walk(extractor, tree);

    return log.getProblems();
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号