Re: Parsing nested structures with yacc

Chris F Clark <cfc@shell01.TheWorld.com>
Fri, 08 Aug 2008 10:01:50 -0400

          From comp.compilers

Related articles
Parsing nested structures with yacc amoebae@gmail.com (amoe) (2008-08-07)
Re: Parsing nested structures with yacc cfc@shell01.TheWorld.com (Chris F Clark) (2008-08-08)
Re: Parsing nested structures with yacc max@gustavus.edu (Max Hailperin) (2008-08-09)
Re: Parsing nested structures with yacc kamalpr@hp.com (kamal) (2008-08-11)
Re: Parsing nested structures with yacc amoebae@gmail.com (amoe) (2008-08-19)
Re: Parsing nested structures with yacc max@gustavus.edu (Max Hailperin) (2008-08-20)
| List of all articles for this month |
From: Chris F Clark <cfc@shell01.TheWorld.com>
Newsgroups: comp.compilers
Date: Fri, 08 Aug 2008 10:01:50 -0400
Organization: The World Public Access UNIX, Brookline, MA
References: 08-08-014
Keywords: parse
Posted-Date: 08 Aug 2008 18:40:22 EDT

David <amoebae@gmail.com> writes:


> I'm trying to write a basic parser for S-expressions, basic list
> structures used in Lisp. This is mainly to help me understand Lex and
> Yacc. Since Yacc is meant to be good for recursive balanced
> structures, I thought it would be an easy project. I did find it easy
> to write a grammar that recognizes the correct form for an
> S-expression, however, I'm having a massive mental block when it comes
> to putting the data into a form in which it can be manipulated.
> Basically I want to convert the list syntax into an in-memory
> equivalent, using pairs (basically a linked list).


When manipulating a list, one often needs both access to the head and
the tail, because you insert the head into a list above it, but you
append things to the tail of the list. So, imagine that your parser
at each level returned a struct that had head and tail of the
underlying list (or if it is a single elt, both head and tail point to
the same thing). See, if that model doesn't allow you to add code to
your third grammar. For, the first version of the code don't worry
about where you allocate and free such structs, just that you have as
many as you need. After to you get that version working, the
management of these return value structs should be relatively obvious.


Hope this helps,
-Chris


******************************************************************************
Chris Clark Internet: christopher.f.clark@compiler-resources.com
Compiler Resources, Inc. or: compres@world.std.com
23 Bailey Rd Web Site: http://world.std.com/~compres
Berlin, MA 01503 voice: (508) 435-5016
USA fax: (978) 838-0263 (24 hours)


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.