source-academy / java-slang

Implementation of the Java language in TypeScript
Apache License 2.0
1 stars 0 forks source link

Java parser to generate custom AST #8

Closed 1001mei closed 10 months ago

1001mei commented 11 months ago

Background

The java parser library currently being used returns a concrete syntax tree (CST). The process of converting it into an abstract syntax tree (AST) takes much effort and is complicated by the fact that it does not following Java Language Specification (JLS) faithfully. For example, the precedence of * over + in the expression 1 + 2 * 3 is not reflected in the CST output.

In an attempt to get rid of above hassles, this PR uses a parser generator pegjs to generate a Java parser that can return a custom AST. The references used are as follows:

Work Done

1001mei commented 10 months ago

Seems like we will be continue using java-parser library, so will close this PR and parser branch will be used for my own exploration.