0

I have a grammar for parsing SQL scripts. The lexer for the grammar works fine with the following code:

    with open("/path/to/sql/script.sql") as f:
    query = f.read().upper()
    tokenStream = antlr3.StringStream(query)
    lexer = MyLexer(tokenStream)
    for token in lexer:
        # process the token

    pass

I don't know how to parser the I have a grammar for parsing SQL scripts. The lexer for the grammar works fine with the following code. There is not much documentation forthe Python runtime on the ANLTR's website.

1 Answer 1

1

Typically what you want to do after/past the above, is to create a TokenStream from the output of the Lexer and feed these tokens to your Parser. BTW the StringStream that you supply as input to the lexer is not really a token stream despite the name you gave it.

Maybe try something like:

...
lexer = MyLexer(tokenStream)
// Get a token stream
tokens = CommonTokenSream(lexer)
// Feed it to the parser   (assumes you named the Grammar/Parser  "MyParser")
parser = MyParser(tokens)

// Invoke the topmost rule (or some other rule) of the grammar, to start
// the parsing process
parser.SomeRule()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.