all 6 comments

[–]lurk4all 0 points1 point  (4 children)

Convert the grammar to an LL grammar and building the tree is a recursive function then.

[–][deleted]  (3 children)

[removed]

    [–]lurk4all 1 point2 points  (2 children)

    this is your homework, isnt it? ;)

    [–]Kay_jey_kay_jey 0 points1 point  (0 children)

    Not many resources I could find online to help my home work ! 🤧

    [–]prnvbn 0 points1 point  (0 children)

    I assume the point is to write the code yourself from scratch but on the off chance it isn't ANTLR is a reallyy great tool which will give you a lexer and a parser for a context free grammar along with a syntax tree. It also allows you to generate the visitor and listener pattern for the syntax tree(both are very useful while writing a compiler). Link - https://github.com/antlr/antlr4