Version 1.0
Copyright © 2022 Lowell D. Thomas
Python APG
… an
A
BNF
P
arser
G
enerator
Main Page
Related Pages
Packages
Packages
Package Functions
All
a
b
c
d
e
f
g
h
i
k
l
m
n
p
r
s
t
u
v
x
Functions
a
b
c
d
e
f
g
h
i
k
l
m
n
p
r
s
t
u
v
x
Variables
a
b
c
d
e
f
g
h
i
k
l
m
n
p
r
s
t
u
v
Classes
Class List
Class Index
Class Members
All
_
a
b
c
d
e
f
g
h
i
l
m
n
o
p
r
s
t
u
w
Functions
_
a
c
d
e
f
g
h
i
o
p
r
s
t
u
w
Variables
a
b
c
e
f
g
h
i
l
m
n
o
p
r
s
t
u
Files
File List
•
All
Classes
Namespaces
Files
Functions
Variables
Pages
examples
basics
main.py
Go to the documentation of this file.
1
''' @file examples/basics/main.py
2
@brief Driver function for demonstrating Python APG basic operations.
3
Run
4
<pre>python3 examples/basic/main.py --help</pre>
5
to see all of the basic options.
6
@dir examples
7
@brief Examples of using all aspects of the parser, parser generator
8
and pattern-matching engine.
9
In each sub-directory has a "main.py" file. Execute this file
10
to run the example. e.g. from your project directory
11
<pre>python3 examples/basic/main.py --help</pre>
12
will give all of the basic example options.
13
Examine any of the other files in the directory to study the examples
14
or run them in a debugger to further understand the examples lessons.
15
@dir examples/basics
16
@brief All of the examples of basic parsing operations.
17
Run
18
<pre>python3 examples/basic/main.py --help</pre>
19
to see all of the basic options.
20
Examine any of the other files in the directory to study the examples
21
or run them in a debugger to further understand the examples lessons.
22
'''
23
import
sys
24
import
os
25
# add the current working directory to the path
26
# DO NOT MOVE THE FOLLOWING STATEMENT
27
# if using autopep8 formatter, for example, set argument '--ignore=E402'
28
sys.path.append(os.getcwd())
29
30
31
def
usage
():
32
display =
'usage: python3 examples/basics/main.py option\n'
33
display +=
' option must be one of the following\n'
34
display +=
' --back_reference demonstrates back referencing\n'
35
display +=
' --look_ahead demonstrates use of look ahead operators, & and !\n'
36
display +=
' --look_behind demonstrates use of look behind operators, && and !!\n'
37
display +=
' --parser demonstrates basic grammar generation and parsing\n'
38
display +=
' --stats demonstrates displaying the parser\'s statistics\n'
39
display +=
' --substrings demonstrates parsing a substring of the full input string\n'
40
display +=
' --trace demonstrated displaying a trace of the parser\'s parse tree\n'
41
display +=
' --udts demonstrates the use of User_Defined Terminals, handwritten phrase matching\n'
42
return
display
43
44
45
if(
len
(sys.argv) == 1):
46
print(
usage
())
47
exit()
48
49
if(sys.argv[1] ==
'--parser'
):
50
import
examples.basics.parsing_basics
51
exit()
52
53
if(sys.argv[1] ==
'--back_reference'
):
54
import
examples.basics.back_reference
55
exit()
56
57
if(sys.argv[1] ==
'--look_ahead'
):
58
import
examples.basics.look_ahead
59
exit()
60
61
if(sys.argv[1] ==
'--look_behind'
):
62
import
examples.basics.look_behind
63
exit()
64
65
if(sys.argv[1] ==
'--stats'
):
66
import
examples.basics.stats
67
exit()
68
69
if(sys.argv[1] ==
'--trace'
):
70
import
examples.basics.trace
71
exit()
72
73
if(sys.argv[1] ==
'--substrings'
):
74
import
examples.basics.substrings
75
exit()
76
77
if(sys.argv[1] ==
'--udts'
):
78
import
examples.basics.udts
79
exit()
80
81
print(
usage
())
examples.basics.back_reference
Definition:
back_reference.py:1
examples.basics.look_ahead
Definition:
look_ahead.py:1
examples.basics.look_behind
Definition:
look_behind.py:1
examples.basics.main.usage
def usage()
Definition:
main.py:31
examples.basics.parsing_basics
Definition:
parsing_basics.py:1
examples.basics.stats
Definition:
stats.py:1
examples.basics.substrings
Definition:
substrings.py:1
examples.basics.substrings.len
int len
Definition:
substrings.py:27
examples.basics.trace
Definition:
trace.py:1
examples.basics.udts
Definition:
udts.py:1
Generated by
1.9.1
Python APG, Version 1.0, is licensed under the
2-Clause BSD License
,
an
Open Source Initiative
Approved License.