Enhanced C#
Language of your choice: library documentation
Nested classes | Public fields | Properties | Public Member Functions | Static Public Member Functions | List of all members
Loyc.LLParserGenerator.Alts Class Reference

Describes a series of alternatives (branches), a kleene star (*), or an optional element (?). More...


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

Remarks

Describes a series of alternatives (branches), a kleene star (*), or an optional element (?).

Branches, stars and optional elements are represented by the same class because they all require prediction, and prediction works the same way for all three.

The one-or-more operator '+' is represented simply by repeating the contents once, i.e. (x+) is converted to (x x*), which is a Seq of two elements: x and an Alts object that contains a clone of x (a clone, because a Pred object can only exist in one place in a grammar). Thus, there is no predicate that represents x+ itself.

Alts has a few options beyond the LoopMode:

I have an uneasy feeling that the code in here is overly complicated, particularly the way I handled slashes and merging Alts. I'm just not sure what simpler techniques I should have used instead.

Public fields

LoopMode Mode = LoopMode.None
 
bool? Greedy = null
 Specifies whether the loop is greedy or nongreedy (ignored for non-loops). This flag is used in case of ambiguity between between the arms and exit branch; if the loop is greedy, the arms win; if not, loop exits. More...
 
List< PredArms = new List<Pred>()
 
Pred ErrorBranch = null
 Specifies the action to take for error input. If an error branch is specified, it serves as the default arm and DefaultArm has no significant effect. If ErrorBranch is null but DefaultArm is null and the LLParserGenerator.NoDefaultArm flag is set, a default error handler is generated. More...
 
bool ExitOnError = true
 
int? DefaultArm = null
 Specifies the case that should be encoded as the default in the prediction tree, i.e., the else clause in the if-else chain or the "default:" label in the switch statement. 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...
 

Properties

IEnumerable< PredArmsAndCustomErrorBranch [get]
 
bool HasExit [get]
 
int? ArmCountPlusExit [get]
 
override bool IsNullable [get]
 
- 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]
 

Public Member Functions

 Alts (LNode basis, LoopMode mode, bool? greedy=null)
 
 Alts (LNode basis, LoopMode mode, Pred contents, bool? greedy=null)
 
bool HasErrorBranch (LLParserGenerator llpg)
 
bool HasDefaultErrorBranch (LLParserGenerator llpg)
 
bool NonExitDefaultArmRequested ()
 
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 ()
 
string AltName (int altNum)
 
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 ()
 

Static Public Member Functions

static Alts Merge (LNode basis, Pred a, Pred b, bool slashJoined, BranchMode aMode, BranchMode bMode, IMessageSink warnings)
 
- 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

◆ Clone()

override Pred Loyc.LLParserGenerator.Alts.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.Alts.Clone().

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

Member Data Documentation

◆ DefaultArm

int? Loyc.LLParserGenerator.Alts.DefaultArm = null

Specifies the case that should be encoded as the default in the prediction tree, i.e., the else clause in the if-else chain or the "default:" label in the switch statement.

Use 0 for the first arm (only warning messages add 1 to arm indexes). -1 means that the exit branch is the default (if there is no exit branch, the last branch is the default instead?)

◆ ErrorBranch

Pred Loyc.LLParserGenerator.Alts.ErrorBranch = null

Specifies the action to take for error input. If an error branch is specified, it serves as the default arm and DefaultArm has no significant effect. If ErrorBranch is null but DefaultArm is null and the LLParserGenerator.NoDefaultArm flag is set, a default error handler is generated.

◆ Greedy

bool? Loyc.LLParserGenerator.Alts.Greedy = null

Specifies whether the loop is greedy or nongreedy (ignored for non-loops). This flag is used in case of ambiguity between between the arms and exit branch; if the loop is greedy, the arms win; if not, loop exits.

Greedy == null by default. This means that the loop is still greedy, but a warning is printed if ambiguity is detected.