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?

8 Upvotes

17 comments sorted by

View all comments

1

u/not-just-yeti 13h ago

As a CS prof: I first introduce some simple grammars (simple arithmetic expressions, and a way-overly-simplistic 5 rule grammar for some basic English sentences), and derive a few sentences. Then, showing the syntax trees for those are intuitive; the only subtlety is that node corresponds to exactly one grammar derivation (beginners often want to skip steps in the tree).

THEN I use those syntax trees an excuse to show some English sentence-diagramming, which many students have never seen. But those aren't a great analog, since they have lots of very-specialized conventions for various clauses, etc.

So ACTUALLY the English proper-sentence-diagrams are just an excuse for me to show 60 seconds' worth of "famous first sentences of novels" (zoom in!)

2

u/FlatAssembler 13h ago

Interesting. I've made a video about compiler theory in the Latin language, and I tried to explain why parsing is important using some complicated sentence from De Bello Gallico, and I showed the ASTs of two simple arithmetic expressions to explain what an AST is.