0

I just have to build myself some parsers for different computer languages. I thought about using ANTLR but what I really want is to explore this myself because I dislike the idea of generated code (yeah silly I know).

The question is how are compile errors (missing identifiers, wrong token for a certain rule etc.) are handled and represented within ASTs etc.

What I know from compiler lectures is that a parser usually tries to throw away token or try to find the next matching code element (like missing a ';' and so taking the ';' of the next expression).

But then how is this expressed within the AST. Is there some malformed expression object/type? I am a bit puzzled.

I do not want to just reject a certain input but handle it.

Martin Kersten
  • 5,127
  • 8
  • 46
  • 77
  • An interesting question is this. I'm not particularly well versed on parser implementation in compilers. Can you list a couple of examples of situations where [specific] compilers will try to "carry on"? I think maybe some C compilers may give up in a function if there is a syntax error, and go onto following functions if there are any. – RichColours Jan 16 '16 at 20:15
  • 2
    This topic has been covered before on SO. [Here](http://stackoverflow.com/questions/26059547/how-to-create-ast-parser-which-allows-syntax-errors?rq=1)'s one such example. – 500 - Internal Server Error Jan 16 '16 at 20:26

0 Answers0