lexing nested parenthesis

Kristian Ovaska kristian.ovaska at helsinki.fi
Fri Aug 2 10:45:19 CEST 2002

pinard at iro.umontreal.ca (François Pinard):
>1) it looks like not supported anymore

Good open source never dies, though. :)

>2) it prohibits more than one grammar per module and
>forces a specific presentation (because it needs to read back the Python
>_source_ at run-time), 3) I had to fight it so it accepts a scanner of my
>choice, yet I do not remember the details as I write.

I agree on these. Maybe the author thought it would be easy to use if
everything is top-level, so to say. But it should have Parser and
Scanner base classes which you extend.

You have to do all this in the parsing module if you have the scanner
in another module (at least I did it so):

import lex, yacc 
import scanner
from scanner import tokens

# parser rules here

lexer = lex.lex(scanner)
parser = yacc.yacc()
parser.parse('source code', lexer)

You could probably build the scanner in the scanner module, but I
prefer it this way.

Kristian Ovaska <kristian.ovaska at helsinki.fi>

More information about the Python-list mailing list