[antlr-interest] Problems with python
Ronny Herzog
ronny-herzog at web.de
Sat Jun 10 01:58:40 PDT 2006
Hello!
I have the following problem by checking out antlr for python. I wrote a
very small grammar from a tutorial and generated some python code. But I
got an error message I cannot handle:
>
Traceback (most recent call last):
File "tut1.py", line 17, in ?
main()
File "tut1.py", line 14, in main
P.series()
File "/home/earl/sourcecode/pylangs/tutorial1/SeriesParser.py", line
50, in series
self.element()
File "/home/earl/sourcecode/pylangs/tutorial1/SeriesParser.py", line
72, in element
la1 = self.LA(1)
File "/usr/lib/python2.4/antlr.py", line 2025, in LA
return self.inputState.input.LA(i)
AttributeError: 'NoneType' object has no attribute 'LA'
<
The code is not much, so I post it here:
tut1.g
>
options
{
language = "Python";
}
class IntAndIDLexer extends Lexer;
INT : ('0'..'9')+ ;
ID : ('a'..'z')+ ;
COMMA: ',' ;
NL : '\n';
class SeriesParser extends Parser;
/** Match an element (INT or ID) with possibly a
* bunch of ", element" pairs to follow matching
* input that looks like 32,a,size,28923,i
*/
series
: element (COMMA element )* NL
;
/** Match either an INT or ID */
element: INT | ID ;
<
and the python code tut1.py:
>
import IntAndIDLexer
import SeriesParser
import sys
import antlr
def main():
L = IntAndIDLexer.Lexer()
P = SeriesParser.Parser()
P.setFilename(L.getFilename())
for token in L :
print token
P.series()
if __name__ == "__main__":
main()
<
Thx for any help!
Earl
--
Ronny Herzog
Bautzner Str. 55
01099 Dresden
0176/70082636
0351/7966484
More information about the antlr-interest
mailing list