<!---
Created from:
* the original README file at https://github.com/javacc/javacc
* the documentation https://github.com/javacc/javacc/www
* an example README.md file from https://github.com/apache/flink
-->
# <a name="top"></a>JavaCC
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/net.java.dev.javacc/javacc/badge.svg)](https://maven-badges.herokuapp.com/maven-central/net.java.dev.javacc/javacc)
[![Javadocs](https://www.javadoc.io/badge/net.java.dev.javacc/javacc.svg)](https://www.javadoc.io/doc/net.java.dev.javacc/javacc)
Java Compiler Compiler (JavaCC) is the most popular parser generator for use with Java applications.
A parser generator is a tool that reads a grammar specification and converts it to a Java program that can recognize matches to the grammar.
In addition to the parser generator itself, JavaCC provides other standard capabilities related to parser generation such as tree building (via a tool called JJTree included with JavaCC), actions and debugging.
All you need to run a JavaCC parser, once generated, is a Java Runtime Environment (JRE).
This README is meant as a brief overview of the core features and how to set things up to get yourself started with JavaCC. For a fully detailed documentation, please see [https://javacc.github.io/javacc/](https://javacc.github.io/javacc/).
## <a name="toc"></a>Contents
- [Introduction](#introduction)
* [Features](#features)
* [Example](#example)
* [Tutorials](docs/tutorials/index.md)
* [FAQ](docs/faq.md)
- [Getting Started](#getting-started)
* [Download & Installation](#download)
* [Building JavaCC from Source](#building-from-source)
* [Developing JavaCC](#developing)
- [Community](#community)
* [Support](#support)
* [Documentation](#documentation)
* [Resources](#resources)
* [Powered by JavaCC](#powered-by)
- [License](#license)
## <a name="introduction"></a>Introduction
### <a name="features"></a>Features
* JavaCC generates top-down ([recursive descent](https://en.wikipedia.org/wiki/Recursive_descent_parser)) parsers as opposed to bottom-up parsers generated by [YACC](https://en.wikipedia.org/wiki/Yacc)-like tools. This allows the use of more general grammars, although [left-recursion](https://en.wikipedia.org/wiki/Left_recursion) is disallowed. Top-down parsers have a number of other advantages (besides more general grammars) such as being easier to debug, having the ability to parse to any [non-terminal](https://en.wikipedia.org/wiki/Terminal_and_nonterminal_symbols) in the grammar, and also having the ability to pass values (attributes) both up and down the parse tree during parsing.
* By default, JavaCC generates an `LL(1)` parser. However, there may be portions of grammar that are not `LL(1)`. JavaCC offers the capabilities of syntactic and semantic lookahead to resolve shift-shift ambiguities locally at these points. For example, the parser is `LL(k)` only at such points, but remains `LL(1)` everywhere else for better performance. Shift-reduce and reduce-reduce conflicts are not an issue for top-down parsers.
* JavaCC generates parsers that are 100% pure Java, so there is no runtime dependency on JavaCC and no special porting effort required to run on different machine platforms.
* JavaCC allows [extended BNF](https://en.wikipedia.org/wiki/Extended_Backus%E2%80%93Naur_form) specifications - such as `(A)*`, `(A)+` etc - within the lexical and the grammar specifications. Extended BNF relieves the need for left-recursion to some extent. In fact, extended BNF is often easier to read as in `A ::= y(x)*` versus `A ::= Ax|y`.
* The lexical specifications (such as regular expressions, strings) and the grammar specifications (the BNF) are both written together in the same file. It makes grammars easier to read since it is possible to use regular expressions inline in the grammar specification, and also easier to maintain.
* The [lexical analyzer](https://en.wikipedia.org/wiki/Lexical_analysis) of JavaCC can handle full Unicode input, and lexical specifications may also include any Unicode character. This facilitates descriptions of language elements such as Java identifiers that allow certain Unicode characters (that are not ASCII), but not others.
* JavaCC offers [Lex](https://en.wikipedia.org/wiki/Lex_(software))-like lexical state and lexical action capabilities. Specific aspects in JavaCC that are superior to other tools are the first class status it offers concepts such as `TOKEN`, `MORE`, `SKIP` and state changes. This allows cleaner specifications as well as better error and warning messages from JavaCC.
* Tokens that are defined as *special tokens* in the lexical specification are ignored during parsing, but these tokens are available for processing by the tools. A useful application of this is in the processing of comments.
* Lexical specifications can define tokens not to be case-sensitive either at the global level for the entire lexical specification, or on an individual lexical specification basis.
* JavaCC comes with JJTree, an extremely powerful tree building pre-processor.
* JavaCC also includes JJDoc, a tool that converts grammar files to documentation files, optionally in HTML.
* JavaCC offers many options to customize its behavior and the behavior of the generated parsers. Examples of such options are the kinds of Unicode processing to perform on the input stream, the number of tokens of ambiguity checking to perform etc.
* JavaCC error reporting is among the best in parser generators. JavaCC generated parsers are able to clearly point out the location of parse errors with complete diagnostic information.
* Using options `DEBUG_PARSER`, `DEBUG_LOOKAHEAD`, and `DEBUG_TOKEN_MANAGER`, users can get in-depth analysis of the parsing and the token processing steps.
* The JavaCC release includes a wide range of examples including Java and HTML grammars. The examples, along with their documentation, are a great way to get acquainted with JavaCC.
### <a name="example"></a>Example
This example recognizes matching braces followed by zero or more line terminators and then an end of file.
Examples of legal strings in this grammar are:
`{}`, `{{{{{}}}}}` // ... etc
Examples of illegal strings are:
`{}{}`, `}{}}`, `{ }`, `{x}` // ... etc
#### Grammar
```java
PARSER_BEGIN(Example)
/** Simple brace matcher. */
public class Example {
/** Main entry point. */
public static void main(String args[]) throws ParseException {
Example parser = new Example(System.in);
parser.Input();
}
}
PARSER_END(Example)
/** Root production. */
void Input() :
{}
{
MatchedBraces() ("\n"|"\r")* <EOF>
}
/** Brace matching production. */
void MatchedBraces() :
{}
{
"{" [ MatchedBraces() ] "}"
}
```
#### Output
```java
$ java Example
{{}}<return>
```
```java
$ java Example
{x<return>
Lexical error at line 1, column 2. Encountered: "x"
TokenMgrError: Lexical error at line 1, column 2. Encountered: "x" (120), after : ""
at ExampleTokenManager.getNextToken(ExampleTokenManager.java:146)
at Example.getToken(Example.java:140)
at Example.MatchedBraces(Example.java:51)
at Example.Input(Example.java:10)
at Example.main(Example.java:6)
```
```java
$ java Example
{}}<return>
ParseException: Encountered "}" at line 1, column 3.
Was expecting one of:
<EOF>
"\n" ...
"\r" ...
at Example.generateParseException(Example.java:184)
at Example.jj_consume_token(Example.java:126)
at Example.Input(Example.java:32)
at Example.main(Example.java:6)
```
## <a name="getting-started"></a>Getting Started
Follow the steps here to get started with JavaCC.
This guide will walk you through locally building the project, running an existing example, and setup to start developing and testing your own JavaCC application.
### <a name="download"></a>Download & Installation
JavaCC 7.0.10 is our latest stable release.
* JavaCC 7.0.10 - ([Source (zip)](https://github.com/java
没有合适的资源?快使用搜索试试~ 我知道了~
javacc7.0.10源代码
共490个文件
java:221个
jj:77个
template:49个
需积分: 2 0 下载量 124 浏览量
2023-08-03
14:57:13
上传
评论
收藏 3.44MB ZIP 举报
温馨提示
JavaCC JavaCompilerCompiler 是一个用JAVA开发的最受欢迎的语法分析生成器 这个分析生成器工具可以读取上下文无关且有着特殊意义的语法并把它转换成可以识别且匹配该语法的JAVA程序 JavaCC可以在Java虚拟机 JVM V1 2或更高的版本上。
资源推荐
资源详情
资源评论
收起资源包目录
javacc7.0.10源代码 (490个子文件)
genkey.bat 252B
javacc.bat 94B
jjtree.bat 94B
jjdoc.bat 93B
EG4DumpVisitor.cc 2KB
main.cc 1KB
allmain.cc 1KB
eg4.cc 1KB
eg3.cc 955B
eg2.cc 955B
eg1.cc 763B
ASTMyOtherID.cc 663B
ASTMyID.cc 441B
MyErrorHandler.cc 252B
make_bundle.cmd 551B
build.cmd 25B
contributors 45B
.editorconfig 662B
.gitattributes 410B
.gitignore 668B
.gitignore 44B
EG4DumpVisitor.h 1KB
ASTMyOtherID.h 626B
ASTMyID.h 455B
myparser.h 450B
MyErrorHandler.h 359B
token_base.h 21B
mytm.h 16B
head 0B
javacc.html 99KB
default.html 4KB
package.html 429B
package.html 423B
package.html 412B
package.html 400B
package.html 387B
Hello.idl 71B
maven-ant-tasks-2.1.3.jar 1.26MB
cpptasks.jar 375KB
javacc.jar 282KB
ant-contrib-1.0b3.jar 219KB
junit.jar 118KB
junit.jar 118KB
NfaState.java 108KB
RStringLiteral.java 65KB
ParseEngine.java 64KB
LexGen.java 54KB
LexGenCPP.java 45KB
ParseGen.java 38KB
Semanticize.java 35KB
Options.java 35KB
ParseGenCPP.java 29KB
RCharacterList.java 24KB
NfaStateTest.java 22KB
CPPNodeFiles.java 21KB
JavaFiles.java 21KB
JavaCCGlobals.java 18KB
JJDoc.java 15KB
JavaCodeGenerator.java 14KB
TableDrivenJavaCodeGenerator.java 13KB
CPPCodeGenerator.java 13KB
Main.java 12KB
SimpleCharStream.java 12KB
SimpleCharStream.java 12KB
ModifiedSimpleCharStream.java 12KB
ModifiedOldSimpleCharStream.java 12KB
OldSimpleCharStream.java 12KB
BaseSimpleCharStream.java 12KB
ChangedOptionsSimpleCharStream.java 12KB
CodeGenerator.java 12KB
SimpleCharStream.java 12KB
UnparseVisitor.java 11KB
NodeFiles.java 11KB
OutputFile.java 11KB
LookaheadCalc.java 11KB
BackupCharStream.java 10KB
JavaCCParserInternals.java 10KB
JJTreeState.java 10KB
Obfuscator.java 10KB
SimpleCharStream.java 9KB
OutputFileGenerator.java 9KB
LookaheadWalk.java 8KB
JJTreeOptions.java 8KB
TextGenerator.java 8KB
JJTree.java 8KB
NormalProduction.java 8KB
JJDocMain.java 7KB
CalcGUI.java 7KB
OtherFilesGen.java 7KB
OptionsTest.java 7KB
CalcGUI.java 7KB
Parser.java 7KB
Parser.java 7KB
Parser.java 7KB
XTextGenerator.java 7KB
OtherFilesGenCPP.java 7KB
CPPFiles.java 6KB
HTMLGenerator.java 6KB
ParseException.java 6KB
ParseException.java 6KB
共 490 条
- 1
- 2
- 3
- 4
- 5
资源评论
宁波阿成
- 粉丝: 1w+
- 资源: 11
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功