From: Ben Giddings Date: 2005-03-17T04:43:50+09:00 Subject: Re: Examples for racc? Jonathan Paisley wrote: > Perhaps it is sufficient to scan the line a couple of times with some > regular expressions? e.g.: > > class GCCInvocation > def initialize(line) > @includes = [] > @lang_opts = [] > @output = "" > @defines = [] > @sources = [] > line = " " + line > line.gsub!(/ -I ?(\S+)/) { @includes << $1; "" } > line.gsub!(/ -f ?(\S+)/) { @lang_opts << $1; "" } > line.gsub!(/ -o ?(\S+)/) { @output = $1; "" } > line.gsub!(/ -D ?(\S+)/) { @defines << $1; "" } > line.gsub!(/ ([^- ]\S+)/) { @sources << $1 } > @remainder = line.squeeze(' ') > end > end Yeah, that would work (with tweaked regexps), but I would imagine it would be less efficient. Each regexp is essentially a complex parser, and so in your example above, you have five parsers per gcc line. If I could do it in one parser, it would probably be quicker. I also think it might be easier to avoid mistakes due to complex regexps. I might try it though, it might be enough to do it the simple way. Ben