Home | History | Annotate | Download | only in ply

Lines Matching defs:Grammar

34 # This implements an LR parser that is constructed from grammar rules defined
169 # This class is used to hold non-terminal grammar symbols during parsing.
171 # .type = Grammar symbol type
183 # grammar rule. Index lookup and assignment actually assign the
288 pslice = YaccProduction(None) # Production object passed to grammar rules
318 symstack = [ ] # Stack of grammar symbols
418 # Call the grammar rule with our special slice object
459 # Call the grammar rule with our special slice object
603 pslice = YaccProduction(None) # Production object passed to grammar rules
629 symstack = [ ] # Stack of grammar symbols
707 # Call the grammar rule with our special slice object
745 # Call the grammar rule with our special slice object
875 pslice = YaccProduction(None) # Production object passed to grammar rules
901 symstack = [ ] # Stack of grammar symbols
968 # Call the grammar rule with our special slice object
1000 # Call the grammar rule with our special slice object
1117 # === Grammar Representation ===
1120 # manipulate the rules that make up a grammar.
1131 # This class stores the raw information about a single production or grammar rule.
1132 # A grammar rule refers to a specification such as this:
1266 # lr_before - Grammar symbol immediately before
1305 # === GRAMMAR CLASS ===
1307 # The following class represents the contents of the specified grammar along
1314 class Grammar(object):
1318 # building an augmented grammar
1348 self.Start = None # Starting symbol for the grammar
1420 raise GrammarError("%s:%d: Syntax error. %%prec can only appear at the end of a grammar rule" % (file,line))
1469 # Sets the starting symbol and creates the augmented grammar. Production
1514 # infinite recursion cycles (grammar rules where there is no possible way
1579 # Find all symbols that were used the grammar, but not defined as tokens or
1580 # grammar rules. Returns a list of tuples (sym, prod) where sym in the symbol
1596 # Find all terminals that were defined, but not used by the grammar. Returns
1610 grammar rules that were defined, but not used (maybe not reachable)
1626 # rules that were never used by the grammar. term is the name of the terminal
1878 # a grammar.
1940 def __init__(self,grammar,method='LALR',log=None):
1944 self.grammar = grammar
1955 self.lr_productions = grammar.Productions # Copy of grammar Production array
1970 self.grammar.build_lritems()
1971 self.grammar.compute_first()
1972 self.grammar.compute_follow()
1996 # of LR(0) items and X is a grammar symbol. This function is written
2038 C = [ self.lr0_closure([self.grammar.Productions[0].lr_next]) ]
2044 # Loop over the items in C and each grammar symbols
2097 for p in self.grammar.Productions[1:]:
2126 if t[1] in self.grammar.Nonterminals:
2149 if a in self.grammar.Terminals:
2153 if state == 0 and N == self.grammar.Productions[0].prod[0]:
2241 if p.prod[li] in self.grammar.Terminals: break # No forget it
2312 # Attaches the lookahead symbols to grammar rules.
2363 Productions = self.grammar.Productions
2364 Precedence = self.grammar.Precedence
2407 laheads = self.grammar.Follow[p.name]
2436 # that was defined first in the grammar file
2458 if a in self.grammar
2524 if s in self.grammar.Nonterminals:
2720 # This takes a raw grammar rule string and parses it into production data
2723 grammar = []
2747 grammar.append((file,dline,prodname,syms))
2753 return grammar
2769 self.grammar = []
2795 # Compute a signature over the grammar
2957 # Get all p_functions from the grammar
2975 grammar = []
3000 grammar.append((name, g))
3006 # Looks like a valid grammar rule
3011 # or functions that look like they might be grammar rules.
3023 self.log.warning("%s:%d: Possible grammar rule '%s' defined without p_ prefix",
3028 self.grammar = grammar
3107 # Create a grammar object
3108 grammar = Grammar(pinfo.tokens)
3113 grammar.set_precedence(term,assoc,level)
3118 # Add productions to the grammar
3119 for funcname, gram in pinfo.grammar:
3122 grammar.add_production(prodname,syms,funcname,file,line)
3128 # Set the grammar start symbols
3131 grammar.set_start(pinfo.start)
3133 grammar.set_start(start)
3142 # Verify the grammar structure
3143 undefined_symbols = grammar.undefined_symbols()
3148 unused_terminals = grammar.unused_terminals()
3160 debuglog.info("Grammar")
3162 for n,p in enumerate(grammar.Productions):
3166 unused_rules = grammar.unused_rules()
3184 terms = list(grammar.Terminals)
3187 debuglog.info("%-20s : %s", term, " ".join([str(s) for s in grammar.Terminals[term]]))
3192 nonterms = list(grammar.Nonterminals)
3195 debuglog.info("%-20s : %s", nonterm, " ".join([str(s) for s in grammar.Nonterminals[nonterm]]))
3199 unreachable = grammar.find_unreachable()
3203 infinite = grammar.infinite_cycles()
3208 unused_prec = grammar.unused_precedence()
3216 # Run the LRGeneratedTable on the grammar
3220 lr = LRGeneratedTable(grammar,method,debuglog)