Search code examples
javarecursioncompiler-constructionjavacc

What are square brackets used for in JavaCC


guys in JavaCC when I have a non-terminal inside square brackets, for example:

void NonTerminal: {}
{
    [OtherNonTerminal()]
}

void OtherNonTerminal: {}
{
    <TOKEN> [<OTHERTOKEN> OtherNonTerminal()]
}

What do the square brackets around it mean?


Solution

  • [OtherNonTerminal()] is the same as (OtherNonTerminal())? and means that OtherNonTerminal is optional. That is, NonTerminal can either match OtherNonTerminal or nothing.