Enhanced C#
Language of your choice: library documentation
Public fields | Public Member Functions | List of all members
Loyc.LLParserGenerator.Gate Class Reference

Represents a "gate" (p => m), which is a mechanism to separate prediction from matching in the context of branching (Alts). More...


Source files:
Inheritance diagram for Loyc.LLParserGenerator.Gate:
Loyc.LLParserGenerator.Pred Loyc.ICloneable< Pred > Loyc.IHasLocation

Remarks

Represents a "gate" (p => m), which is a mechanism to separate prediction from matching in the context of branching (Alts).

Gates are explained futher in this article: http://www.codeproject.com/Articles/688152/The-Loyc-LL-k-Parser-Generator-Part-2

Public fields

Pred Predictor
 Left-hand side of the gate, which is used for prediction decisions. More...
 
Pred Match
 Right-hand side of the gate, which is used for matching decisions. More...
 
- Public fields inherited from Loyc.LLParserGenerator.Pred
Symbol VarLabel
 
bool VarIsList
 
Func< LNode, LNodeResultSaver
 A function that saves the result produced by the matching code of this predicate (null if the result is not saved). For example, if the parser generator is given the predicate @[ x='a'..'z' ], the default matching code will be @(Match('a', 'z')), and ResultSaver will be set to a function that receives this matching code and returns @(x = Match('a', 'z')) in response. More...
 

Public Member Functions

 Gate (LNode basis, Pred predictor, Pred match)
 
override void Call (PredVisitor visitor)
 
- Public Member Functions inherited from Loyc.LLParserGenerator.Pred
 Pred (LNode basis)
 
LNode AutoSaveResult (LNode matchingCode)
 
string ToStringWithPosition ()
 
virtual string ChooseGotoLabel ()
 Optional. If this predicate represents the matching code for a branch of an Alts and this code is reached through a goto statement, this method is used to select a label name. Supported by RuleRef. More...
 
- Public Member Functions inherited from Loyc.ICloneable< Pred >
Clone ()
 
bool IsEquivalency [get, set]
 If true, this is an "&lt;=>" equivalency gate, otherwise it's a "=>" normal gate. More...
 
override bool IsNullable [get]
 
override Pred Clone ()
 Deep-clones a predicate tree. Terminal sets and Nodes referenced by the tree are not cloned; the clone's value of Next will be null. The same Pred cannot appear in two places in a tree, so you must clone before re-use. More...
 
override string ToString ()
 

Additional Inherited Members

- Properties inherited from Loyc.LLParserGenerator.Pred
LNode Basis [get, protected set]
 
abstract bool IsNullable [get]
 Returns true if this predicate can match an empty input. More...
 
object Location [get]
 
- Properties inherited from Loyc.IHasLocation
object Location [get]
 
- Static Public Member Functions inherited from Loyc.LLParserGenerator.Pred
static Seq operator+ (char a, Pred b)
 
static Seq operator+ (Pred a, char b)
 
static Seq operator+ (Pred a, Pred b)
 
static Pred operator| (char a, Pred b)
 
static Pred operator| (Pred a, char b)
 
static Pred operator| (Pred a, Pred b)
 
static Pred operator/ (Pred a, Pred b)
 
static Pred operator+ (Pred a)
 
static Pred Or (Pred a, Pred b, bool slashJoined)
 
static Pred Or (Pred a, Pred b, bool slashJoined, LNode basis, BranchMode aMode=BranchMode.None, BranchMode bMode=BranchMode.None, IMessageSink sink=null)
 
static Alts Star (Pred contents, bool?greedy=null)
 
static Alts Opt (Pred contents, bool?greedy=null)
 
static Seq Plus (Pred contents, bool?greedy=null)
 
static TerminalPred Range (char lo, char hi)
 
static TerminalPred Set (IPGTerminalSet set)
 
static TerminalPred Set (string set)
 
static TerminalPred Set (params LNode[] s)
 
static TerminalPred Not (params LNode[] s)
 
static TerminalPred Char (char c)
 
static TerminalPred Chars (params char[] c)
 
static Seq Seq (string s, LNode basis=null)
 
static Rule Rule (string name, Pred pred, bool isStartingRule=false, bool isToken=false, int maximumK=-1)
 
static Pred operator+ (LNode pre, Pred p)
 
static Pred operator+ (Pred p, LNode post)
 
static LNode MergeActions (LNode action, LNode action2)
 
static AndPred And (object test)
 
static AndPred AndNot (object test)
 
static Pred Set (string varName, Pred pred)
 
static Pred SetVar (string varName, Pred pred)
 
static Pred AddSet (string varName, Pred pred)
 
static Pred Op (string varName, Symbol @operator, Pred pred)
 

Member Function Documentation

override Pred Loyc.LLParserGenerator.Gate.Clone ( )
inlinevirtual

Deep-clones a predicate tree. Terminal sets and Nodes referenced by the tree are not cloned; the clone's value of Next will be null. The same Pred cannot appear in two places in a tree, so you must clone before re-use.

Reimplemented from Loyc.LLParserGenerator.Pred.

References Loyc.LLParserGenerator.Gate.Clone(), Loyc.LLParserGenerator.Gate.Match, and Loyc.LLParserGenerator.Gate.Predictor.

Referenced by Loyc.LLParserGenerator.Gate.Clone().

Member Data Documentation

Pred Loyc.LLParserGenerator.Gate.Match

Right-hand side of the gate, which is used for matching decisions.

Referenced by Loyc.LLParserGenerator.Gate.Clone(), and Loyc.LLParserGenerator.LLParserGenerator.GenerateCodeVisitor.Visit().

Pred Loyc.LLParserGenerator.Gate.Predictor

Left-hand side of the gate, which is used for prediction decisions.

Referenced by Loyc.LLParserGenerator.Gate.Clone(), and Loyc.LLParserGenerator.LLParserGenerator.GetCanonical.Do().

Property Documentation

bool Loyc.LLParserGenerator.Gate.IsEquivalency
getset

If true, this is an "&lt;=>" equivalency gate, otherwise it's a "=>" normal gate.

This controls the follow set of the predictor. For a "=>" normal gate, the predictor (left-hand side) has anything (_*) as its follow set. For an equivalency, in which the predictor side and the match side are intended to represent the same language, the follow set of the predictor will be the same as that of the match; both are set to whatever follows the gate as a whole.

The "=>" normal gate is often used to simplify or tweak prediction decisions, e.g. in this example the gate is intended to ensure that the caller will not call Number unless LA0 is ('.'|'0'..'9'):

token Number '.'|'0'..'9' =>
'0'..'9'* ('.' '0'..'9'+)? };

Notice that the predictor is, in general, shorter than the match side. It could potentially confuse the caller if the follow set of the predictor and match sides were the same. An equivalency gate, on the other hand, should be the same length as the match side, so it can have the same follow set (I don't have a use case in mind for an equivalency gate yet).