Code - Grammar / Syntax (Lexical)


This section regroups the entity of a computer language from a lexical point of view. It's the same as Parts of the speech for a natural language.

Grammars are useful models when designing software that processes data with a recursive structure.

To see how a grammar is defined to be able to parse it in a compiler. See Language - (Grammar | Syntax | Lexicon)

Every language displays a structure called its grammar or syntax.

The Grammar is also known as:

  • Formal Grammar (formal meaning with structure)
  • The Syntax
  • The Language structure
  • The lexicon (The input file of the lexer)

The syntax of a computer language is the set of rules that defines the combinations of symbols (text or visual) that are considered to be a correctly structured document or fragment in that language.

A syntax does not only define the set of sentences of a language, but also provides them with a structure.

The syntax describing the form (the structure) has to be contrasted with the semantics (the meaning). See Code - Semantic (Meaning|Behaviour)

Structure / Building Block / Construct

Programs are just collections of statements. A statement are made up of one or more token that performs a specific task. This statement tokens made one or more expressions.

The following expressions are the basis building block of any language:

  • variables to store data (aka state) during your program’s execution.
  • types to defined the type of actions on your value (like math on numbers or output with strings)
  • conditionals flow like if statements to make decisions.
  • loops to repeat tasks until a condition stops being true.
  • functions or class to organize your code into logical and reusable chunks.
  • operators to perform basic known operation on value.
  • comment to document the code.

The definition on how you write of all this building block is called a grammar.

Others constructs common to many languages

Powered by ComboStrap