Recursive in BNF Grammar

Well, I'm not sure how to write a function using recursive parsing to parse the grammar, as shown below. In fact, I'm not sure if I did it right ...

BNF:

 A : B | A '!'
 B : '[' ']'

pseudo code:

f()
{
   if(tok is B) 
      parse_b();
      return somethingB
   else if(????) how will I know if it start of A or I don't need to?
      x = f();
      parse_c();
      return somethingA
}

I did this (there is no check to determine if this is A, but I feel that something is wrong with it):

f()
{
   if(tok is B) 
      parse_b();
      return somethingB
   else
      x = f();
      parse_c();
      return somethingA
}
+4
source share
1 answer

See my SO answer to another similar question for information on how to create a recursive descent parser .

, , , , .

+2

Source: https://habr.com/ru/post/1545009/


All Articles