This is a Java grammar for the Lezer parser system.
The grammar used is based in a large part on the corresponding tree-sitter grammar.
The code is licensed under an MIT license.
Java grammar for Lezer
License: MIT License
This is a Java grammar for the Lezer parser system.
The grammar used is based in a large part on the corresponding tree-sitter grammar.
The code is licensed under an MIT license.
JDK compile failed because of too many characters in character literal
If you parse i < c + 1
, you will get an AST that looks like this:
I'm expecting the CompareOp to have a lower precedence than the ArithOp. Looking at tree-sitter grammar, this is indeed the case, ADD
has a higher precedence than REL
.
In the grammar here, you will first notice that the order is reversed (which could have caused some confusion), and it looks like that compare now has a higher precedence than addition.
Lines 1 to 20 in d899688
Can somebody recheck the precedence here? Thank you!
I ran into this issue when working with labels starting with upper case letters. By the specification, this is valid. The grammar defines identifiers as starting with only lower case letters.
This program is accepted by the java compiler.
package tests;
@Deprecated(since = "9")
public class Simple {
private static final String HELLO = "Hello, world!";
public static void main(String[] args) {
System.out.println(HELLO);
Label: for (int i = 0; i < 5; i++) {
if (i == 2)
break Label;
}
}
}
MethodDeclaration(
Modifiers(public,static),
void,
Definition,
FormalParameters(
"(",
FormalParameter(
ArrayType(TypeName,Dimension("[","]")),
Definition
),
")"
),
Block(
"{",
ExpressionStatement(
MethodInvocation(
FieldAccess(Identifier,".",Identifier),
".",
MethodName(Identifier),
ArgumentList("(",Identifier,")")
),
";"
),
ExpressionStatement(Identifier,⚠(":")),
ForStatement(
for,
ForSpec(
"(",
LocalVariableDeclaration(
PrimitiveType,
VariableDeclarator(Definition,AssignOp,IntegerLiteral),
";"
),
BinaryExpression(Identifier,CompareOp,IntegerLiteral),
";",
UpdateExpression(Identifier,UpdateOp),
")"
),
Block(
"{",
IfStatement(if,
ParenthesizedExpression(
"(",
BinaryExpression(Identifier,CompareOp,IntegerLiteral),
")"
),
BreakStatement(break,⚠)
),
ExpressionStatement(Identifier,";"),
"}"
)
),
"}"
)
)
I am working on a tree traversal library for lezer/java and found this definition which was a bit strange for me:
Dimension {
annotation* !array "[" "]"+
}
This leads me to my question: Why is int[]]
a valid syntax in this grammar? Is this intended?
Here's a valid syntax tree parsed by this grammar:
class HelloWorld {
public static void main(String[]] args) {
System.out.println("Hello, World!");
}
}
Program:
└╴ClassDeclaration:
├╴class
├╴Definition: HelloWorld
└╴ClassBody:
├╴{
├╴MethodDeclaration:
│ ├╴Modifiers:
│ │ ├╴public
│ │ └╴static
│ ├╴void
│ ├╴Definition: main
│ ├╴FormalParameters:
│ │ ├╴(
│ │ ├╴FormalParameter:
│ │ │ ├╴ArrayType:
│ │ │ │ ├╴TypeName: String
│ │ │ │ └╴Dimension:
│ │ │ │ ├╴[
│ │ │ │ ├╴]
│ │ │ │ └╴]
│ │ │ └╴Definition: args
│ │ └╴)
│ └╴Block:
│ ├╴{
│ ├╴ExpressionStatement:
│ │ ├╴MethodInvocation:
│ │ │ ├╴FieldAccess:
│ │ │ │ ├╴Identifier: System
│ │ │ │ ├╴.
│ │ │ │ └╴Identifier: out
│ │ │ ├╴.
│ │ │ ├╴MethodName:
│ │ │ │ └╴Identifier: println
│ │ │ └╴ArgumentList:
│ │ │ ├╴(
│ │ │ ├╴StringLiteral: "Hello, World!"
│ │ │ └╴)
│ │ └╴;
│ └╴}
└╴}
(Definition of "Dims" in the official Java 16 documentation)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.