Create Parser with ANTLR? .g file and main.java
Posted on 2004-03-28
I have the following grammar:
<Expr> ---> (<operator><oplist>)
<oplist> ---> <operand><oplist>
<operand> ---> <Expr> | INT
<operator> ---> + | - | * | /
some sentences in the above grammar are:
(+6 8) //meaning 6+8=14
(* (+ 2 4) (/ 8 2)) //meaning (2+4)*(8/2) = (6)*(4) = 24
(+ 8 2 3 5) //meaning 8+2+3+5 = 18
I have read everything on the ANTLR and have created the sample parsers, etc. but I am having a problem getting my above grammar into the proper format ( .g file) so that I can run
java antlr.Tool aboveGrammar.g
Also, do I have to have some sort of unique code in my main.java to make sure that the parser generated from ANTLR works properly for the type of sentences listed above?
I will increase the points on this question to whomever actually walks me through this process as I have spent 2 days or more already trying to figure it out. Thanks!