HyperDbg Debugger
Loading...
Searching...
No Matches
lalr_parsing.grammar.NonTerminal Class Reference

Public Member Functions

 __init__ (self, name, productions)
 
 __repr__ (self)
 
 __str__ (self)
 
 stringify (self, pretty=True)
 

Public Attributes

 name
 
 productions
 

Constructor & Destructor Documentation

◆ __init__()

lalr_parsing.grammar.NonTerminal.__init__ ( self,
name,
productions )
2 def __init__(self, name, productions):
3 # Creates an instance of a NonTerminal that represents a set of
4 # grammar productions for a non-terminal.
5 #
6 # Keyword arguments:
7 # name -- the name of the non-terminal
8 # productions -- a list whose elements can be:
9 # 1. Lists of objects of type NTerm or str.
10 # The str elements represent terminal grammar symbols.
11 # 2. a str with space-separated words. These words represent grammar symbols (T and NT)
12 #
13 self.name = name
14 self.productions = [(x.split() if isinstance(x, str) else x) for x in productions]
15

Member Function Documentation

◆ __repr__()

lalr_parsing.grammar.NonTerminal.__repr__ ( self)
16 def __repr__(self):
17 return 'NonTerminal(' + repr(self.name) + ')'
18

◆ __str__()

lalr_parsing.grammar.NonTerminal.__str__ ( self)
19 def __str__(self):
20 return self.name
21

◆ stringify()

lalr_parsing.grammar.NonTerminal.stringify ( self,
pretty = True )
22 def stringify(self, pretty=True):
23 title = '%s: ' % self.name
24
25 if pretty:
26 separator = '\n%s| ' % (' ' * len(self.name))
27 else:
28 separator = ' | '
29
30 def strprod(prod):
31 return ' '.join(str(sym) for sym in prod)
32
33 rules = separator.join(strprod(prod) for prod in self.productions)
34
35 return title + rules
36
37

Member Data Documentation

◆ name

lalr_parsing.grammar.NonTerminal.name

◆ productions

lalr_parsing.grammar.NonTerminal.productions

The documentation for this class was generated from the following file: