-2

I read that its possible to do this ,

Will it require backtracking?

What would be the sketch from recovering from the parsing errors .

stringRay2014
  • 636
  • 1
  • 11
  • 29
  • 1
    Can you provide some examples of what you are talking about and specific input data that you believe might show the problem? – Brian Topping Apr 25 '15 at 19:02
  • Is a top down parser the same as a formal grammar? – kpie Apr 25 '15 at 19:07
  • sorry this was just a question I found in a past exam paper and I was curious to know the answer , There is no example though – stringRay2014 Apr 25 '15 at 19:13
  • Do you mean "ungramaticality *in* a string"? As in syntax errors? And what do you mean by "sketch" in the last line? – sepp2k Apr 25 '15 at 20:54
  • @sepp2k Sketch the technique to recover from the parsing error that could occur. – stringRay2014 Apr 25 '15 at 21:26
  • Any parser (top down or not, backtracking or not) "detects ungrammaticality" (OP: this isn't really a valid word). If there are no syntax errors, then by definition the parsed document is grammatical. If there are detected errors, the document is not grammatical. – Ira Baxter May 12 '15 at 03:47
  • The question about "recovering from syntax errors" has been a topic in research literature for 40+ years, with no widely accepted, simple, easy to explain answer. So we can't really address it here. – Ira Baxter May 12 '15 at 03:49

1 Answers1

1

The way a top down parser can detect the ungrammaticality, i.e. the invalidity of an input string is, for example:

if you have the non-terminal A on the top of your stack for instance, and the next token in your input string is the symbol b,

then go to your parse table and go to the row for A, and the column for b, and if there is an empty cell, then the input string is invalid.

A method to recover would be to entry panic mode, where you skip tokens in the input string until you find one in the synchronising set, and then pop A off the stack and continue.

several ways of choosing the synchronising set, it could be follow(A) for example

kujosHeist
  • 810
  • 1
  • 11
  • 25