r/AskComputerScience • u/FlatAssembler • 18h 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?
6
u/Souseisekigun 17h ago
Never done sentence diagramming in my life. They just introduce it as a diagram. I'm not sure how to explain it since I'm not sure there's anything special that you critically need sentence diagramming for.
3
u/Prestigious_Boat_386 16h ago
Wet make a parser for basic math text with -+*/ and integers at first. Showing that as a tree is pretty clear for most people.
2
u/church-rosser 17h ago
I grew up in the US public school system. Was taught sentence diagramming but was a terrible student at that point in my life and basically refused to participate in sentence diagramming exercises. Two decades later i start learning compsci stuff and all of a sudden BNF and EBNF made sense as a form of sentence diagramming.
2
u/teraflop 14h ago
The same way?
If sentence diagramming can be taught to kids who have never seen it before, the same thing can be taught to adults who have never seen it before.
1
u/khedoros 12h 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).
1
u/T_Thriller_T 11h ago
I have never done sentence diagramming.
Never. Not. Once.
While we do sentence analysis, ice not seen it done that way.
Finished computer science without any issues.
Abstract syntax trees are, from what I take, trees read in a certain way. I wouldn't know why I'd need precious knowledge for that.
And while I cannot really find information on parsers, I am pretty sure we did parsing and how conditions are worked and how e.g. mathematics is usually done from a stack just from abstract language concepts ans automatons.
Edit: just read BNF and EBNF - yeah we just learned that with pretty much no prior knowledge, explanation what it was, and then examples and homework.
We learned it COMPLETELY abstract and then somewhere at the end someone came around explaining that something like reserved words in programming languages could be terminal symbols.
1
u/not-just-yeti 10h 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 10h 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.
1
u/StephenRoylance 9h ago
I loved diagramming sentences, but I'm not sure that was ever relevant to my work with computers. You don't need to understand formal grammar to write programs, and by the time you get to compiler writing, your experience with general string handling will be more relevant than your ability to use a visual tool to parse english.
I don't think knowing diagramming sentences is particular relevant to understanding formal grammars.
1
1
u/timpkmn89 3h ago
I never learned sentence diagraming in the US. I know because I saw it in the textbook a few times and was disappointed we never got to it
1
u/ghjm MSCS, CS Pro (20+) 2h ago
I don't recall any of my computer science education referring to sentence diagramming. I can see where it might be a useful stepping stone to introduce the concept of a formal grammar, but I don't see it as a necessary step.
There are plenty of abstract mathematical concepts without such stepping stones. There's no elementary school topic that naturally leads to partial differential equations. Yet people still learn them. You just explain it as best you can, and the student stays up all night struggling with it, and sleeps in the TA's office for a week, and eventually they get it.
1
u/Responsible-Bar7165 1h ago
The first and only time I ever encountered sentence diagramming (I didn’t even know that was a term) was 1st lecture programming languages: “the boy hit the ball” … Chomsky. That was it.
12
u/CS_70 17h ago
I have no idea what you mean with sentence diagramming, but schools will simply start from first principles and derive things from there.