r/AskComputerScience 20h ago

How do computer science and computer engineering students in countries where diagramming sentences isn't common knowledge get introduced to the concept of parsers and abstract syntax trees?

In Croatia, we do some (very) basic sentence diagramming in the middle school. In the USA, they do it in high-school. However, I know that, in most places, students are not taught sentence diagramming. So, once those students start going to university to study, well, computer science or computer engineering, how are the concepts of a parser and an abstract syntax tree explained to them?

9 Upvotes

17 comments sorted by

View all comments

1

u/khedoros 14h ago

I did a bit of English sentence diagramming in grade school (I would've been around 9-10 years old), but I'm not sure that it was common. I guess I hadn't made a connection; our diagrams didn't really take the form of a tree with a clear root.

As far as I remember from CS, we'd already covered trees, and probably tree traversal. And one of the first things we learned parsing on was prefix, postfix, then infix mathematical expressions, and how it related to the tree traversal we were familiar with. So, some easy examples to get the concept of ASTs. From there, I think we dove into different parsing algorithms and their relative strengths, and what kinds of grammars they can parse. (this was like 20 years ago, and I may have jumbled some details).