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 21:34:10
|
Hey Ignore my previous post now using: "\n" { return NEWLINE; } " "+ { int top_len = VEC_index( gpy_int, gpy_indent_stack, VEC_length( gpy_int, gpy_indent_stack )-1 ); int indent = yyleng/4; if( top_len <= indent ) { if( top_len != indent ) { VEC_safe_push( gpy_int, gc, gpy_indent_stack, indent ); } return INDENT; } else if( top_len > indent ) { 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; } Didnt realise yyleng records the entire length of matched rules when using <something>+ it recorded the entire length of it so all i needed to do was divide. --Phil |