Skip to content

AleksaMCode/bnf-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BNF parser

Parser reads a grammar definition expressed in BNF (Backus-Naur Form) at runtime after which it parses inputed strings.

Description

The project idea was to create a text parser that would parse the contents of the input file, as specified by the grammar in the modified Backus-Naur form. The grammar is given in a .bnf file.

The modified BNF form is written based on the rules for the standard BNF form, with the following appendices:

  • <a> ::= regex(regular_expression)

    Denotes a node that is determined on the basis of a regular expression specified in parentheses. In a given case, <a> represents any expression that matches the given regex.

  • <a> ::= standard_expression

    Denotes a node that is determined based on tables of standard regular expressions, where in place of standard_expression can be any of the items from the following table.

standard_expression Meaning
phone_number Phone number with or without international and country call codes, with different delimiters
mail_address Properly formatted e-mail address
web_link Properly formatted absolute URL
number_constant Integer or floating-point constant
big_city Any city from a parsers list

Implementation specifications

  • The grammar (configuration) file, must contain, in a modified BNF form, a specification of the parsing method.

  • XML tags of an output file must be named based on the token name in the BNF form, so that the resulting parsing tree is clear and equivalent to the specified BNF form.

  • In case the BNF grammar is incorrect, throw an exception describing where the error occurred (i.e. the line from the BNF grammar on which the error occurred).

  • In case a string from an input file cannot be parsed according to the BNF form, skip that input line.

Dependencies

Projects that BNF parser uses and/or is dependent on:

References

  • Peter Linz - An Introduction to Formal Languages and Automata

  • Peter Sestoft, Ken Friis Larsen - Grammars and parsing with C# 2.0

  • Anil Maheshwari, Michiel Smid - Introduction to Theory of Computation

  • Dick Grune, Ceriel J. H. Jacobs - Parsing Techniques: A Practical Guide (Monographs in Computer Science)

To-Do List

  • Implement download of city names from a web API instead of using hard-coded city names in code.
  • Create a GUI for BNF parser.