Is there a rule for detecting errors in Lex / Yacc analysis?

Should we catch errors when parsing a general-purpose language as early as possible (in Lex) or where is it more convenient and provide us with more information (in Yacc)? How do different languages ​​solve this problem?

+3
source share
2 answers

In general, the more complex the error, the more difficult the code to approve the error . Lexers and parsers are fairly simple (in practice) and therefore catch simple errors.

  • Lexers pick up invalid character sequences that must make up the token
  • , Bison/Yacc, , .

. /, . /, , , .

, / ( ) AST .

:

a.b();
ab();

lexer/parser - , . ?

  • , , .

  • ID , , .

.

, . .

+3

, . Token, char, ​​ . , , , .

0

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


All Articles