Beispiel #1
0
def parse(files, user_options, symbol_table):
    """Parses the files using the symbol_table to determine what are atoms

    files -- the files to be parsed
    options -- the options specified by the user
    symbol_table -- the symbol table defined by the tokenizer

    """
    global options
    options = user_options

    global symbolTable
    symbolTable = symbol_table

    for fileName in files:
        file_content = fileToString(fileName, options)
        global inputStack
        inputStack = shlexToList(tokenizer.parseWords(file_content))
        try:
            parseF()
        except ParserException as e:
            print "message: " + e.value
            print file_content
            printCharacterException(file_content, e.character)
            print "file: " + fileName
            if(optionParseAll not in options):
                raise ParserException("Parsing not correct")
Beispiel #2
0
def printCharacterException(file_content, character):
    """
    prints the location of the error in the file
    """
    stack = shlexToList(tokenizer.parseWords(file_content))
    stack.reverse()
    stack.insert(character - 1, ">>>>>")
    stack.insert(character + 1, "<<<<<")
    file = " ".join(stack)
    print file
def createTree(fileContent):

    global stack
    stack = shlexToList(tokenizer.parseWords(fileContent))

    tok = stack.pop()

    # sanity check, this should always be true at this point
    if tok != "(":
        raise CreateParseTreeException(stack)

    root = createTreeHelper()

    # stack should now be empty
    if len(stack) != 1 and stack[0] != "$":
        raise CreateParseTreeException("Stack not empty")

    return root