lectures.alex.balgavy.eu

Lecture notes from university.
git clone git://git.alex.balgavy.eu/lectures.alex.balgavy.eu.git
Log | Files | Refs | Submodules

Grammars.md (446B)


      1 +++
      2 title = 'Grammars'
      3 +++
      4 # Grammars
      5 A grammar defines the syntax of the input. We can then write a program implementing the rules of that grammar.
      6 
      7 For a calculator, a grammar looks like this:
      8 
      9 ```
     10 Expression:
     11   Term
     12   Expression “+” Term
     13   Expression “-“ Term
     14 Term:
     15   Primary
     16   Term “*” Primary
     17   Term “/“ Primary
     18   Term “%” Primary
     19 Primary:
     20   Number
     21   “(“ Expression “)”
     22 Number:
     23   floating-point-literal
     24 ```