2

I am trying to run an example provided by CUP: Parsing directly to XML.

I stored the 'Minijava Grammar' in a file named minijava.cup and the scanner into a file named xml.flex. I ran JFlex to obtain Lexer.java from the xml.flex file. After that I obtained Parser.java and sym.java after running the command specified on the CUP example:

java -jar java-cup-11b.jar -locations -interface -parser Parser -xmlactions minijava.cup

My directory looks like this:

input.xml
java-cup-11b.jar
java-cup-11b-runtime.jar
jflex-1.6.1.jar
Lexer.java
minyjava.cup
Parser.java
sym.java
xml.flex

I am trying to compile the Lexer.java file by using the following command:

javac -cp java-cup-11b-runtime.jar Lexer.java

but I get 47 errrors in the format "..cannot find symbol...". The first ones specify that classes sym and minijava.Constants can't be found.

Lexer.java:17: error: cannot find symbol

public class Lexer implements java_cup.runtime.Scanner, sym, minijava.Constants{

^ symbol: class sym

Lexer.java:17: error: package minijava does not exist

public class Lexer implements java_cup.runtime.Scanner, sym, minijava.Constants {

^ Lexer.java:679: error: cannot find symbol

{return symbolFactory.newSymbol("EOF", EOF, new Location(yyline+ 1,yycolumn+1,yychar), new Location(yyline+1,yycolumn+1,yychar+1));

I do not understand why the sym.java file is not visible to Lexer or where to get the minijava.Constants file.

Community
  • 1
  • 1
Dragos Geornoiu
  • 527
  • 2
  • 8
  • 17

1 Answers1

1

You are missing the current directory (where your sources are) in the classpath. It is not included by default, but if you put . in the %CLASSPATH% (or $CLASSPATH for unices) environment variable.

Try to change the -cp setting to add the current directory ..

javac -cp .;java-cup-11b-runtime.jar Lexer.java

If you are on a GNU/Linux, OS X or any UNIX-like system, it would be

javac -cp .:java-cup-11b-runtime.jar Lexer.java

In the same way, add the current directory to the -cp parameter when running with java command.

Seki
  • 11,135
  • 7
  • 46
  • 70
  • That worked, thank you. I tried something similar previously: "javac -cp .*;java-cup-11b-runtime.jar Lexer.java", but didn't work. Now I get 15 errors that are related to the minijava.Constants, I will try to find where does that example expect me to get it from . – Dragos Geornoiu Apr 20 '16 at 10:07
  • `.*` is not the same than `.`: the first one will search all files of the current directory which in my sense is wrong while `.` adds the current directory for searching the classes. – Seki Apr 20 '16 at 11:37
  • Yeah, I realized that after you answered, I mixed the two in my head and taught each one did the other... – Dragos Geornoiu Apr 20 '16 at 17:41
  • actually, I did a mistake: `.*` will not search all files of the current directory but rather all hidden files of the current directory (in unix-world), and I am not sure for Windows: it seems to look for `.` and `..` but I have not tested the effect. – Seki Apr 21 '16 at 07:32