Formal Grammar

Vocola uses Grammatica to parse command files. Here is the formal grammar, slightly simplified for readability:


%productions%
          file = using* statements
         using = '$using' words ';'
    statements = (include | context | definition | function | command)+

       include = '$include' actions ';'
       context = '$if' ifbody ('$elseif' ifbody)* ['$else' statements] '$end'
        ifbody = words ('|' words)* ';' statements

    definition = variable ':=' menuBody ';'
      variable = '<' VARIABLE '>'
      function = prototype ':=' actions ';'
     prototype = NAME '(' [NAME (',' NAME)*] ')'
       command = terms '=' actions ';'

         terms = (term | optionalWords)+
          term = words | variable | range | menu
         range = NUMBER '..' NUMBER
 optionalWords = '[' words ']'

          menu = '(' menuBody ')'
      menuBody = alternative ('|' alternative)*
   alternative = terms ['=' [actions] ]

         words = word+
          word = (QUOTED_CHARS | NAME | CHARS)

       actions = action+
        action = words | reference | call
     reference = '$' (NUMBER | NAME)
          call = dottedName '(' [actions (',' actions)*] ')'
    dottedName = NAME ('.' NAME)*

%tokens%
    WHITESPACE      = <<[ \t\n\r]+>> %ignore%
    NAME            = <<[a-zA-Z_]\w*>>
    VARIABLE        = <<\w+>>
    NUMBER          = <<\d+>>
    CHARS           = <<[^"'#=;|\[\]()<>, \t\n\r]+>>
    QUOTED_CHARS    = <<"([^"\n\r]|"")*"|'([^'\n\r]|'')*'>>
    COMMENT_MULTI   = <<#\|(.|[\n\r])*?\|#>> %ignore%
    COMMENT         = <<#.*>> %ignore%
 
Copyright © 2002-2023 Rick Mohr