A
A
Anton Medvedev2014-09-26 15:56:38
Algorithms
Anton Medvedev, 2014-09-26 15:56:38

How to create an AST parser that allows for syntax errors?

For starters, how are AST (Abstract Syntax Tree) trees actually built? What to read?
How to create a parser for a language like SQL that generates an AST tree and forgives syntax errors?
Example: "3+4*5":

+
 / \
3   *
   / \
  4   5

But if the user made a mistake "3+4*+", the parser still tries to understand what the user meant:
+
 / \
3   *
   / \
  4   +
     / \
    ?   ?

Where to begin? Thank you!
SQL:
---SELECT_________________
   /           \           \
  .           FROM        JOIN
 / \           |         /    \
a city_name  people   address  ON
                                |
                                =______________
                               /               \
                              .____             .
                             /     \           / \
                            p  address_id     a  id

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2014-09-26
@Elfet

For starters, how are AST (Abstract Syntax Tree) trees actually built? What to read?

Dragon book.
Provide grammar rules for describing syntax errors and recovering from them. In bison, for example, there is an "error" token for this.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question