Exemplo n.º 1
0
def load_grammar(gt="Grammar.txt", gp=None,
                 save=True, force=False, logger=None):
    """Load the grammar (maybe from a pickle)."""
    if logger is None:
        logger = logging.getLogger()
    if gp is None:
        head, tail = os.path.splitext(gt)
        if tail == ".txt":
            tail = ""
        gp = head + tail + ".".join(map(str, sys.version_info)) + ".pickle"
    if force or not _newer(gp, gt):
        logger.info("Generating grammar tables from %s", gt)
        g = pgen.generate_grammar(gt)
        if save:
            logger.info("Writing grammar tables to %s", gp)
            try:
                g.dump(gp)
            except IOError, e:
                logger.info("Writing failed:"+str(e))
Exemplo n.º 2
0
    keywords: { [keyword: string]: number };
    /**
     * A mapping from a token to a symbol.
     * A dict mapping token numbers to arc labels
     */
    tokens: { [token: number]: number };
    /**
     * Actually maps from the node constructor name.
     */
    sym: { [name: string]: number };
    /**
     * A lookup table for converting the value in the `sym` mapping back to a string.
     */
    number2symbol: { [value: number]: string };
    /**
     * A list of DFAs, where each DFA is a list of
     * states, each state is is a list of arcs, and each
     * arc is a (i, j) pair where i is a label and j is
     * a state number.  The DFA number is the index into
     * this list.  (This name is slightly confusing.)
     * Final states are represented by a special arc of
     * the form (0, j) where j is its own state number.
     */
    states: Dfa[];
}
""" + pgen.generate_grammar('grammar-typhon.txt').genjs() + \
"""
// Nothing more to see here.
"""
open(sys.argv[1], "w").write(out)
Exemplo n.º 3
0
Arquivo: main.py Projeto: bjg/pytch
"@": Sk.token.tokens.T_AT,
"@=": Sk.token.tokens.T_ATEQUAL,
"==": Sk.token.tokens.T_EQEQUAL,
"!=": Sk.token.tokens.T_NOTEQUAL,
"<>": Sk.token.tokens.T_NOTEQUAL,
"<=": Sk.token.tokens.T_LESSEQUAL,
">=": Sk.token.tokens.T_GREATEREQUAL,
"~": Sk.token.tokens.T_TILDE,
"^": Sk.token.tokens.T_CIRCUMFLEX,
"<<": Sk.token.tokens.T_LEFTSHIFT,
">>": Sk.token.tokens.T_RIGHTSHIFT,
"**": Sk.token.tokens.T_DOUBLESTAR,
"+=": Sk.token.tokens.T_PLUSEQUAL,
"-=": Sk.token.tokens.T_MINEQUAL,
"*=": Sk.token.tokens.T_STAREQUAL,
"/=": Sk.token.tokens.T_SLASHEQUAL,
"%=": Sk.token.tokens.T_PERCENTEQUAL,
"&=": Sk.token.tokens.T_AMPEREQUAL,
"|=": Sk.token.tokens.T_VBAREQUAL,
"^=": Sk.token.tokens.T_CIRCUMFLEXEQUAL,
"<<=": Sk.token.tokens.T_LEFTSHIFTEQUAL,
">>=": Sk.token.tokens.T_RIGHTSHIFTEQUAL,
"**=": Sk.token.tokens.T_DOUBLESTAREQUAL,
"//": Sk.token.tokens.T_DOUBLESLASH,
"//=": Sk.token.tokens.T_DOUBLESLASHEQUAL,
"->": Sk.token.tokens.T_RARROW
};
""" + \
        pgen.generate_grammar().genjs()
open(sys.argv[1], "w").write(out)
Exemplo n.º 4
0
    /**
     * A mapping from a token to a symbol.
     * A dict mapping token numbers to arc labels
     */
    tokens: { [token: number]: number };
    /**
     * Actually maps from the node constructor name.
     */
    sym: { [name: string]: number };
    /**
     * A lookup table for converting the value in the `sym` mapping back to a string.
     */
    number2symbol: { [value: number]: string };
    /**
     * A list of DFAs, where each DFA is a list of
     * states, each state is is a list of arcs, and each
     * arc is a (i, j) pair where i is a label and j is
     * a state number.  The DFA number is the index into
     * this list.  (This name is slightly confusing.)
     * Final states are represented by a special arc of
     * the form (0, j) where j is its own state number.
     */
    states: Dfa[];
}

""" + pgen.generate_grammar('grammar.txt').genjs() + \
"""
// Nothing more to see here.
"""
open(sys.argv[1], "w").write(out)
Exemplo n.º 5
0
"}": T_RBRACE,
"@": T_AT,
"==": T_EQEQUAL,
"!=": T_NOTEQUAL,
"<>": T_NOTEQUAL,
"<=": T_LESSEQUAL,
">=": T_GREATEREQUAL,
"~": T_TILDE,
"^": T_CIRCUMFLEX,
"<<": T_LEFTSHIFT,
">>": T_RIGHTSHIFT,
"**": T_DOUBLESTAR,
"+=": T_PLUSEQUAL,
"-=": T_MINEQUAL,
"*=": T_STAREQUAL,
"/=": T_SLASHEQUAL,
"%=": T_PERCENTEQUAL,
"&=": T_AMPEREQUAL,
"|=": T_VBAREQUAL,
"^=": T_CIRCUMFLEXEQUAL,
"<<=": T_LEFTSHIFTEQUAL,
">>=": T_RIGHTSHIFTEQUAL,
"**=": T_DOUBLESTAREQUAL,
"//": T_DOUBLESLASH,
"//=": T_DOUBLESLASHEQUAL,
"->": T_RARROW
};
""" + \
        pgen.generate_grammar().genjs()
open(sys.argv[1], "w").write(out)