If you come from a programming background, you have heard the word syntax a lot: the Syntax of Python, Java,…
As a Linguist (Ph.D. in Linguistics), I DO NOT get asked this question enough by programmers! Apparently, everyone knows what it is. So, why bother writing about it?
Syntax is one of the most important areas in Linguistics or the scientific study of language. Programming languages are, after all, languages!
In this post, you will learn what syntax is both in Linguistics and Programming.
What is Linguistics?
Linguistics is the scientific study of language and its structure, as well as its development, use, and influence in society. It is a field of study that looks at how language is used in different contexts and how it changes over time. It is a branch of knowledge that intersects with many other disciplines, such as anthropology, psychology, and communication science.
Linguists study the structure of language, including its grammar and syntax. They also look at the meaning of words (semantics) and how they can be used to convey a message (pragmatics). Additionally, linguists analyze the development of language in different societies (sociolinguistics), as well as its evolution. They also explore the relationship between language and culture, and how language affects the way we think and communicate.
Linguists use a variety of methods to study language. These include fieldwork, which involves observing how people use language in different contexts; corpus linguistics, which examines the use of language in large collections of written texts; and psycholinguistics, which looks at how language is processed and acquired.
What is syntax?
The word ‘Syntax’ is originally Greek meaning ‘arrangement’ or ‘a putting together’. So, syntax is about the arrangement of words in a grammatically correct sentence. Take a look at the following sentence:
The man saw the cat.
Grammatically, there is a subject (the man), and a predicate consisting of a verb (saw), and an object (the cat).
Syntax is an essential part of linguistics. It is the study of the structure of language and the rules that govern its formation. Syntax is concerned with how sentences are formed, how words are combined to create meaning, and how different parts of a sentence are related.
Syntax studies the way in which words are arranged in a sentence and how they can be used to convey a message. It looks at the relationship between words, how they are ordered in a sentence, and how they interact.
The study of syntax is important for understanding how language works, as well as for improving communication and making sure that messages are clear and accurate.
Subscribe to Receive the Latest Python Tips
Syntactic Tree Diagram
In syntactic terms, for the following sentence, there is a Sentence (S) consisting of a noun phrase (the man), and a verb phrase (saw the cat), which in turn consists of a Verb (saw), and a Noun Phrase (the cat). To illustrate we draw a tree diagram:
NP: Noun Phrase
VP: Verb Phrase
D: Determiner (article)
We make sentences from phrases or groups of words that have a closer relationship to each other than to the words outside the phrase. That is why we cluster those words that go together in a phrase (the man, saw the cat, the cat, …)
Syntax and Chomsky
The study of syntax and syntactic structures became highly important in linguistics after Noam Chomsky’s book Syntactic Structures (1957).
In that book, Chomsky elaborates on his theory of syntax which became known as transformational generative grammar.
For example, the passive sentence “The bank was robbed by Rob” corresponds to the active sentence “Rob robbed the bank,” according to transformational grammar. Whom [or who] did Adam love? and Who loved Eve? are queries that are related to the statement “Adam loved Eve.” Although sets like these active and passive phrases seem extremely different on the surface (i.e., in aspects like word order), a transformational grammar aims to demonstrate that the sentences are remarkably similar in their “underlying structure” (i.e., in their deeper links to one another).
According to transformational grammar, these phrases are given a “deep structure” and a “surface structure” to indicate their link. Thus, “The bank was robbed by Rob” is only the surface structure of “Rob robbed the bank”.
He gave a famous example to emphasize the independence of syntax from semantics:
“The colorless green ideas sleep furiously.”
Although this sentence is syntactically complete and correct, it does not make much sense.
What is syntax in programming?
Syntax in computer programming is the set of rules that define how a computer program should be written and structured. Syntax dictates the structure of a program, how the program should be written, and how the program should be read.
For example, in Python to create a function you, you have this specific arrangement (hence the meaning of Syntax in Greek):
You put the keyword
def before the name of a function which is immediately followed by parentheses and colon:
def greet(): print("Hello")
Comparing with natural languages, in order to make a declarative sentence in English you use Subject – Verb – Object arrangement and order: The teacher saw the principal.
Syntax is the foundation of any natural and programming language, and it is essential for understanding how to write in a programming/natural language correctly. Syntax in programming languages includes elements such as keywords, data types, variables, functions, and operators and their arrangement. Understanding the syntax of a programming language is essential for writing and executing a program correctly.