Syntax

From Seobility Wiki
Jump to: navigation, search

Definition

Syntax can be considered as a form of computer grammar. In order to interpret information and understand intent, whether it be delivering a website or search results, syntax is used to provide an information structure that computers can use to understand it. Sometimes, this syntax is very loose, such as in search queries. Here, a computer will attempt to interpret information regardless of how it is entered. In other situations, such as computer code, syntax is very rigid and deviations may result in a computer program either running incorrectly, or not running at all.

Syntax in programming

Programming syntax refers to the structure of how code is written and formatted in a particular language. There are very many programming languages, and each may either have its own syntax, or borrow heavily from an existing syntax. As a program can be written in one of many different ways, it is not possible to list syntax for all programming languages. Instead, some of the more common ones have been chosen below.

C and C-like syntax

C was a foundational programming language and has influenced many other programming languages that followed in various ways, including copying its syntax. Modern languages that have adopted code conventions and syntax from it include C++, PHP, and Java.

Computer code written in a C-like programming language will typically end declarations and function calls with a semi-colon ;, wrap code blocks like functions and classes in curly brackets {} and comments are written by either appending // characters to a line, or wrapping comments in /* */.

Python

Python has a somewhat unique syntax, in that is eschews a lot of code conventions. Rather than using any of the special characters as in C-like syntax, Python uses line breaks and indentation. A code block is defined by indenting the code below where it is declared, and line breaks indicate the end of program calls and declarations.

Lisp

Lisp also has a very unique syntax, wrapping almost every statement or expression in brackets (). Unlike many other languages, brackets are very often nested and used to clearly separate things like function declarations, function arguments and function calls.

Syntax of a URL

URLs follow a loosely defined syntax, but there is variation depending on the program or protocol being invoked and how the code to interpret it is written.

The first part of a URL is the protocol. For web addresses, this is typically either http:// or https://, but there are other protocols, including ftp:// and gopher://.

The second part of a URL is called the domain name, which might be preceded by www. and is followed by a TLD (top-level domain), such as .com, .org, or .net. Subdomains may exist, which precede the domain name and are followed by a full stop, using a syntax such as: subdomain.domain.TLD

This is the extent of what is required for a valid URL, but there may be more. It depends on the program and the code used. After a / character, a file path or string of arguments may appear. This could look something like: domain.TLD/images/imagename.png or domain.TLD/?page=contact&customerID=123

A file path will link a user to a specific file on the server. A string of characters typically represents information that is passed between pages and used somewhere on the page itself.

Another optional element is the fragment identifier, located at the end of a URL. The fragment identifier starts with a # and refers to a point within a web page so that it can be accessed directly.

Google Search syntax

Google uses the power of its computer infrastructure to interpret search queries however they are entered. However, there is a syntax to Google searches that can help you fine-tune search queries and deliver more specific results. An example of some of the different search options is listed below.

Google can search for information on a specific website by appending a search query with site:domain. For example, site:spotify.com The Beatles would search for The Beatles only on Spotify.

There are many other options that work in the same way and are largely self-explanatory. These include

filetype: 
related:
intitle:
inurl:
weather:
stocks:
movie:
map: 

and more. These are all used to narrow down search results and refine queries, as without this information, a computer must interpret ambiguous statements and guess at search intent. As more information is provided, the computer can use it to deliver higher quality, more relevant results.

Google search queries also accept several Boolean operators. These generally enable you to include or exclude certain information, sometimes in tangent with other information. For example, 'AND' and 'OR' can be used between separate words or phrases to only return results that either contain both, or at least one statement, respectively.

A search query wrapped in double quotations "" will conduct an exact search for the phrase placed inside the brackets. Double periods .. can be used between numbers to act as a range search operator. All of these Boolean operators can be used together in a single search query. A search for results from both The Beatles and common nicknames between specific years, could look like: ("The Beatles" AND "Fab Four") 1965..1969

Similar articles

About the author
Seobility S
The Seobility Wiki team consists of seasoned SEOs, digital marketing professionals, and business experts with combined hands-on experience in SEO, online marketing and web development. All our articles went through a multi-level editorial process to provide you with the best possible quality and truly helpful information. Learn more about the people behind the Seobility Wiki.