Tutorial by Examples

To install PLY on your machine for python2/3, follow the steps outlined below: Download the source code from here. Unzip the downloaded zip file Navigate into the unzipped ply-3.10 folder Run the following command in your terminal: python setup.py install If you completed all the above, you...
Let's demonstrate the power of PLY with a simple example: this program will take an arithmetic expression as a string input, and attempt to solve it. Open up your favourite editor and copy the following code: from ply import lex import ply.yacc as yacc tokens = ( 'PLUS', 'MINUS', ...
There are two steps that the code from example 1 carried out: one was tokenizing the input, which means it looked for symbols that constitute the arithmetic expression, and the second step was parsing, which involves analysing the extracted tokens and evaluating the result. This section provides a ...
This section explains how the tokenized input from Part 1 is processed - it is done using Context Free Grammars (CFGs). The grammar must be specified, and the tokens are processed according to the grammar. Under the hood, the parser uses an LALR parser. # Yacc example import ply.yacc as yacc ...

Page 1 of 1