//////////////////////////////////////////////////////////////////
//                          Elex:Lexiconizer Generator Win32 0.98b
//									  eias erinys fecit, 2001. 06.
//												  eias@nexon.co.kr
//											  sheplany@nownuri.net
//////////////////////////////////////////////////////////////////

*.  Ͽ

	Elex   ƴ 쿡 Ӱ Ͻ   ֽ
	. , ÿ  zip  ·  ֽñ  ٶ
	ϴ. ǹ  ø   ּҷ  ֽø  
	  亯 帮 ϰڽϴ.

0. What it Elex?

	 Է  r.e. (Regular Expression)   
	 ˾Ƴ  r.e. شϴ DFA (determined finite au-
	tomata) Է ־ ˾Ƴ  ֽϴ.

	Lexiconizer Generator ־ ū  r.e. ũƮ ޾
	 شϴ DFA  ϰ,  Է¿ ؼ DFA  
	  ְ ִ Ŭ( Elex) մϴ.

	Elex  ϵ Ǿ ֽϴ.
	
		Elex.exe		: Elex  
		Elex_cpp.def	: Elex Ǵ ҽ ø
		Elex_h.def		: Elex Ǵ  ø

1. version information

	v0.5b (2001. 01. 02)
		- pre-release

	v0.53b (2001. 01. 09)
		- minor changes
			:  Ŭ ̸  ̸ ũƮ 
			:   ̻ Elex Ŭ ÿ #include 
			:   ϰ 

	v0.57b (2001. 01. 30)
		- minor changes
			:     IsEnd() false̴  
			: ̹   ޾Ƽ  
			:  Ʈ ޾Ƽ  
			:   ̸   ߸  

	v0.9b (2001. 02. 02)
		- major changes
			: ũƮ   
				: #include ġ ߰ ũƮ  
				:   Լ,  ũƮ  
				: ū ó ũƮ  
				: ļ  ū  
				:  ū  ҽ  ġ 
			: r.e  
				:   ߰
				: 1  ߰
			: ũƮ ϰ r.e   
		- minor changes
			: ū     ҽ ڵ   ӵ
			    
			: r.e Ʈ ȿ \"     
			: r.e     ߸  
			: CToken ߻ϴ ޸  

	v0.96b (2001. 04. 21)
		- major changes
			: elex  ӵ 
			:  elex  ӵ  (binary search tree)
			: DFA  ߻ϴ ޸  
			: ESL 
		- minor changes
			:   ɺ 
			:  ε 

	v0.98b (2001. 06. 11)
		- major changes
			: class   ܺ Ͽ elex 
		- minor changes
			: #define _ELEXNAME_H__ κп elex  ̸ 
			        
		- known problems
			: µ 丮 ų  б ̰ų ϴ
			      ߻ ߸ 
			: ѱ ó Ұ


2. Elex 

	Elex [r.e. script file]

		[r.e script file]	: DFA   R.E.  


3. Regular Expression

	Elex ޾Ƶ r.e. ⺻ 1byte մϴ.  
	 1byte ڵ ̾  ڵ ̾    մ
	.

		e.g) abc		: abc  ū ǹ

	ȣ  ǹ  켱   ǹմϴ. *, +, ? 
	 Ŭ (Closure) ǹմϴ. ȣ ̾  Ŭ  
	  ϴ. *, +, ?  0~ѹ, 1~ѹ,  0
	Ȥ 1 ݺ ǹմϴ.

		e.g) a*			: "", a, aa, aaa, aaaa, aaaaa, ...
		     ab*c		: ac, abc, abbc, abbbc, abbbbc, ...
			 a(bc)*d	: ad, abcd, abcbcd, abcbcbcd, ...
			 a(bc)+d	: abcd, abcbcd, abcbcbcd, ...
			 a(bc?)d	: ad, abcd


	~ not ǹմϴ. ǿڰ ƴ   ٴ 
	ϴ. Ŭ   ϴ.

		e.g) a~			: b, c, d, e, ..., 1, 2, 3, ..., A, B, ...
		     a(bc)~d	: a1d, abd, abbd, a2d, ...  abcd 


	| or ǹմϴ.

		e.g) a|b		: a, b
		     a|(bc)*	: a, "", bc, bcbc, bcbcbc, bcbcbcbc, ...
			 (a|b)*		: "", a, b, ab, ba, abb, aba, aab, ...


	[] []ȿ ִ ڵ ̾ յǴ  ƴ϶ or 
	ȴٴ  ǹմϴ.

		e.g) [abc]		: a, b, c				(same as (a|b|c))
			 [ab]*		: "", a, b, ab, ba, ... (same as (a|b)*)


	"" ""ȿ ڵ ڷ  ʴ´ٴ  ǹ
	ϴ. escape ڴ  մϴ.

		e.g) a"*"		: *						(not as a*)
		     "*+?~"		: *+?~


	\ escape ڸ ǹմϴ.

		e.g) \n (enter), \t (tab), \b (backspace), \x10, \012, ...


	"" ""ȿ ڵ ڷ  ʴ´ٴ  ǹ
	# sharp ڸ ǹմϴ. \ ۵Ǵ 2Ʈ escape 
	 ƴ 쿡 #ڿ   ó˴ϴ. #ڴ  ܼ ڿ
	̾ 1Ʈ ǹմϴ.

		e.g) #", \"		: "


	_ ƹ ڳ   ǹմϴ.

		e.g) _			: a, b, c, ..., A, B, c, ..., 0, 1, 2...


	-    ϳ ǹմϴ.
	
		e.g) a-c		: a, b, c				(same as a|b|c)
		     c-a		: a, b, c				(same as a-c)


	{} {} ڵ ҹ 谡 ٴ Դϴ.  ִ
	 ( (), [], {} )  켱   ϴ.

		e.g) {abc}		: abc, ABC, aBc, aBC, Abc, ...
		     {ab}|{bb}	: ab, AB, aB, Ab, bb, BB, bB, Bb


4. r.e script grammar

	<script> -> <output def> <pre-script def> <lex def list>

	<output def> ->    <elexname def> <elexfilename def>
					|| <elexfilename def> <elexname def>

	<elexname def> -> elexname = [µ elex Ŭ ̸];
	<elexfilename def> -> elexfilename = "[µ elex  ̸]";

	<pre-script def> -> <pre-include def> <pre-define def>

	<pre-include def> -> include = <block>; || null
	<pre-define  def> -> define =  <block>; || null

	<block> -> {*[ũƮ]*}
	<_block> -> <block> || null
	<re> -> {:[r.e]:}

	<lex def list> -> <lex def> <lex def list> || null

	<lex def> -> [ū ̸] <ignore> <re> <_block> <value>;

	<ignore> -> (ignore) || null
	<value> -> (value) <block> || null

	e.g) test.lex
		// test.lex
		elexname = CTestElex;
		elexfilename = ".\Test\TestElex";

		// precompiled    ̴.
		include = {*
		#include "stdafx.h"
		*};

		//   Լ
		define = {*
		static int g_bFinished = false;
		*};

		// ٷ Ѿ鼭 CTestElexFrom m_iRow 1 
		NEWLINE	(ignore)	{:\r?\n:} {*NEWLINE();*};
		INTEGER				{:[#+#-]?0-9+:}
		(value) {*
			//RETURN new int(TEXT);
			RETURN atoi(TEXT);
		*};


5.  Elex 

	 Elex Ͽ [class name] Ŭ  [class name]From,
	[class name]FromFile,  [class name]FromString    Ŭ
	ֽϴ.  [class name] Ŭ  ϴ 
	 ڽϴ.

		run)

		some drive:\some directory>Elex test.lex
		Elex:Lexiconizer Generator Win32 0.98b, 2001. 06. 11, eias erinys fecit.

		Loading Script...OK

		Dump Script :
			Elex classname will be CTestElex
			Elex  filename will be TestElex (.\Test\TestElex)

			Pre-Script defined. (header inclusion)
			Pre-Script defined. (body)

			<NEWLINE, si> = '\r?\n'
			<INTEGER, v> = '[#+#-]?0-9+'

		Generating DFA...
		Processing <NEWLINE> = '\r?\n' :
		Construction of NFA resulted in 6 states.
		Computing DFA from NFA......
		Conversion of NFA to DFA resulted in 3 states.
		Simplifying equivalent states.....
		Simplification of DFA resulted in 3 states.

		Processing <INTEGER> = '[#+#-]?0-9+' :
		Construction of NFA resulted in 12 states.
		Computing DFA from NFA.......
		Conversion of NFA to DFA resulted in 4 states.
		Simplifying equivalent states.....
		Simplification of DFA resulted in 3 states.

		Finalize...
		Construction of NFA resulted in 7 states.
		Computing DFA from NFA........
		Conversion of NFA to DFA resulted in 5 states.
		Simplifying equivalent states.....
		Simplification of DFA resulted in 5 states.

		Dump Elex class files :
		.\Test\TestElex.h
		.\Test\TestElex.cpp

		some drive:\some directory>

	̷  CTestElex ؼ

		code)

		CTestElex elex;

		elex.initMove();
		elex.move('+');
		elex.move('0');
		if (!elex.move('a')) {
			if (elex.isFinal()) {
				printf("<%s>\n", 
					elex.getTokenName(elex.getResult()));
			}
			elex.initMove();
		}

	  ڵ带 Ű,

		<INTEGER>

	   ˴ϴ. [class name]FromFile    
	ϱ մϴ.  ڵ带 Ű, 

		code)

		CTestElexFromFile elex("test.txt");
		CTestElexFromFile::CToken token;

		while (!elex.isEnd()) {
			token = elex.GetNextToken();
			if (!token.GetIgnore()) {
				printf("line %d, col%d, %s(%s), %d\n", 
					elex->GetRow(), elex->GetCol(),
					elex->GetTypeName(), elex->GetText(),
					(int) elex->Value());
			}
		}

		test.txt)

			123
			12334

			12aa-12

	   ɴϴ.

		output)

			line 1, col 1, INTEGER(123), 123
			line 2, col 1, INTEGER(12334), 12334
			line 4, col 1, INTEGER(12), 12
			line 4, col 3, failed(a)
			line 4, col 4, failed(a)
			line 4, col 5, INTEGER(-12), -12

	[class name]FromString    ϸ   
	   ɴϴ.

		code)

		CTestElexFromString elex("123\n12334\n\n12aa-12\n");
		CTestElexFromString::CToken token;

		while (!elex.isEnd()) {
			token = elex.GetNextToken();
			if (!token.GetIgnore()) {
				printf("line %d, col%d, %s(%s)\n", 
					elex->GetRow(), elex->GetCol(),
					elex->GetTypeName(), elex->GetText());
			}
		}

	(ADVANCED) [class name]From ؼ, GetNextChar()  
	̵ϸ   Ŭ   ֽϴ.
	(ADVANCED) Elex Script Examples 丮 Elex.lex RegExp.
	lex ̿ؼ ϴ.

