private ParserActionType GetActionTypeForOperation(TokenAst current) { ITerminal thisTerm = current.Terminal; for (int i = _stack.Count - 2; i >= 0; i--) { if (_stack[i].Node == null) { continue; } IGrammarTerm term = _stack[i].Node.Term; if (!term.IsSet(TermOptions.IsOperator)) { continue; } ITerminal prevTerm = term as ITerminal; if (prevTerm.Precedence == thisTerm.Precedence) { return(thisTerm.Associativity == Associativity.Left ? ParserActionType.Reduce : ParserActionType.Shift); } ParserActionType result = prevTerm.Precedence > thisTerm.Precedence ? ParserActionType.Reduce : ParserActionType.Shift; return(result); } return(ParserActionType.Shift); }
internal ParserAction(ParserActionType actionType, ParserState newState, Production reduceProduction) { this.ActionType = actionType; this.NewState = newState; this.ReduceProduction = reduceProduction; this.ConflictResolver = null; }
public ActionRecord(ParserActionType actionType, ParserState newState, NonTerminal nonTerminal, int popCount) { ActionType = actionType; NewState = newState; NonTerminal = nonTerminal; PopCount = popCount; }
private ParserActionType GetActionTypeForOperation(Token current) { Terminal thisTerm = current.Terminal; for (int i = Stack.Count - 2; i >= 0; i--) { if (Stack[i].Node == null) { continue; } BnfTerm term = Stack[i].Node.Term; if (!term.IsSet(TermOptions.IsOperator)) { continue; } Terminal prevTerm = term as Terminal; //if previous operator has the same precedence then use associativity if (prevTerm.Precedence == thisTerm.Precedence) { return(thisTerm.Associativity == Associativity.Left ? ParserActionType.Reduce : ParserActionType.Shift); } ParserActionType result = prevTerm.Precedence > thisTerm.Precedence ? ParserActionType.Reduce : ParserActionType.Shift; return(result); } //If no operators found on the stack, do simple shift return(ParserActionType.Shift); }
private TokenPreviewHint(ParserActionType action) : base(action) { FirstString = String.Empty; OtherStrings = new HashSet <string>(); FirstTerminal = null; OtherTerminals = new HashSet <Terminal>(); MaxPreviewTokens = 0; }
public Production ReduceProduction; //defaulted to //constructor internal ConflictResolutionArgs(ParsingContext context, ParserAction conflictAction) { Context = context; Scanner = Context.Parser.Scanner; NewShiftState = conflictAction.NewState; ReduceProduction = conflictAction.ReduceProduction; Result = ParserActionType.Shift; //make shift by default }
public ProductionList ReduceProductions = new ProductionList(); //may be more than one, in case of conflict internal ActionRecord(string key, ParserActionType type, ParserState newState, Production reduceProduction) { Key = key; ActionType = type; NewState = newState; if (reduceProduction != null) { ReduceProductions.Add(reduceProduction); } }
public Production ReduceProduction; //defaulted to //constructor internal ConflictResolutionArgs(CompilerContext context, ParserAction conflictAction) { Context = context; Scanner = context.Compiler.Parser.Scanner; var coreParser = context.Compiler.Parser.CoreParser; CurrentParserState = coreParser.CurrentState; CurrentParserInput = coreParser.CurrentInput; NewShiftState = conflictAction.NewState; ReduceProduction = conflictAction.ReduceProduction; Result = ParserActionType.Shift; }
public ResolveInCode(ParserActionType parserAction, Func<ConflictResolutionArgs, bool> resolver) : base(parserAction) { this.resolver = resolver; }
public CustomGrammarHint(ParserActionType action) : base(HintType.Custom, null) { Action = action; }
public TokenPreviewHint(ParserActionType action, Terminal first) : this(action) { FirstTerminal = first; }
public TokenPreviewHint(ParserActionType action, string first) : this(action) { FirstString = first; }
public ActionRecord CreateDerived(ParserActionType type, Production reduceProduction) { return(new ActionRecord(this.Key, type, this.NewState, reduceProduction)); }
public ResolveInCode(ParserActionType parserAction, Func <ConflictResolutionArgs, bool> resolver) : base(parserAction) { this.resolver = resolver; }
} // for Reduce action internal ParserAction(ParserActionType actionType, ParserState newState, Production reduceProduction) { this.ActionType = actionType; this.NewState = newState; this.ReduceProduction = reduceProduction; }
public ProductionList ReduceProductions = new ProductionList(); //may be more than one, in case of conflict internal ActionRecord(string key, ParserActionType type, ParserState newState, Production reduceProduction) { Key = key; ActionType = type; NewState = newState; if (reduceProduction != null) ReduceProductions.Add(reduceProduction); }