Ejemplo n.º 1
0
        private static MNode lexInput(MInputStream input)
        {
            ByteAutomata ba = new ByteAutomata();

            automata = ba;
            defineTransitions(ba);
            ba.next((byte)1); // set first state
            root         = new MNode(null, 0, "<ROOT>");
            currentExpr  = root;
            currentBlock = null;
            currentToken = null;
            lastStart    = 0;
            ba.run(input);
            ba.step((byte)' '); // ended cleanly: last white space
            if (currentBlock != null)
            {
                MeanCS.print("closing parenthesis missing at the end");
                ba.ok = false;
            }
            if (!ba.ok)
            {
                ba.printError();
                root = null;
                return(null);
            }
            MeanCS.verbose("\nFINISHED!");
            return(root);
        }
Ejemplo n.º 2
0
 private static void defineTransitions(ByteAutomata ba)
 {
     stateSpace  = ba.addState("space");
     stateName   = ba.addState("name");
     stateNumber = ba.addState("number");
     ba.transition(stateSpace, whiteSpace, null);
     ba.transition(stateSpace, letters, () => { next(stateName); });
     ba.transition(stateSpace, numbers, () => { next(stateNumber); });
     ba.transition(stateSpace, expressionBreak, () => { exprBreak(); });
     ba.transition(stateSpace, blockStart, () => { addBlock(); });
     ba.transition(stateSpace, blockEnd, () => { endBlock(); });
     ba.transition(stateName, letters, null);
     ba.transition(stateName, whiteSpace, () => { addToken(NODE_TEXT); next(stateSpace); });
     ba.transition(stateName, blockStart, () => { addToken(NODE_TEXT); stay(); next(stateSpace); });
     ba.transition(stateName, blockEnd, () => { addToken(NODE_TEXT); stay(); next(stateSpace); });
     ba.transition(stateName, expressionBreak, () => { addToken(NODE_TEXT); exprBreak(); next(stateSpace); });
     ba.transition(stateNumber, numbers, null);
     ba.transition(stateNumber, whiteSpace, () => { addToken(NODE_NUMBER); next(stateSpace); });
     ba.transition(stateNumber, blockStart, () => { addToken(NODE_NUMBER); stay(); next(stateSpace); });
     ba.transition(stateNumber, blockEnd, () => { addToken(NODE_NUMBER); stay(); next(stateSpace); });
     ba.transition(stateNumber, expressionBreak, () => { addToken(NODE_NUMBER); exprBreak(); next(stateSpace); });
 }