示例#1
0
文件: LRParser.cs 项目: singba/SSharp
        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);
        }
示例#2
0
 internal ParserAction(ParserActionType actionType, ParserState newState, Production reduceProduction)
 {
     this.ActionType       = actionType;
     this.NewState         = newState;
     this.ReduceProduction = reduceProduction;
     this.ConflictResolver = null;
 }
示例#3
0
 public ActionRecord(ParserActionType actionType, ParserState newState, NonTerminal nonTerminal, int popCount)
 {
     ActionType  = actionType;
     NewState    = newState;
     NonTerminal = nonTerminal;
     PopCount    = popCount;
 }
示例#4
0
 public ActionRecord(ParserActionType actionType, ParserState newState, NonTerminal nonTerminal, int popCount)
 {
   ActionType = actionType;
   NewState = newState;
   NonTerminal = nonTerminal;
   PopCount = popCount;
 }
示例#5
0
        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);
        }
示例#6
0
 private TokenPreviewHint(ParserActionType action) : base(action)
 {
     FirstString      = String.Empty;
     OtherStrings     = new HashSet <string>();
     FirstTerminal    = null;
     OtherTerminals   = new HashSet <Terminal>();
     MaxPreviewTokens = 0;
 }
示例#7
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
 }
示例#8
0
        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);
            }
        }
示例#9
0
        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;
 }
示例#11
0
 public CustomGrammarHint(ParserActionType action) : base(HintType.Custom, null)
 {
     Action = action;
 }
示例#12
0
 public TokenPreviewHint(ParserActionType action, Terminal first) : this(action) {
     FirstTerminal = first;
 }
示例#13
0
 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));
 }
示例#15
0
 public ResolveInCode(ParserActionType parserAction, Func <ConflictResolutionArgs, bool> resolver)
     : base(parserAction)
 {
     this.resolver = resolver;
 }
示例#16
0
        }                                                 // for Reduce action

        internal ParserAction(ParserActionType actionType, ParserState newState, Production reduceProduction)
        {
            this.ActionType       = actionType;
            this.NewState         = newState;
            this.ReduceProduction = reduceProduction;
        }
示例#17
0
    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);
    }