C# 클래스 Loyc.LLParserGenerator.CodeGenHelperBase

Suggested base class for custom code generators. Each derived class is typically designed for a different kind of token.
LLPG comes with two derived classes, IntStreamCodeGenHelper for parsing input streams of characters or integers, and GeneralCodeGenHelper for parsing other streams. This class contains common code used by both, for example: - default code snippets such as LA0 and LA(n), the default error branch, and switch statements; - the decision function ShouldGenerateSwitch(); and - alias handling (alias "foo" = bar); note that the derived class's NodeToPred() method is responsible for using _definedAliases.
상속: IPGCodeGenHelper
파일 보기 프로젝트 열기: qwertie/ecsharp 1 사용 예제들

보호된 프로퍼티들

프로퍼티 타입 설명
F Loyc.Syntax.LNodeFactory
_Check Symbol
_Error Symbol
_LA Symbol
_LA0 Symbol
_Match Symbol
_MatchAny Symbol
_MatchExcept Symbol
_MatchExceptRange Symbol
_MatchRange Symbol
_Skip Symbol
_T Symbol
_TryMatch Symbol
_TryMatchExcept Symbol
_TryMatchExceptRange Symbol
_TryMatchRange Symbol
_alias Symbol
_classBody WList
_currentRule Rule
_definedAliases LNode>.Dictionary
_setNameCounter int
_underscore Symbol

공개 메소드들

메소드 설명
Begin ( WList classBody, ISourceFile sourceFile ) : void
BeginRule ( Rule rule ) : void
CallRule ( RuleRef rref, bool recognizerMode ) : LNode
CallTryRecognizer ( RuleRef rref, int lookahead ) : LNode
CodeGenHelperBase ( ) : System
CodeToTerminalPred ( LNode expr, string &errorMsg ) : Pred
CreateRuleMethod ( Rule rule, VList methodBody ) : LNode
CreateTryWrapperForRecognizer ( Rule rule ) : LNode

See IPGCodeGenHelper.CreateTryWrapperForRecognizer for more information.

Done ( ) : void
ErrorBranch ( IPGTerminalSet covered, int laIndex ) : LNode

Generates code for the default error branch of prediction (called when there is no explicit error branch).

Example ( IPGTerminalSet set ) : string
ExampleChar ( IPGTerminalSet set ) : char?
GenerateAndPredCheck ( AndPred andPred, LNode code, int li ) : LNode

Generate code to check an and-predicate during or after prediction, e.g. &!{foo} becomes !(foo) during prediction and Check(!(foo)); afterward.

LLLPG substitutes $LI and $LA before it calls this method. This method can return null to suppress the Check statement.

GenerateMatch ( IPGTerminalSet set, bool savingResult, bool recognizerMode ) : LNode
GenerateMatchExpr ( IPGTerminalSet set, bool savingResult, bool recognizerMode ) : LNode

Generate code to match a set, e.g. @{ MatchRange('a', 'z'); or @{ MatchExcept('\n', '\r'); }. If the set is too complex, a declaration for it is created in classBody.

GenerateSkip ( bool savingResult ) : LNode

Returns (Skip()), or (MatchAny()) if the result is to be saved.

GenerateSwitch ( IPGTerminalSet branchSets, MSet casesToInclude, LNode branchCode, LNode defaultBranch, LNode laVar ) : LNode
GenerateTest ( IPGTerminalSet set, LNode laVar ) : LNode
GetListType ( LNode type ) : LNode
LA ( int k ) : LNode

Generates code to read LA(k).

LAType ( ) : LNode

Returns the data type of LA(k)

MakeInitializedVarDecl ( LNode type, bool wantList, Symbol varName ) : LNode
Optimize ( IPGTerminalSet set, IPGTerminalSet dontcare ) : IPGTerminalSet
ResolveAlias ( LNode expr ) : LNode
SetListInitializer ( LNode varDecl ) : void

Sets ListType and/or ListInitializer based on an expression. A statement like Type x = expr sets ListType = Type and ListInitializer = expr; A statement like Type x just sets ListType = Type; and any other expression expr sets ListInitializer = expr.

ShouldGenerateSwitch ( IPGTerminalSet sets, MSet casesToInclude, bool hasErrorBranch ) : bool

Decides whether to use a switch() and for which cases, using BaseCostForSwitch and GetRelativeCostForSwitch.

VisitInput ( LNode stmt, IMessageSink sink ) : LNode

보호된 메소드들

메소드 설명
ApiCall ( Symbol apiName ) : LNode

Returns an LNode representing a call to the specified LLLPG API. For example, if the user used a "inputSource=input" option, then ApiCall(_Match, F.Literal('7')) would generate a node that represents input.Match('7').

ApiCall ( Symbol apiName, IEnumerable args, bool isStatic = false ) : LNode

Returns an LNode representing a call to the specified LLLPG API. For example, if the user used a "inputSource=input" option, then ApiCall(_Match, F.Literal('7')) would generate a node that represents input.Match('7').

ApiType ( LNode typeName ) : LNode
DefaultOf ( LNode type, bool wantList ) : LNode
EndMayBeReachable ( LNode stmt ) : bool
GenerateSetDecl ( IPGTerminalSet set, Symbol setName ) : LNode

Generates a declaration for a variable that holds the set.

For example, if setName is foo, a set such as [aeiouy] might use an external declaration such as HashSet<int> foo = NewSet('a', 'e', 'i', 'o', 'u', 'y');

GenerateSetDecl ( IPGTerminalSet set ) : Symbol
GenerateSetName ( Rule currentRule ) : Symbol
GenerateTest ( IPGTerminalSet set, LNode subject, Symbol setName ) : LNode

Generates code to test whether a terminal is in the set.

At first, LLParserGenerator calls this method with setName == null. If it returns null, it calls the method a second time, giving the name of an external variable in which the set is held (see GenerateSetDecl(IPGTerminalSet)). For example, if the subject is @la0, the test for a simple set like [a-z?] might be something like (la0 >= 'a' && 'z' >= la0) || la0 == '?'. When the setName is foo, the test might be foo.Contains(la0) instead.

GetCases ( IPGTerminalSet set ) : IEnumerable

Gets the literals or symbols to use for switch cases of a set (just the values, not including the case labels.)

GetRelativeCostForSwitch ( IPGTerminalSet set ) : int

Used to help decide whether a "switch" or an if statement will be used to handle a prediction tree, and if so which branches. This method should calculate the "cost of switch" (which generally represents a code size penalty, as there is a separate case for every element of the set) and the "cost of if" (which generally represents a speed penalty) and return the difference (so that positive numbers favor "switch" and negative numbers favor "if".)

If the set is inverted, return a something like -1000000 to ensure 'switch' is not used for that set.

비공개 메소드들

메소드 설명
AddSwitchHandler ( LNode branch, WList stmts ) : void
ForwardedArgList ( LNode args ) : VList
ReplaceT ( LNode expr, LNode replacement ) : LNode
VarName ( LNode varStmt ) : LNode

메소드 상세

ApiCall() 보호된 메소드

Returns an LNode representing a call to the specified LLLPG API. For example, if the user used a "inputSource=input" option, then ApiCall(_Match, F.Literal('7')) would generate a node that represents input.Match('7').
protected ApiCall ( Symbol apiName ) : LNode
apiName Symbol
리턴 LNode

ApiCall() 보호된 메소드

Returns an LNode representing a call to the specified LLLPG API. For example, if the user used a "inputSource=input" option, then ApiCall(_Match, F.Literal('7')) would generate a node that represents input.Match('7').
protected ApiCall ( Symbol apiName, IEnumerable args, bool isStatic = false ) : LNode
apiName Symbol
args IEnumerable Parameters to the API call, or null to access a /// property or field.
isStatic bool
리턴 LNode

ApiType() 보호된 메소드

protected ApiType ( LNode typeName ) : LNode
typeName LNode
리턴 LNode

Begin() 공개 메소드

public Begin ( WList classBody, ISourceFile sourceFile ) : void
classBody WList
sourceFile ISourceFile
리턴 void

BeginRule() 공개 메소드

public BeginRule ( Rule rule ) : void
rule Rule
리턴 void

CallRule() 공개 메소드

public CallRule ( RuleRef rref, bool recognizerMode ) : LNode
rref RuleRef
recognizerMode bool
리턴 LNode

CallTryRecognizer() 공개 메소드

public CallTryRecognizer ( RuleRef rref, int lookahead ) : LNode
rref RuleRef
lookahead int
리턴 LNode

CodeGenHelperBase() 공개 메소드

public CodeGenHelperBase ( ) : System
리턴 System

CodeToTerminalPred() 공개 추상적인 메소드

public abstract CodeToTerminalPred ( LNode expr, string &errorMsg ) : Pred
expr LNode
errorMsg string
리턴 Pred

CreateRuleMethod() 공개 메소드

public CreateRuleMethod ( Rule rule, VList methodBody ) : LNode
rule Rule
methodBody VList
리턴 LNode

CreateTryWrapperForRecognizer() 공개 메소드

See IPGCodeGenHelper.CreateTryWrapperForRecognizer for more information.
public CreateTryWrapperForRecognizer ( Rule rule ) : LNode
rule Rule
리턴 LNode

DefaultOf() 보호된 메소드

protected DefaultOf ( LNode type, bool wantList ) : LNode
type LNode
wantList bool
리턴 LNode

Done() 공개 메소드

public Done ( ) : void
리턴 void

EndMayBeReachable() 보호된 정적인 메소드

protected static EndMayBeReachable ( LNode stmt ) : bool
stmt LNode
리턴 bool

ErrorBranch() 공개 메소드

Generates code for the default error branch of prediction (called when there is no explicit error branch).
public ErrorBranch ( IPGTerminalSet covered, int laIndex ) : LNode
covered IPGTerminalSet The permitted token set, which the input did not match. /// NOTE: if the input matched but there were and-predicates that did not match, /// this parameter will be null (e.g. the input is 'b' in (&{x} 'a' | &{y} 'b'), /// but y is false.
laIndex int Location of unexpected input, relative to current position.
리턴 LNode

Example() 공개 추상적인 메소드

public abstract Example ( IPGTerminalSet set ) : string
set IPGTerminalSet
리턴 string

ExampleChar() 공개 메소드

public ExampleChar ( IPGTerminalSet set ) : char?
set IPGTerminalSet
리턴 char?

GenerateAndPredCheck() 공개 메소드

Generate code to check an and-predicate during or after prediction, e.g. &!{foo} becomes !(foo) during prediction and Check(!(foo)); afterward.
LLLPG substitutes $LI and $LA before it calls this method. This method can return null to suppress the Check statement.
public GenerateAndPredCheck ( AndPred andPred, LNode code, int li ) : LNode
andPred AndPred Predicate for which an expression has already been generated
code LNode The expression to be checked
li int Current lookahead amount. -1 means "prediction is /// complete, generate a Check() statement".
리턴 LNode

GenerateMatch() 공개 메소드

public GenerateMatch ( IPGTerminalSet set, bool savingResult, bool recognizerMode ) : LNode
set IPGTerminalSet
savingResult bool
recognizerMode bool
리턴 LNode

GenerateMatchExpr() 공개 추상적인 메소드

Generate code to match a set, e.g. @{ MatchRange('a', 'z'); or @{ MatchExcept('\n', '\r'); }. If the set is too complex, a declaration for it is created in classBody.
public abstract GenerateMatchExpr ( IPGTerminalSet set, bool savingResult, bool recognizerMode ) : LNode
set IPGTerminalSet
savingResult bool
recognizerMode bool
리턴 LNode

GenerateSetDecl() 보호된 추상적인 메소드

Generates a declaration for a variable that holds the set.
For example, if setName is foo, a set such as [aeiouy] might use an external declaration such as HashSet<int> foo = NewSet('a', 'e', 'i', 'o', 'u', 'y');
protected abstract GenerateSetDecl ( IPGTerminalSet set, Symbol setName ) : LNode
set IPGTerminalSet
setName Symbol
리턴 LNode

GenerateSetDecl() 보호된 메소드

protected GenerateSetDecl ( IPGTerminalSet set ) : Symbol
set IPGTerminalSet
리턴 Symbol

GenerateSetName() 보호된 메소드

protected GenerateSetName ( Rule currentRule ) : Symbol
currentRule Rule
리턴 Symbol

GenerateSkip() 공개 메소드

Returns (Skip()), or (MatchAny()) if the result is to be saved.
public GenerateSkip ( bool savingResult ) : LNode
savingResult bool
리턴 LNode

GenerateSwitch() 공개 메소드

public GenerateSwitch ( IPGTerminalSet branchSets, MSet casesToInclude, LNode branchCode, LNode defaultBranch, LNode laVar ) : LNode
branchSets IPGTerminalSet
casesToInclude MSet
branchCode LNode
defaultBranch LNode
laVar LNode
리턴 LNode

GenerateTest() 공개 메소드

public GenerateTest ( IPGTerminalSet set, LNode laVar ) : LNode
set IPGTerminalSet
laVar LNode
리턴 LNode

GenerateTest() 보호된 추상적인 메소드

Generates code to test whether a terminal is in the set.
At first, LLParserGenerator calls this method with setName == null. If it returns null, it calls the method a second time, giving the name of an external variable in which the set is held (see GenerateSetDecl(IPGTerminalSet)). For example, if the subject is @la0, the test for a simple set like [a-z?] might be something like (la0 >= 'a' && 'z' >= la0) || la0 == '?'. When the setName is foo, the test might be foo.Contains(la0) instead.
protected abstract GenerateTest ( IPGTerminalSet set, LNode subject, Symbol setName ) : LNode
set IPGTerminalSet
subject LNode Represents the variable to be tested.
setName Symbol Names an external set variable to use for the test.
리턴 LNode

GetCases() 보호된 메소드

Gets the literals or symbols to use for switch cases of a set (just the values, not including the case labels.)
protected GetCases ( IPGTerminalSet set ) : IEnumerable
set IPGTerminalSet
리턴 IEnumerable

GetListType() 공개 메소드

public GetListType ( LNode type ) : LNode
type LNode
리턴 LNode

GetRelativeCostForSwitch() 보호된 메소드

Used to help decide whether a "switch" or an if statement will be used to handle a prediction tree, and if so which branches. This method should calculate the "cost of switch" (which generally represents a code size penalty, as there is a separate case for every element of the set) and the "cost of if" (which generally represents a speed penalty) and return the difference (so that positive numbers favor "switch" and negative numbers favor "if".)
If the set is inverted, return a something like -1000000 to ensure 'switch' is not used for that set.
protected GetRelativeCostForSwitch ( IPGTerminalSet set ) : int
set IPGTerminalSet
리턴 int

LA() 공개 메소드

Generates code to read LA(k).
public LA ( int k ) : LNode
k int
리턴 LNode

LAType() 공개 추상적인 메소드

Returns the data type of LA(k)
public abstract LAType ( ) : LNode
리턴 LNode

MakeInitializedVarDecl() 공개 메소드

public MakeInitializedVarDecl ( LNode type, bool wantList, Symbol varName ) : LNode
type LNode
wantList bool
varName Symbol
리턴 LNode

Optimize() 공개 메소드

public Optimize ( IPGTerminalSet set, IPGTerminalSet dontcare ) : IPGTerminalSet
set IPGTerminalSet
dontcare IPGTerminalSet
리턴 IPGTerminalSet

ResolveAlias() 공개 메소드

public ResolveAlias ( LNode expr ) : LNode
expr LNode
리턴 LNode

SetListInitializer() 공개 메소드

Sets ListType and/or ListInitializer based on an expression. A statement like Type x = expr sets ListType = Type and ListInitializer = expr; A statement like Type x just sets ListType = Type; and any other expression expr sets ListInitializer = expr.
public SetListInitializer ( LNode varDecl ) : void
varDecl LNode
리턴 void

ShouldGenerateSwitch() 공개 메소드

Decides whether to use a switch() and for which cases, using BaseCostForSwitch and GetRelativeCostForSwitch.
public ShouldGenerateSwitch ( IPGTerminalSet sets, MSet casesToInclude, bool hasErrorBranch ) : bool
sets IPGTerminalSet
casesToInclude MSet
hasErrorBranch bool
리턴 bool

VisitInput() 공개 메소드

public VisitInput ( LNode stmt, IMessageSink sink ) : LNode
stmt LNode
sink IMessageSink
리턴 LNode

프로퍼티 상세

F 보호되어 있는 프로퍼티

protected LNodeFactory,Loyc.Syntax F
리턴 Loyc.Syntax.LNodeFactory

_Check 보호되어 있는 정적으로 프로퍼티

protected static Symbol _Check
리턴 Symbol

_Error 보호되어 있는 정적으로 프로퍼티

protected static Symbol _Error
리턴 Symbol

_LA 보호되어 있는 정적으로 프로퍼티

protected static Symbol _LA
리턴 Symbol

_LA0 보호되어 있는 정적으로 프로퍼티

protected static Symbol _LA0
리턴 Symbol

_Match 보호되어 있는 정적으로 프로퍼티

protected static Symbol _Match
리턴 Symbol

_MatchAny 보호되어 있는 정적으로 프로퍼티

protected static Symbol _MatchAny
리턴 Symbol

_MatchExcept 보호되어 있는 정적으로 프로퍼티

protected static Symbol _MatchExcept
리턴 Symbol

_MatchExceptRange 보호되어 있는 정적으로 프로퍼티

protected static Symbol _MatchExceptRange
리턴 Symbol

_MatchRange 보호되어 있는 정적으로 프로퍼티

protected static Symbol _MatchRange
리턴 Symbol

_Skip 보호되어 있는 정적으로 프로퍼티

protected static Symbol _Skip
리턴 Symbol

_T 보호되어 있는 정적으로 프로퍼티

protected static Symbol _T
리턴 Symbol

_TryMatch 보호되어 있는 정적으로 프로퍼티

protected static Symbol _TryMatch
리턴 Symbol

_TryMatchExcept 보호되어 있는 정적으로 프로퍼티

protected static Symbol _TryMatchExcept
리턴 Symbol

_TryMatchExceptRange 보호되어 있는 정적으로 프로퍼티

protected static Symbol _TryMatchExceptRange
리턴 Symbol

_TryMatchRange 보호되어 있는 정적으로 프로퍼티

protected static Symbol _TryMatchRange
리턴 Symbol

_alias 보호되어 있는 정적으로 프로퍼티

protected static Symbol _alias
리턴 Symbol

_classBody 보호되어 있는 프로퍼티

protected WList _classBody
리턴 WList

_currentRule 보호되어 있는 프로퍼티

protected Rule,Loyc.LLParserGenerator _currentRule
리턴 Rule

_definedAliases 보호되어 있는 프로퍼티

protected Dictionary _definedAliases
리턴 LNode>.Dictionary

_setNameCounter 보호되어 있는 프로퍼티

protected int _setNameCounter
리턴 int

_underscore 보호되어 있는 정적으로 프로퍼티

protected static Symbol _underscore
리턴 Symbol