On Aug 24, 7:27 pm, "Dave!" <[EMAIL PROTECTED]> wrote:
> Hello!
> I'm using PLY-2.3 to build a C language compiler, and I need to know
> if there's any way to restart the lineno counter between lexical and
> syntactic analysis.
>
>  What I mean with that is that, first of all, I analyze the source
> code and show the tokens found by the lexer with lex.token() function.
> With that I obtain tokens that look like this:  LexToken(RBRACE, '}',
> 22, 485). The problem comes with the syntactic analysis, where I use
> yacc.parse() function. At this point, when it detects an error I made
> it print the token that caused it, but the line number isn't the real
> line number, it doesn't restart the lineno counter between lex.token()
> and yacc.parse().
>
>  For example, in a source code with 20 lines, lex.token() says that
> line 1 is line 1, but yacc.parse() says that line 1 is line 21...
>
>  What can I do??
>

My only suggestion (which probably you already know) is to try and
reset the 'lineno' attribute of your lexer.
Something like (not tested):

my_lexer = lex.lex()
my_lexer.input(text_to_parse)
my_lexer.lineno = 0
my_lexer.input(text_to_parse) # I guess...
my_parser = yacc.yacc( lexter=my_lexer )
my_parser(parse)


Ciao
-----
FB

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"ply-hack" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/ply-hack?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to