I made a simple javacc parser to print text in the command prompt:
options
{
static = true;
}
PARSER_BEGIN(Printer)
package test2;
import java.io.*;
public class Printer
{
public static void main(String args []) throws ParseException
{
Printer parser = new Printer(System.in);
parser.parse(System.out);
}
}
PARSER_END(Printer)
SKIP:
{
"\n"
| "\r"
| "\r\n"
}
TOKEN:{
< PRINT: "print" >
| < STR: (["a"-"z"] | ["A"-"Z"])* >
}
void parse(PrintStream ps) :
{
Token t;
}
{
(< PRINT > " " t = < STR >
{
System.out.println(t.image);
})
}
But the problem is that it can not print any characters other than a-z. How do I bring it to print all unicode characters.
you need to specify UNICODE_INPUT = true; option in your parser. Also regarding STR token you need to modify your regular expression to detect any text you want.
Hope this helps :)
I solved the problem and this is how the code looks now: