Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Parsing in a particular language?

  1. Aug 16, 2012 #1
    Hello everyone,
    I would like to ask how exactly Parsing is done in a particular language? Let's say Octave for an example. And if there is parsing error from where it is called?

    Thank you in advance.

  2. jcsd
  3. Aug 17, 2012 #2


    User Avatar
    Science Advisor

    Hey vivek91m and welcome to the forums.

    The standard way of parsing something is by using context-free grammars. BNF and EBNF are good examples of what constitutes these CFG's for parsing and tree construction purposes:



    There are tools that take a grammar definition and not only check that expressions are in the form of the grammar, but they also build trees that structure the terms.

    This is the structured algorithmic approach of handling this, but you can use custom code that deals with specific structures to handle specific kinds of applications and definitions.

    For example if you want to say implement an XML parser, you can write some code that is very compact that will parse the contents of a tag and the tag itself (with the tag attribute) and then generate a simple tree structure to represent the entire state of the markup context.

    You can then overload say each tag type to have a callback function that has access to the tag tree and the data and it can do what it needs to do.

    In short though it depends on the application and it's needs and there is no one thing that is used, but certainly if you want to understand how computer scientists deal with the problem get a book on compilers and and language parsing.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook