Re: [Flex-help] Python Lexical Analysis
flex is a tool for generating scanners
Brought to you by:
wlestes
From: Philip H. <red...@gc...> - 2010-08-10 19:54:56
|
Hey guys I've actually got a lot of stuff going at the moment now, but one problem is, say i am using a rule like: "\n" { return NEWLINE; } " "+ { int top_len = VEC_index( gpy_int, gpy_indent_stack, VEC_length( gpy_int, gpy_indent_stack )-1 ); if( top_len <= yyleng ) { if( top_len != yyleng ) VEC_safe_push( gpy_int, gc, gpy_indent_stack, yyleng ); return INDENT; } else if( top_len > yyleng ) { VEC_pop( gpy_int, gpy_indent_stack ); return DEDENT; } } <<EOF>> { int top_len = VEC_index( gpy_int, gpy_indent_stack, VEC_length( gpy_int, gpy_indent_stack )-1 ); if( top_len != 0 ) { VEC_pop( gpy_int, gpy_indent_stack ); return DEDENT; } else return 0; } So far thats what i do but its not right since, i need some mechanism for counting the number of " " rules are matched since yytext will return the text of the single rule. There is probably some simple way of doing that this works fine for simple things like: x = 2 y = x def foo( .. ): ... ... .. But fails on more indentation, any suggestions will be great when the parsing code is more concrete i will put up a separate a flex and bison parser code to simply parse python code so you can do what ever you want with it :) --Phil |