Some definitions

The parser constructs a syntax tree of the program from the list of tokens while doing syntax analysis.

According to the doctor the parse tree is condensed into syntax tree

Context-free grammar

A specification for the syntactic structure of the programming language. Like for example specifying how are expression written or statements.

NOTES: from my current lecture understanding is that the brackets in the rule are part of the syntax and they are written as they are

Any grammar rule has a left hand side and a right hand side, the left hand side is named structure name or non terminals.

a terminal is just a symbol or simplest rule in the programming language

exp is a recursive rule, because it has itself’s definition in it

The language of the rule are the set of strings defined by the rule, i.e. the valid syntax for the syntax. They are a string of tokens, not string of characters like RegEx

The order in where you defined the grammar matters, the left hand side of the first rule is called the start symbol - This is very important. According to the TA, the first thing written in my code must satisfy the grammar of the start symbol I defined.

Example:

Parse tree

The parse tree is drawn yo represent the structure of the current program, The inner nodes represents the grammar rules or non terminals, their children are the expressions they are replaced with and lastly the leaf nodes are terminals

Example:

Order of the derivation matter in the order of node creation

The parse tree is then condensed into abstract syntax tree

Ambiguous grammar

If my grammar can generate more than one parse tree, the it is called and ambiguous grammar