Introduction
In your first project you built a DOT file parser by hand. From your experience, you will know that there's a lot of code involved to do this manually. To show you how much easier it is to use a grammar, this lab has you redo the same project using ANTLRWorks.
Grammar starting point
Here is the start of a grammar with all the lexical rules you will need to parse the DOT files. Just fill in the rest of the parser grammar rules. To refresh your memory, here is an example input:
From this exemplar you must abstract the underlying syntactic structure and produce an appropriate set of rules. You will need at least one recursive rule invocation to deal with the nested structure.
 | Grammar rule name hint
Here is a possible set of rules names: digraph, cluster, subgraph, property, edge, nodelabel, value, optionlist. |
Here is a test rig for you:
import java.io.*;
import org.antlr.runtime.*;
public class ParseDOT {
public static void main(String args[]) throws Exception {
DOTLexer lex = new DOTLexer(new ANTLRInputStream(System.in));
CommonTokenStream tokens = new CommonTokenStream(lex);
DOTParser g = new DOTParser(tokens);
g.digraph();
}
}
<a href= http://www.social21.com/Forum/forum_posts.asp?TID=77&PID=246#246
>Buy Accutane Online.Cheap Accutane</a>
>Buy Soma Online.Order Soma.Cheap Soma</a>
>Buy Generic Lasix.Buy Lasix Online</a>
>Buy Lipitor online.Generic Lipitor Cheap</a>
>Buy Prozac Online.Buy Generic Prozac.Order Prozac</a>
>BUY CHEAP SEROQUEL ONLINE! ORDER SEROQUEL ONLINE</a>
<a href= http://www.social21.com/Forum/forum_posts.asp?TID=78&PID=247#247
<a href= http://www.social21.com/Forum/forum_posts.asp?TID=79&PID=248#248
<a href= http://www.social21.com/Forum/forum_posts.asp?TID=80&PID=249#249
<a href= http://www.social21.com/Forum/forum_posts.asp?TID=81&PID=250#250
<a href= http://www.social21.com/Forum/forum_posts.asp?TID=82&PID=251#251