Simple grammar in javacc

It's been 4 years since i have taken a compiler class. I am now trying to create a parser, and I am using javacc for creating the grammar. I will try to demonstrate my problem in the following simple scenario: Let's suppose I need a grammar to read any number of numbers and/or letters, but also to be able and recognize "(" set of characters ")". I have tried something like:

Expression() :
{
<WORD>
| <NUM>
| "(" Foo() ")"
}

Foo() :
{
"0"
| "A"
}

The problem here is that it refuses to recognize exactly what I need since I get a warning that 0 and A will be treated as NUM and WORD respectively. What is the best way to tackle this? Also can someone please give me an example of a recursive rule? Is that even possible? By recursive I refer to the rule calling itself, something like:

Foo() :
{
Foo() ( Foo() )*
}
epitsiAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

humanonomicsCommented:
you mean to say that you want to implement a Grammar mechanism in Java ?
Can you please elaborate more on your needs ?
0
epitsiAuthor Commented:
I will try to keep it as simple as it gets then. I need a javacc file which will be able to parse any text and output it, unless it sees "(0)" in which case it will output "found". For example:

Input: a012(0)
Output: a012found
0
humanonomicsCommented:
What I meant was you want a Java program to do the parsing ?
0
epitsiAuthor Commented:
If it would be more straightforward to write a Java program than using javacc then that would also work.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Languages-Other

From novice to tech pro — start learning today.