How to use the ply.yacc.parse function in ply

To help you get started, we’ve selected a few ply examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github soartech / soar / GGP / analogy / collapse / src / gdlyacc.py View on Github external
def p_empty(p):
	'empty : '
	pass

yacc.yacc()

import sys

if len(sys.argv) < 2:
	print "need kif file"
	sys.exit(1)

file = open(sys.argv[1], 'r').read()

result = yacc.parse(file)

#import psyco
#psyco.full()

try:
	collapse(ir.get_rules())
except KeyboardInterrupt:
	pass
github rspivak / tinypie / src / tinypie / tinypie2.py View on Github external
def main(text):
    """Usage:

    $ cat << EOF | python tinypie2.py
    > print x
    > x = 7
    > print 5
    > EOF
    7
    5
    """
    # Start the parser
    lex.lex()
    yacc.yacc()
    visitor = NodeVisitor()
    tree = yacc.parse(text)
    visitor.visit(tree)
github pysb / pysb / parse_toy.py View on Github external
from ply import yacc, lex
import toyyacc

rules = '''
E + S <-> ES (1,2)
ES --> E + P (0.3)
'''

model = yacc.parse(rules)

print
print "rules:"
for r in model.rules:
    print ' ', r

model.finalize()

print
print "equations:"
for s in model.species.values():
    print '  d[%s]/dt = %s' % (s.name, ' + '.join(str(t) for t in s.mass_action_terms))
github RyanFleck / Projects / py / rcf024_ply.py View on Github external
p[0] = names[p[1]]
    except LookupError:
        print("Undefined name '%s'" % p[1])
        p[0] = 0

def p_error(p):
    print("Syntax error at '%s'" % p.value)

yacc.yacc()

while True:
    try:
        s = input('calc > ')   # use input() on Python 3
    except EOFError:
        break
    yacc.parse(s)
github echronos / echronos / external_tools / ply_info / example / unicalc / calc.py View on Github external
def p_error(p):
    if p:
        print "Syntax error at '%s'" % p.value
    else:
        print "Syntax error at EOF"

import ply.yacc as yacc
yacc.yacc()

while 1:
    try:
        s = raw_input('calc > ')
    except EOFError:
        break
    if not s: continue
    yacc.parse(unicode(s))
github LogicalTrust / minerva_lib / compiler / parser.py View on Github external
def p_empty(p):
    'empty :'
    pass

def p_error(t):
    print("Syntax error '%s' at line %d" % (t.value, t.lexer.lineno))

yacc.yacc()

def parse(content):
    return yacc.parse(content)

if __name__ == '__main__':
    import sys
    if len(sys.argv) > 1:
        print(yacc.parse(open(sys.argv[1]).read()))
    else:
        while 1:
            try:
                line = raw_input('parser_test> ')
                print(yacc.parse(line))
            except EOFError:
                break
github gem5 / gem5 / ext / ply / example / optcalc / calc.py View on Github external
except LookupError:
        print "Undefined name '%s'" % t[1]
        t[0] = 0

def p_error(t):
    print "Syntax error at '%s'" % t.value

import ply.yacc as yacc
yacc.yacc(optimize=1)

while 1:
    try:
        s = raw_input('calc > ')
    except EOFError:
        break
    yacc.parse(s)
github soartech / soar / GGP / translator / src / gdlyacc.py View on Github external
def p_error(t):
	print "error: %s at line %d" % (t.value, t.lexer.lineno)
	#print "Syntax error on line %d" % p.lineno(1)

def p_empty(p):
	'empty : '
	pass

yacc.yacc()

import sys

file = open(sys.argv[1], 'r').read()

result = yacc.parse(file)
github dabeaz / ply / example / calc / calc.py View on Github external
if p:
        print("Syntax error at '%s'" % p.value)
    else:
        print("Syntax error at EOF")

import ply.yacc as yacc
yacc.yacc()

while 1:
    try:
        s = raw_input('calc > ')
    except EOFError:
        break
    if not s:
        continue
    yacc.parse(s)
github taurus-org / taurus / lib / taurus / qt / qtgui / graphic / jdraw / jdraw_parser.py View on Github external
def parse(filename=None, factory=None):

    if filename is None or factory is None:
        return

    _, p = new_parser()

    p.factory = factory
    p.modelStack = []
    p.modelStack2 = []

    res = None
    try:
        filename = os.path.realpath(filename)
        f = open(filename)
        res = yacc.parse(f.read())
    except:
        log = Logger('JDraw Parser')
        log.warning("Failed to parse %s" % filename)
        log.debug("Details:", exc_info=1)
    return res