def __init__(self, options, name):
     self.lexer = MyLexer(options, name)
     if options['program'] == 1:
         self.parser = yacc.yacc(module=MyCRules(Node, self.lexer.tokens))
         self.out = open("./results/minic/{}_parser".format(name), "w")
     if options['program'] == 2:
         self.parser = yacc.yacc(module=MyJsonRules(Node, self.lexer.tokens))
         self.out = open("./results/smacco/{}_parser".format(name), "w")
Exemple #2
0
 def eval_parser(self):
     if self.data:
         try:
             self.parser = yacc.yacc()
             global Parser
             Parser = self.parser
             self.parser.parse(self.data, tracking=True)
             return True
         except Exception, e:
             print "[ERROR]", e
             return False
Exemple #3
0
 def eval_parser(self):
     if self.data:
         try:
             self.parser = yacc.yacc()
             global Parser
             Parser = self.parser
             self.parser.parse(self.data, tracking=True)
             return True
         except Exception, e:
             print "[ERROR]", e
             return False
Exemple #4
0
    
    id_error = list_errors.count + 1  if list_errors.count > 0 else 1

    try:
        number_error, description = get_type_error(33)
        print(str(p.value))
        description += ' or near ' + str(p.value) 
        column = find_column(p)
        list_errors.insert_end(Error(id_error, 'Syntactic',number_error ,description, p.lineno, column))
    except AttributeError:
        number_error, description = get_type_error(1)
        print(number_error, description)
        list_errors.insert_end(Error(id_error, 'Syntactic', number_error, description, 'EOF', 'EOF'))
    id_error += 1

parser = yacc.yacc()
def parse(inpu):
    global input
    global list_errors
    list_errors.remove_all()
    lexer = lex.lex()
    lexer.lineno = 1
    input = inpu
    get_text(input)
    return parser.parse(inpu, lexer=lexer)

# parser = yacc.yacc()
# graficadora = GraficarAST()
# s = '''SELECT EXTRACT(SECOND FROM TIMESTAMP '2001-02-16 20:38:40');
#        SELECT User.name FROM Users INNER JOIN Ordenes ON Ordenes.id = Users.id GROUP BY ID;
#        SELECT COUNT(*) AS Name FROM User;
Exemple #5
0
#### empty production
def p_empty(p):
    '''empty :'''


#### Catastrophic error handler
def p_error(p):
    if not p:
        raise EOFException("Unexpected end of file.")
    raise SyntaxErrorException("syntax error", p.lineno)


import libs.ply.yacc as yacc
import libs.ply.lex as lex

VYPeParser = yacc.yacc()


def parse(data, debug=0):
    global VYPeParser, semantic
    semantic = Semantic()
    semantic.add_predefined_function('void', 'print', infinite=True)
    semantic.add_predefined_function('string', 'read_string')
    semantic.add_predefined_function('char', 'read_char')
    semantic.add_predefined_function('int', 'read_int')
    semantic.add_predefined_function('char', 'get_at', ['string', 'int'])
    semantic.add_predefined_function('string', 'set_at', ['string', 'int', 'char'])
    semantic.add_predefined_function('string', 'strcat', ['string', 'string'])

    p = VYPeParser.parse(data, debug=debug)
    semantic.check_main_function()
Exemple #6
0
# Build the lexer
lexer = lex.lex()

# Give the lexer some input
lexer.input(data)

"""
for tok in lexer:
    print tok

"""

print #blank line

# Build the parser
parser = yacc.yacc(debug=True)
#parse it!    
result = parser.parse(data)

print "======================"
print "Global scope: ", global_scope
print "Local Scopes: ", all_local_scopes
print "======================"


#draw the graph...
print "%s lexer errors and %s syntax errors occurred.\n" % (lexerrs, syntaxerrs)
if lexerrs + syntaxerrs > 0:
    print "As some errors occurred, the tree is probably not correct." 
    print "There is some chance that it will still be able to be rendered correctly, but it is not guaranteed."