简体   繁体   English

Jflex 和 CUP 不适用于 vscode 和 mac

[英]Jflex and CUP not working on vscode and mac

I downloaded jflex by doing brew install jflex everything worked the way it should.我通过执行brew install jflex下载了 jflex,一切正常。

But now when I'm trying to make it work with java_cup.runtime.* .但是现在当我试图让它与java_cup.runtime.*一起工作时。 And I keep getting the errors below我不断收到以下错误

Lexer.java:681: error: cannot find symbol
          { return new java_cup.runtime.Symbol(sym.EOF); }
                                               ^
  symbol:   variable sym
  location: class Lexer

My proffesor said,我的教授说,

"The Symbol class is part of the parser (JavaCUP)'s runtime jar file. You may use it in the lexer simply by setting the classpath to include the jar file from JavaCUP and importing it" “符号 class 是解析器 (JavaCUP) 运行时 jar 文件的一部分。您可以在词法分析器中使用它,只需将类路径设置为包含来自 JavaCUP 的 jar 文件并导入它”

So I made bash file below and did what he said and it is not working.所以我在下面制作了 bash 文件并按照他说的做了,但它不起作用。

#!/bin/bash
jflex MiniJava.jflex
javac -cp "/Users/carlosfield/Desktop/School/csc453/java-cup-bin-11b-20160615/java-cup-11b.jar" Lexer.java
java -cp "/Users/carlosfield/Desktop/School/csc453/java-cup-bin-11b-20160615/java-cup-11b-runtime.jar"  Lexer Factorial.java
rm Lexer*

This is my jflex file这是我的 jflex 文件

import java.util.*;
import java_cup.runtime.*;
%% 
%class Lexer
%cup
%line
%column
%{
private Symbol symbol(int type) {
    return new Symbol(type, yyline, yycolumn);
}
private Symbol symbol(int type, Object value) { 
    return new Symbol(type, yyline, yycolumn, value); 
} 
%} 
WhiteSpace = [ \t\r\n]
Identifier = [a-zA-Z_][a-zA-Z0-9_]*
Integer = 0 | [1-9][0-9]* 
%% 
“+” {  }

The fix for this issue is that if you use %cup in your jflex file you must then make your own sym class which contains public static final int EOF=0 .此问题的解决方法是,如果您在 jflex 文件中使用%cup ,则必须创建自己的符号sym ,其中包含public static final int EOF=0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM