|
|
|||
|
|
Parser Generators
What is a Parser Generator? A parser generator creates a parser for formatted data, given a rule-based description of its structure known as a grammar. Grammars can be used to describe the syntax of any formal language; including programming languages, scripting languages, protocols and standardized formats such as HTML and SQL. A popular notation for defining grammars is Backus-Naur Form (BNF), which has several variants. Parser generators are commonly used in the development of compilers and interpreters; however, they are useful any time that data elements need to be extracted from a structured data source. Typically, the output of a parser generator is source code for some programming language (such as C, C++, or Java), which can then be compiled and linked to the client application. Semantic actions defined within the grammar are used to control how the client application processes data elements as they’re parsed, by binding specific symbols from the grammar to programmer-written application code. When a given symbol is parsed by the parser, application code corresponding to the semantic action for that symbol gets executed. Semantic actions are usually defined directly within the grammar definition and consist of compilable statements from the target programming language. In many cases, semantic actions are used to construct internal representations of the parsed data for subsequent use by the application. Lex and Yacc The most widely-used parser generator is Yacc, which is an acronym for "yet another compiler compiler". Its name reflects a common traditional use for parser generators--that of compiler construction. Yacc uses a BNF-like notation for describing the syntax of context-free grammars. In Yacc, semantic actions consist of C language statements that are entered directly into the grammar definition. Yacc generates C code to be compiled and linked directly with a client program. Yacc operates in coordination with Lex, which is a lexical analyzer (or tokenizer) that scans the input to produce a sequence of tokens. Tokens are used as input to the parser generated by Yacc. Lex uses regular expressions to describe tokens. Many parser generators are based on Lex and Yacc, or are visual front-ends to Lex and Yacc. Examples include Bison and Flex. How ProGrammar is Different ProGrammar differs from traditional parser generators in several important ways:
|
||
|
For comments or questions about this site, please contact webmaster@programmar.com Copyright © 1998-2008 NorKen Technologies, Inc. All rights reserved. |
|||