Grammars and BNF

  • Syntax v.s. Semantics: Grammar v.s. Meaning
    • Syntax: What forms the code take? i.e. different programming langauges
    • Semantics: What's the meaning of the code? What is being executed by the computer?
  • Chomsky Hierarchy
    • Regular: most simple such as Tic-Tac-Toe
    • Context-free: programming languages
    • Context-sensitive: natural languages
    • Unrestricted: anything that is computable

Grammars and BNF

  • Backus-Naur Form (BNF)
  • 
                rule_name -> BLAH blah | blah BLAH blah | blah blah "blah" blah '*' | BLAH           
                
  • Non Terminals
  • 
                blah (aka rule names)
                
  • Terminals
  • 
                BLAH, "blah", and '*' (like VAR, NUM, "if", IF, '*', ';') 
                
  • Rule names for if
  • 
                if_exp or if_stmt