I really wanted to parse it at work, so I had the opportunity to use a parser generator called JavaCC. This article is a procedure for myself that I read and summarized various things such as Getting Started on the official page when using JavaCC.
Environment We have confirmed the operation in the following environment.
OS | JDK | JavaCC |
---|---|---|
Redhat Enterprise Linux(RHEL) 6 | 1.6 | 6.0 |
macOS Mojave | 1.8 | 6.0 |
Windows 10 | 1.8 | 6.0 |
Reference Official page: Getting Started
Download Download the zip file from the Official Download Site. In my environment, I pressed the link button "Download JavaCC 6.0" and the download started.
Unzip Unzip the downloaded zip file You can unzip it anywhere you have write permission. (I unzipped it under my home directory as follows so as not to damage the environment on the server side.)
${HOME}/usr/local/tools/javacc-6.0
%systemdrive%%homepath%¥usr¥local¥tools¥javacc-6.0
Creating an executable file There is a directory called "bin" in the unzipped directory (folder). The following executable file will be generated here.
#!/bin/bash
java -cp ${HOME}/usr/local/tools/javacc-6.0/bin/lib/javacc.jar javacc "$@"
@ECHO OFF
java -cp %systemdrive%%homepath%¥usr¥local¥tools¥javacc-6.0¥bin¥lib¥javacc.jar javacc %%*
Pass through the path. Add the directory where the executable file is placed to the user environment variable PATH.
export PATH=${PATH}:${HOME}/usr/local/tools/javacc-6.0/bin
set PATH=%PATH%;%systemdrive%%homepath%¥usr¥local¥tools¥javacc-6.0¥bin
Let's test Setup is complete above. Now let's test if it works. (Omitted for Windows)
Linux/Mac(Home directory/home/When hogehoge)
> #First, check that the PATH has passed
> which javacc
/home/hogehoge/usr/local/tools/javacc-6.0/bin/javacc
> #Confirm that javacc can be executed
> javacc
Java Compiler Compiler Version 6.0_1 (Parser Generator)
Usage:
javacc option-settings inputfile
"option-settings" is a sequence of settings separated by spaces.
Each option setting must be of one of the following forms:
...(In reality, you will get a longer message.)