I need to write a file TXT using the syntax of Tokens on JavaCC
Eample: (My Code..)
PARSER_BEGIN(ExaF)
import java.io.*;
public class ExaF
{
public static void main( String[] args )throws ParseException
{
try
{
ExaF analizador = new ExaF( System.in ) ;
An.Prog();
System.out.println("\n\n All Ok");
}
catch(ParseException e)
{
System.out.println(e.getMessage());
System.out.println("\n\n Problem...");
}
}
}
PARSER_END(ExaF)
TOKEN:
{
<GAT: "#" > {System.out.print("00 ");}
| <FIN: ";" > {System.out.print("01 ");}
| <LLA: "{" > {System.out.print("02 ");}
| <LLC: "}" > {System.out.print("03 ");}
}
But i need some like this:
TOKEN:
{
<GAT: "#" > {tex.write("00 ");}
| <FIN: ";" > {tex.write("01 ");}
| <LLA: "{" > {tex.write("02 ");}
| <LLC: "}" > {tex.write("03 ");}
}
I try...
PrintStream stext;
stext = new PrintStream(new File("3S.txt"));
stext.print("00 ");
and...
File sfile=new File("3S.txt");
FileWriter texto = new FileWriter(sfile,true);
texto.write("00 ");
texto.close();
Any idea??? JavaCC says:
javac:821: error: cannot find simbol stext.print("00 ");
Since stext is used in the token manager you should declare it as follows
TOKEN_MGR_DECLS: {
PrintStream stext = new PrintStream(new File("3S.txt"));
}
Having done that, you will be able to use stext in token actions. Consult the documentation at https://javacc.java.net/doc/javaccgrm.html#prod12 for more information.