Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Since when is RTFM an answer? Anyways. What you are trying to do is not at all easy, since Java is context free (type-2). Try, for starters writing a syntax-analyser for a language of type-3 (<a href="http://en.wikipedia.org/wiki/Chomsky_hierarchy" rel="nofollow">Chomsky Hierarchy</a>). But I'll try to explain to you what you'd need to do anyways.</p> <p>You would have to define rules for Java which look like that (in my example I'll define a function within a java class, where lowercase letters are terminals and uppercase letters are non-terminals). Terminals cannot be derived any further while non-terminals can.</p> <p>X -> Y means X derives to Y. X -> Y | Z means X derives either to Y or Z.</p> <p>f is any name. t is a Type, this would not be a terminal, if I'd try to go all the way, but since I define types to be non-declarable to make my life less of a pain, it's a terminal. '(', ')', '{', '}', ',' and ' ' are terminals. Eps is Epsilon and means nothing.</p> <pre><code>S -&gt; K t f(T) { N } T -&gt; t f | t f , T F -&gt; F, f | f K -&gt; k K | k N -&gt; L N | L L -&gt; f(F); </code></pre> <p>With this I could parse </p> <pre><code>final boolean equals(Object obj) { compare(this, obj); compare(obj, this); } </code></pre> <p>Which would result in: </p> <pre><code>S -&gt; K t f(T) { N } with K -&gt; k -&gt; k t f(T) { N } with T -&gt; t f -&gt; k t f(t f) { N } with N -&gt; L N -&gt; k t f(t f) { L N } with L -&gt; f(F); -&gt; k t f(t f) { f(F); N } with F -&gt; f, F -&gt; k t f(t f) { f(f, F); N } with F -&gt; f -&gt; k t f(t f) { f(f, f); N } with N -&gt; L -&gt; k t f(t f) { f(f, f); L } with L -&gt; f(F) -&gt; k t f(t f) { f(f, f); f(F) } ... -&gt; k t f(t f) { f(f, f); f(f, f); } -&gt; k (=final) t(=boolean) f(=equals) (t(=Object) f(=obj)) { ... } </code></pre> <p>Which proves that S defines my simplyfied java (Well it doesn't, but at least I gave an example). So the next thing we have to do is figure out how to get a syntax-tree out of these rules. </p> <p>Thankfully, this is the easy part, because all you have to do is change the lines to be a tree. So S has children K t f(T) { N }. K has children K and k... Uppercase means a Node has children, Lowercase says it doesn't.</p> <p>Last problem, you do not start with S but you start with the code already being written. Which leaves you with</p> <pre><code>K t f(T) { N } -&gt; S t f -&gt; T t f , T -&gt; T F, f -&gt; F f -&gt; F k K -&gt; K k -&gt; K L N -&gt; N N -&gt; L f(F); -&gt; L </code></pre> <p>Parsing in reverse would look like this:</p> <pre><code>final boolean equals(Object obj) { compare(this, obj); compare(obj, this); } final -&gt; k boolean -&gt; t equals -&gt; f Object -&gt; t obj -&gt; f compare -&gt; f this -&gt; f k t f(t f) { f(f, f); f(f,f); } with k -&gt; K K t f(t f) ... with t f -&gt; T K t f(T) ... ... </code></pre> <p>Which would build the tree from down below.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload