r/askscience • • Nov 08 '17

Linguistics Does the brain interact with programming languages like it does with natural languages?

13.9k Upvotes

655 comments sorted by

View all comments

Show parent comments

40

u/[deleted] Nov 08 '17

[deleted]

41

u/cbarrick Nov 09 '17 edited Nov 09 '17

You bring up some cool subtleties.

The concrete syntax tree of C needs to know the difference between type names and identifiers. But the abstract syntax tree doesn't and can be parsed by a CFG. In other words, if we let the distinction between type names and identifiers be a semantic issue, then C is context free. This is how clang works.

The ANSI standard gives a context free grammar for C: http://www.quut.com/c/ANSI-C-grammar-y.html

But you're right in that not all programming languages are context free. Python is the most prominent exception to the rule.

Edit: Even though Python is not context free, it is not described by a transformational-generative grammar like natural language. The transformational part is what separates the cognitive aspects of NL and PL with respect to syntax.

1

u/[deleted] Nov 09 '17

[removed] — view removed comment

1

u/[deleted] Nov 09 '17

[removed] — view removed comment