From: Marco Gerards <mgerards@xs4all.nl>
To: The development of GRUB 2 <grub-devel@gnu.org>
Subject: Re: Standalone problem to test syntax rules
Date: Sun, 22 Jul 2007 15:06:49 +0200 [thread overview]
Message-ID: <87ps2kfuza.fsf@xs4all.nl> (raw)
In-Reply-To: <20070703175316.GA2306@ws3.vdp.com> (bean123@126.com's message of "Wed, 4 Jul 2007 01:53:16 +0800")
Bean <bean123@126.com> writes:
Hi Bean,
> I have written a small problem to test my parse.y, to compile, use the
> following commands:
>
> bison -d -p grub_script_yy -b grub_script parser.y
> gcc -oparser parser.c lexer.c grub_script.tab.c
>
> After compilation, run parser
>
> ./parser
>
> Just enter the commands after '##', and the syntax tree associtaed with it
> will be displayed.
>
> The program support option - , which is used to disable prompt '##' and '>>'.
> This is useful when inputting from files:
>
> ./parser - < input_file
>
> Some example:
>
> ## aa "aa${BB}cc" "\
>>dd"
> CMD
> TEXT
> STR "aa"
> TEXT
> STR "aa"
> VAR "BB"
> STR "cc"
> TEXT
> STR "dd"
[...]
> The reason why I like to use binary tree is:
>
> 1. Standard data type for all script elements, only one set of function is
> needed to manipulate the structure.
>
> 2. Enumeration and deallocation is simpler. Instead of using switch, we
> can enumerate the tree using its two branch, child and next.
>
> I also figure out how to release memory when syntax error occurs. When a
> node is first created using grub_script_newnode, it's added to a linked
> list state->free_list. When it's referenced, it's moved from the linked
> list to the branch of a tree. If the whole script is parsed, all nodes
> will be moved to the final tree, but if it fails at some point, partial
> built element can be found in the free list. This way, we can also keep
> track of nodes allocated. For example, consider this command:
You are right that it has advantages. But I prefer using an Abstract
Syntax Tree. It is used a lot in most literature on parsers, clean
and easy to understand.
The disadvantage is that you need a separate free routine for each
kind of node. But heck, we can even generalize this!
I agree there is a lot of room for improvement. But stepping away
from using ASTs is not the way to go in my opinion.
--
Marco
next prev parent reply other threads:[~2007-07-22 13:05 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-07-03 17:53 Standalone problem to test syntax rules Bean
2007-07-03 17:54 ` Bean
2007-07-22 13:06 ` Marco Gerards [this message]
2007-07-22 15:55 ` Bean
2007-07-22 16:21 ` Marco Gerards
2007-07-22 16:34 ` Bean
2007-11-10 18:43 ` Marco Gerards
2007-11-10 19:49 ` Gregg Levine
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87ps2kfuza.fsf@xs4all.nl \
--to=mgerards@xs4all.nl \
--cc=grub-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.