File: full.inc

package info (click to toggle)
tcllib 1.18-dfsg-3
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 64,304 kB
  • ctags: 28,857
  • sloc: tcl: 174,135; ansic: 14,215; sh: 2,643; xml: 1,766; yacc: 1,148; pascal: 583; makefile: 106; perl: 84; f90: 84; python: 33; ruby: 13; php: 11
file content (54 lines) | stat: -rw-r--r-- 1,651 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54

In this section we are working a complete example, starting with a PEG
grammar and ending with running the parser generated from it over some
input, following the outline shown in the figure below:

[para][image flow][para]

Our grammar, assumed to the stored in the file [file calculator.peg]
is

[include expr_peg.inc]

From this we create a snit-based parser

[include full_[vset MODE].inc]

which leaves us with the parser package and class written to the file
[file calculator.tcl].

Assuming that this package is then properly installed in a place where
Tcl can find it we can now use this class via a script like

[include parser_use.inc]

where the abstract syntax tree stored in the variable will look like

[para][include expr_ast.inc][para]

assuming that the input file and channel contained the text

[example { 120+5 }]

A more graphical representation of the tree would be

[para][image expr_ast][para]

Regardless, at this point it is the user's responsibility to work with
the tree to reach whatever goal she desires. I.e. analyze it,
transform it, etc. The package [package pt::ast] should be of help
here, providing commands to walk such ASTs structures in various ways.

[para]

One important thing to note is that the parsers used here return a
data structure representing the structure of the input per the grammar
underlying the parser. There are [emph no] callbacks during the
parsing process, i.e. no [term {parsing actions}], as most other
parsers will have.

[para]

Going back to the last snippet of code, the execution of the parser
for some input, note how the parser instance follows the specified
[term {Parser API}].