Skip to content

How to use different parsers with one input text to make an AST? #1730

Answered by bd82
nathantetro asked this question in Q&A
Discussion options

You must be logged in to vote

Hello @nathantetro

If I get 1 input string (for example: " import x from 'y'; let a = 5; "), how do I know which of the parsers to apply to the different parts of the string?

There is normally some root rule that iterates on these sub-rules of the different parts. e.g:

E.g in Java a program may be:

  • package declaration
  • followed by import declarations
  • followed by class declarations.

This is actually defined in the Java Grammar and would be your root rule if you were implementing a Parser for Java...

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by nathantetro
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants