Qaupot Blog
Software Engineering, Trip

flex (lex) : The Fast Lexical Analyzer

http://flex.sourceforge.net/

flex๋Š” ์Šค์บ๋„ˆ(๋•Œ๋•Œ๋กœ Tokenizer๋ผ๊ณ  ๋ถˆ๋ฆฝ๋‹ˆ๋‹ค)๋ฅผ ๋งŒ๋“ค๊ธฐ ์œ„ํ•œ ๋„๊ตฌ์ž…๋‹ˆ๋‹ค.
์ง€์ •๋œ ๊ทœ๊ฒฉ์— ๋งž์ถ”์–ด lexํŒŒ์ผ์„ ๋งŒ๋“ค๊ณ , ์ด๋ฅผ flex๋ฅผ ํ†ตํ•ด ๋ณ€ํ™˜ํ•˜๋ฉด lex.yy.cํŒŒ์ผ์„ ์ƒ์„ฑํ•ด ๋ƒ…๋‹ˆ๋‹ค.
์ด ํŒŒ์ผ์€ ๋‹ค์‹œ gcc๋‚˜ ms vc์ปดํŒŒ์ผ๋Ÿฌ๋“ฑ์„ ํ†ตํ•ด ์ปดํŒŒ์ผ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ž…๋ ฅ ํŒŒ์ผ์€ ๋‹ค์Œ์˜ ํ˜•ํƒœ๋ฅผ ๋”ฐ๋ฆ…๋‹ˆ๋‹ค.

definitions
%%
rules
%%
user code

์ž์„ธํ•œ ํ˜•ํƒœ๋Š” http://flex.sourceforge.net/manual/Format.html#Format ๋ฅผ ์ฐธ๊ณ ํ•ด์ฃผ์„ธ์š”.

ํŒจํ„ด์€ Regular Expression(์ •๊ทœํ‘œํ˜„์‹)์— ๊ธฐ๋ฐ˜ํ•ฉ๋‹ˆ๋‹ค.
http://flex.sourceforge.net/manual/Patterns.html#Patterns

์ฃผ์„, ์‹ค์ˆ˜, ์ด๋ฉ”์ผ์ฃผ์†Œ๋“ฑ์˜ ๋„๋ฆฌ ์‚ฌ์šฉ๋˜๋Š” ์ •๊ทœํ‘œํ˜„์‹์€
http://www.regular-expressions.info/examples.html ์—์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์˜ˆ์ œ์ฝ”๋“œ๋Š”
http://flex.sourceforge.net/manual/Simple-Examples.html#Simple-Examples ๋ฅผ ์ฐธ๊ณ ํ•ด์ฃผ์„ธ์š”.

VC์™€ ์—ฐ๊ณ„ํ•ด์„œ ์‚ฌ์šฉํ•˜์‹œ๋ ค๋ฉด ์ปดํ“จํ„ฐ์˜ path ํ™˜๊ฒฝ๋ณ€์ˆ˜์— flex๊ฐ€ ์œ„์น˜ํ•œ ํด๋”๋ฅผ ์ถ”๊ฐ€ํ•ด ์ฃผ์‹œ๊ณ ,
๋ง์ปค ์ข…์†์„ฑ์— libfl.a๋ฅผ ์ถ”๊ฐ€ํ•˜์‹  ํ›„,
๋นŒ๋“œ ์ „ ์ด๋ฒคํŠธ์— flex "$(ProjectDir)ํŒŒ์ผ๋ช….l "์™€ ๊ฐ™์€ ํ˜•ํƒœ๋กœ ์ง€์ •ํ•ด์ฃผ์‹œ๋ฉด ํŽธ๋ฆฌํ•ฉ๋‹ˆ๋‹ค.

http://www.gnu.org/software/flex/
์œ„ ์‚ฌ์ดํŠธ์— ๋ช…์‹œ๋˜์–ด ์žˆ๋Š”๊ฒƒ์ฒ˜๋Ÿผ flex๋Š” GNU ํ”„๋กœ์ ํŠธ๊ฐ€ ์•„๋‹ˆ๋ฉฐ, BSD์— ๊ฐ€๊นŒ์šด ๋ผ์ด์„ผ์Šค๋ฅผ ์ ์šฉ๋ฐ›์Šต๋‹ˆ๋‹ค.

(์†Œ์Šค์˜ CopyingํŒŒ์ผ)

Flex carries the copyright used for BSD software, slightly modified because it originated at the Lawrence Berkeley (not Livermore!) Laboratory, which operates under a contract with the Department of Energy:

(์†Œ์Šค์˜ readmeํŒŒ์ผ)

Note that flex is distributed under a copyright very similar to that of BSD Unix, and not under the GNU General Public License (GPL), except for the "configure" script, which is covered by the GPL.

์ด ๋ธ”๋กœ๊ทธ๋Š” ๊ฐœ์ธ ๋ธ”๋กœ๊ทธ์ž…๋‹ˆ๋‹ค. ๊ฒŒ์‹œ๊ธ€์€ ์˜ค๋ฅ˜๋ฅผ ํฌํ•จํ•˜๊ณ  ์žˆ์„ ์ˆ˜ ์žˆ์ง€๋งŒ, ์ €์ž๋Š” ์˜ค๋ฅ˜๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด ๋…ธ๋ ฅํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.
๊ฒŒ์‹œ๊ธ€์— ๋ณ„๋„์˜ ๊ณ ์ง€๊ฐ€ ์—†๋Š” ๊ฒฝ์šฐ, ํฌ๋ฆฌ์—์ดํ‹ฐ๋ธŒ ์ปค๋จผ์ฆˆ ์ €์ž‘์žํ‘œ์‹œ-๋น„์˜๋ฆฌ-๋ณ€๊ฒฝ๊ธˆ์ง€ 4.0 ๋ผ์ด์„ ์Šค๋ฅผ ๋”ฐ๋ฆ…๋‹ˆ๋‹ค.

This blog is personal blog. published posts may contain some errors, but author doing efforts to clear errors.
If post have not notice of license, it under creative commons Attribution-NonCommercial-NoDerivatives 4.0.