Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1I3qEO-0004WA-C8 for mharc-grub-devel@gnu.org; Thu, 28 Jun 2007 05:24:04 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1I3qEM-0004Vn-8b for grub-devel@gnu.org; Thu, 28 Jun 2007 05:24:02 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1I3qEK-0004V8-Fv for grub-devel@gnu.org; Thu, 28 Jun 2007 05:24:01 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1I3qEK-0004V3-9X for grub-devel@gnu.org; Thu, 28 Jun 2007 05:24:00 -0400 Received: from m15-112.126.com ([220.181.15.112]) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1I3qEE-0005TX-0p for grub-devel@gnu.org; Thu, 28 Jun 2007 05:24:00 -0400 Received: from localhost (unknown [218.240.201.197]) by smtp2 (Coremail) with SMTP id wKjJDLCLTQQlfoNGf9lKBg==.33655S2; Thu, 28 Jun 2007 17:23:49 +0800 (CST) Date: Thu, 28 Jun 2007 17:23:23 +0800 From: Bean To: The development of GRUB 2 Message-ID: <20070628092323.GA2319@ws3.vdp.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.13 (2006-08-11) X-Coremail-Antispam: 1U3Yxn0WfASr-VFAUDIcSsGvfJTA7C26xCjj4IEI4klw4CSww Aac4AC62xK8xCEY4vEwIxC4wC2zVAF1VAY17CE14v26r1j6r15Mx02cVAKzwASzI0EjI02 j7AqF2xKxwAv7VC0I7IYx2IY67AKxVWUJVWUGwCF72vE52k0Y41lYx0Ex4A2jsIE14v26r 1j6r4UM7C26IkvcIIF6IxKo4kEV4ylc2IjII80xcxEwVAKI48JM7AC8VAFwI0_Jr0_Gr1l n4vEIxA26c8GOVWUur1xXr4lb4IE77IF4wAFIxvE14AKwVWUJVWUGwAqx4xG64xvF2IEw4 CE5I8CrVC2j2Wlb7Iv0xC_CrUanT9S1TB71UUUUUUa7-sFnT9fnUUI43ZEXa7IUeDCztUU UUUFnT9fnV15pF4xZFy8XryfKr17Xw45Zw17toXrpry8WFb_Jr1UXa4UKw4IvF12qFZ5Jr 45ZF13tas7A3WDW34Fga4Fvan5uFs5ZwnIkFyY9FZ3GFy5AF45CrZxKw1jyr9aq X-detected-kernel: Linux 2.6, seldom 2.4 (older, 4) Subject: Some suggestion about the script engine X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 28 Jun 2007 09:24:02 -0000 notice something strange about the script engine: 1. Command is executed as soon as it's parsed, myabe we should wait until the whole file is analysed. 2. Menu entry is parsed twice. 3. Memory consumption is huge, each token would take up 2048/2096 bytes. Maybe we should allocate just enough memory to hold the string. 4. Some problem with syntax For example, if ls; then ls fi works (shouldn't be), but if ls; then ls; fi doesn't (should be), and if ls; then ls fi result in an infinite loop. I'm thinking about a new architecture. The script can be represented using binary tree. Every node in the tree has two pointers. Child points to the first node in the next level, while next points to the next node in the same level. With this design, when we want to free a certain node, just free its entire child branch. there is no need to record memory usage anymore. Here is a sample syntax file. line: one_line_commands { $$=$1; } | function_cmd { $$=$1; } | menu_cmd { $$=$1; } newlines: | newlines "\n" commands: one_line_commands { $$=$1; } | one_line_commands "\n" newlines commands { $$=$1; append_items($$, $2); } one_line_commands: command { $$=$1; $1->next=0; } | command ; one_line_commands { $$=$1; $1->next=$2; } command: simple_command { $$=$1; } | if_command { $$=$1; } simple_command: text arguments { $$->type=SIMPLE_COMMAND; $$->child=$1; } arguments: { $$=0; } | text arguments { $$=$1; $1->next=$2; } if_cmdblk: command ; { $$->type=COMMAND_LIST; $$->child=$1; $1->next=0; } || "\n" newlines commands "\n" newlines { $$->type=COMMAND_LIST; $$->child=$2; } if_command: "if" simple_command ; "then" if_cmdblk "fi" { $$->type=IF_COMMAND; $$->child=$2; $2->next=$5; $5->next=0; } | "if" simple_command ; "then" if_cmdblk "else" if_cmdblk "fi" { $$->type=IF_COMMAND; $$->child=$2; $2->next=$5; $5->next=$7; $7->next=0; } function_cmd: "function" text newlines "{" newlines commands newlines "}" { $$->type=FUNCTION_CMD; $$->child=$2; $2->next->type=COMMAND_LIST; $2->next->child=$6; } menu_cmd: "menuentry" text newlines "{" newlines commands newlines "}" { $$->type=MENU_CMD; $$->child=$2; $2->next->type=COMMAND_LIST; $2->next->child=$6; } Text is the basic token, it can be plain text or text mixed with variable, for example: abc "aa bb" "aa"bb aa$BB aa${BB}cc ... The lexer would break it into pieces. abc => abc "aa bb" => "aa bb" "aa"bb => "aa" bb aa$BB => aa $BB aa${BB}cc => aa $BB cc When text is evaluated, each piece is evaluated individually, then joined together to form the end result. -- Bean