本文整理汇总了C#中ParserState类的典型用法代码示例。如果您正苦于以下问题:C# ParserState类的具体用法?C# ParserState怎么用?C# ParserState使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ParserState类属于命名空间,在下文中一共展示了ParserState类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateAcceptAction
private void CreateAcceptAction(ParserState initialState, NonTerminal augmentedRoot)
{
var root = augmentedRoot.Productions[0].RValues[0];
var shiftAction = initialState.Actions[root] as ShiftParserAction;
var shiftOverRootState = shiftAction.NewState;
shiftOverRootState.Actions[_grammar.Eof] = new AcceptParserAction();
}
示例2: CParser
public CParser(ParserState parserState, CLexer lexer)
{
this.ParserState = parserState;
this.lexer = new LookAheadLexer(
new CDirectiveLexer(parserState, lexer));
this.grammar = new CGrammar();
}
示例3: BuildIfStatement
public void BuildIfStatement()
{
var grammer = new AndyStructuralGrammar();
var p = new ParserState("if");
Assert.That(grammer.if_keyword.Match(p), Is.True);
p = new ParserState("if()");
var rule = grammer.if_keyword + grammer.Delimiter("(") + grammer.Delimiter(")");
Assert.That(rule.Match(p), Is.True);
p = new ParserState("if (a == b)");
Assert.That(grammer.if_condition.Match(p), Is.True);
p = new ParserState("if(a == 10){a=20;}");
var if_block = grammer.if_condition + grammer.block;
Assert.That(if_block.Match(p), Is.True);
p = new ParserState("if(a == 10){a=20;}");
if_block = grammer.if_condition + new RecursiveRule(() => grammer.block);
Assert.That(if_block.Match(p), Is.True);
p = new ParserState("if(a == 10){a=20;}");
Assert.That(grammer.control_statement.Match(p), Is.True);
}
示例4: Parse
public List<Node> Parse(string input)
{
var state = new ParserState() { input = input, pos = 0 };
if (!Match(state))
throw new Exception(String.Format("Rule {0} failed to match", Name));
return state.nodes;
}
示例5: ActionRecord
public ActionRecord(ParserActionType actionType, ParserState newState, NonTerminal nonTerminal, int popCount)
{
ActionType = actionType;
NewState = newState;
NonTerminal = nonTerminal;
PopCount = popCount;
}
示例6: Execute
public bool Execute(ParserState state)
{
var builder = new StringBuilder();
for (var i = 0; i < base.Children.Count; i++)
{
var action = base.Children[i];
var subState = state.Clone();
subState.CurrentItem = string.Empty;
if (!action.Execute(subState))
{
logger.LogDebug($"{state.Tracker} Http sub {i} action failed.");
return false;
}
else
{
builder.Append(state.CurrentItem);
}
}
var value = builder.ToString();
logger.LogDebug($"{state.Tracker} Http setting {name} to {value}.");
state.HTTPHeaders[name] = value;
return true;
}
示例7: Parse
public ParseResult Parse(Lexer lexer, ParserState initialState)
{
var context = new ParserContext(this, Automaton.Grammar, lexer);
context.CurrentState = initialState;
context.ParserStack.Push(new ParserNode(context, new GrammarDefinition("init"))
{
State = initialState
});
ReadNextToken(context);
context.CurrentNode = new ParserNode(context, Automaton.Grammar.ToElement(lexer.Current.GetTokenCode()), lexer.Current);
while (lexer.Current != null && context.Root == null && context.CurrentState != null)
{
// If no input and no default action (e.g. a grammar reduction),
// that means we have to read the next token.
if (context.CurrentNode == null && context.CurrentState.DefaultAction == null)
ReadNextToken(context);
var action = GetNextAction(context);
action.Execute(context);
}
lexer.SpecialBag.InsertNodesIntoAstNode(context.Root.Result);
return ParseResult.FromContext(context);
}
示例8: GrammarReductionConflict
public GrammarReductionConflict(ParserState state, TokenGrammarElement lookahead, ParserAction action1, ParserAction action2)
{
State = state;
Lookahead = lookahead;
Action1 = action1;
Action2 = action2;
}
示例9: IncludeBinary
private bool IncludeBinary(List<string> tokens, ParserState state)
{
if (tokens.Count == 1)
throw new Exception(string.Format("No file specified for .incbin pragma", tokens[1]));
tokens[1] = tokens[1].Replace("\"", string.Empty);
byte[] data = GetBytesFromFile(state.WorkingDirectory + @"\" + tokens[1]);
if (data == null)
throw new Exception($"Error loading file '{tokens[1]}'");
int begin = 0, length = data.Length;
if (tokens.Count >= 3)
if (!Int32.TryParse(tokens[2], out begin))
throw new Exception("Third paramter for incbin must be numeric");
if (tokens.Count == 3)
{
length = length - begin;
}
if (tokens.Count == 4)
if (!Int32.TryParse(tokens[3], out length))
throw new Exception("Fourth paramter for incbin must be numeric");
if ((begin >= length) || (begin + length > data.Length))
throw new Exception("Out of bounds for incbin");
for (int i = 0; i < length; i++)
state.Code.Add(data[i + begin]);
return true;
}
示例10: ShiftParserAction
public ShiftParserAction(BnfTerm term, ParserState newState) {
if (newState == null)
throw new Exception("ParserShiftAction: newState may not be null. term: " + term.ToString());
Term = term;
NewState = newState;
}
示例11: Match
/// <summary>
/// Indicates if the current parser state matches the rule.
/// </summary>
/// <param name="state">The state.</param>
/// <returns></returns>
public override bool Match(ParserState state)
{
while (this.FirstSon.Match(state))
{
}
return true;
}
示例12: PrecedenceBasedParserAction
public PrecedenceBasedParserAction(BnfTerm shiftTerm, ParserState newShiftState, Production reduceProduction)
{
_reduceAction = new ReduceParserAction(reduceProduction);
var reduceEntry = new ConditionalEntry(CheckMustReduce, _reduceAction, "(Precedence comparison)");
ConditionalEntries.Add(reduceEntry);
DefaultAction = _shiftAction = new ShiftParserAction(shiftTerm, newShiftState);
}
示例13: XmlConverter
public XmlConverter(TextReader rdr, XmlWriter writer, IPlatform platform)
{
this.rdr = rdr;
this.writer = writer;
this.platform = platform;
this.parserState = new ParserState();
}
示例14: InternalMatch
protected override bool InternalMatch(ParserState state)
{
var old = state.Clone();
bool result = Child.Match(state);
state.Assign(old);
return result;
}
示例15: Parse
public static ParserState Parse(string source, IAbstractSyntaxTreePrinter printer = null, Rule rule = null)
{
if (rule == null)
rule = _grammar.file;
var state = new ParserState(source);
try
{
if (rule.Match(state))
{
if (state.AtEndOfInput())
{
if (printer != null)
printer.Print(state.GetRoot());
return state;
}
throw new ParsingException(state, rule, message: "Failed to read end of input");
}
throw new ParsingException(state, rule, message: "Failed to parse source");
}
catch (ParsingException e)
{
return state.Exception(e);
}
}