Simple precedence parser

Simple precedence parser

In computer science, a Simple precedence parser is a type of bottom-up parser for context-free grammars that can be used only by Simple precedence grammars.

The implementation of the parser is quite similar to the generic bottom-up parser. A stack is used to store a viable prefix of a sentential form from a rightmost derivation. Simbols lessdot, dot = and gtrdot are used to identify the pivot, and to know when to Shift or when to Reduce.

= Implementation =

* Compute the Wirth-Weber precedence relationship table.
* Start with a stack with only the starting marker $.
* Start with the string being parsed (Input) ended with an ending marker $.
* While not (Stack equals to $S and Input equals to $) (S = Initial simbol of the grammar)
** Search in the table the relationship between Top(stack) and NextToken(Input)
** if the relationship is dot = or lessdot
*** Shift:
*** Push(Stack, relationship)
*** Push(Stack, NextToken(Input))
*** RemoveNextToken(Input)
** if the relationship is gtrdot
*** Reduce:
*** SearchProductionToReduce(Stack)
*** RemovePivot(Stack)
*** Search in the table the relationship between the Non terminal from the production and first symbol in the stack (Starting from top)
*** Push(Stack, relationship)
*** Push(Stack, Non terminal)

SearchProductionToReduce (Stack)
* search the Pivot in the stack the nearest lessdot from the top
* search in the productions of the grammar which one have the same right side than the Pivot

= Example =

Given the language:E --> E + T' | T'T' --> TT --> T * F | FF --> ( E' ) | numE' --> E

num is a terminal, and the lexer parse any integer as num.

and the Parsing table:

STACK PRECEDENCE INPUT ACTION

$ < 2 * ( 1 + 3 )$ SHIFT$ < 2 > * ( 1 + 3 )$ REDUCE (F -> num)$ < F > * ( 1 + 3 )$ REDUCE (T -> F)$ < T = * ( 1 + 3 )$ SHIFT$ < T = * < ( 1 + 3 )$ SHIFT$ < T = * < ( < 1 + 3 )$ SHIFT$ < T = * < ( < 1 > + 3 )$ REDUCE 4 times (F -> num) (T -> F) (T' -> T) (E ->T ') $ < T = * < ( < E = + 3 )$ SHIFT$ < T = * < ( < E = + < 3 )$ SHIFT$ < T = * < ( < E = + < 3 > )$ REDUCE 3 times (F -> num) (T -> F) (T' -> T) $ < T = * < ( < E = + = T > )$ REDUCE 2 times (E -> E + T) (E' -> E)$ < T = * < ( < E' = )$ SHIFT$ < T = * < ( = E' = ) > $ REDUCE (F -> ( E' ))$ < T = * = F > $ REDUCE (T -> T * F)$ < T > $ REDUCE 2 times (T' -> T) (E -> T')$ < E > $ ACCEPT


Wikimedia Foundation. 2010.

Игры ⚽ Нужна курсовая?

Look at other dictionaries:

  • Simple precedence grammar — A simple precedence grammar is a context free formal grammar that can be parsed with a simple precedence parser. TOC =Formal definition=G = ( N , Sigma;, P , S ) is a simple precedence grammar if all the production rules in P comply with the… …   Wikipedia

  • Operator-precedence parser — An operator precedence parser is a bottom up parser that interprets an operator precedence grammar. For example, most calculators use operator precedence parsers to convert from the human readable infix notation with order of operations format… …   Wikipedia

  • Parser Grammar Engine — The Parser Grammar Engine (originally Parrot Grammar Engine) or PGE is a compiler and runtime for a Perl 6 rules for the Parrot virtual machine. [cite web | url=http://search.cpan.org/ ltoetsch/parrot 0.2.2/compilers/pge/README | title=Parrot… …   Wikipedia

  • Wirth-Weber precedence relationship — The Wirth Weber relationship between a pair of symbols (V t cup V n) is necessary to determine if a formal grammar is a Simple precedence grammar, and in such case the Simple precedence parser can be used. The goal is to identify the when the… …   Wikipedia

  • Operator-precedence grammar — An operator precedence grammar is a kind of grammar for formal languages. Technically, an operator precedence grammar is a context free grammar that has the property (among others[1]) that no production has either an empty right hand side or two… …   Wikipedia

  • Analizador sintáctico de precedencia simple — Saltar a navegación, búsqueda En el área de los lenguajes formales, un analizador de sintaxis por precedencia simple es un tipo de analizador sintáctico ascendente para gramáticas libres de contexto que pueden ser utilizados para reconocer… …   Wikipedia Español

  • Parsing — In computer science and linguistics, parsing, or, more formally, syntactic analysis, is the process of analyzing a sequence of tokens to determine their grammatical structure with respect to a given (more or less) formal grammar.Parsing is also… …   Wikipedia

  • Bottom-up parsing — (also known as shift reduce parsing) is a strategy for analyzing unknown data relationships that attempts to identify the most fundamental units first, and then to infer higher order structures from them. It attempts to build trees upward toward… …   Wikipedia

  • List of algorithms — The following is a list of the algorithms described in Wikipedia. See also the list of data structures, list of algorithm general topics and list of terms relating to algorithms and data structures.If you intend to describe a new algorithm,… …   Wikipedia

  • Список алгоритмов — Эта страница информационный список. Основная статья: Алгоритм Ниже приводится список алгоритмов, группированный по категориям. Более детальные сведения приводятся в списке структур данных и …   Википедия

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”