:: Re: [DNG] Studying C as told. (For …
Página Inicial
Delete this message
Reply to this message
Autor: Hendrik Boom
Data:  
Para: dng
Assunto: Re: [DNG] Studying C as told. (For help)
On Wed, Jul 06, 2016 at 08:16:12AM +0100, KatolaZ wrote:
> On Wed, Jul 06, 2016 at 08:54:12AM +0200, Edward Bartolo wrote:
> > Hi,
> >
> > It seems the interest to give me feedback about what I am studying and
> > coding is dwindling rapidly. Nevertheless, I am coding a parser in C.
> > I have already coded the tokeniser and tested it. Next, I will
> > dedicate my efforts to the actual parsing. I am writing a syntax
> > checker for simple boolean expressions as an EXERCISE.
> >
> > Thankfully, the world does have other people who are willing to
> > positively criticise and actually help me in my endeavour to REVISE C,
> > for I have already studied it some years ago.
> >
> > I am attaching my little project code. (parser.c)
> >
> > Edward
>
>
> Even for didactical purposes, I would never start writing a parser in
> C from scratch. You should use lex and yacc for that, unless your
> language is a very simple regular language (e.g., no balanced
> parentheses). The handling of context-free languages and LALR(1)
> grammars is not straightforward and will almost certainly lead to
> useless frustration, which you might not want to go through even if
> you work as a language designer to bring bread on your table.


THe handling of anything LR is not straightforward except with
ridiculously simplifying assumptions -- approximately restrictions
that mean you might as well be using recursive-descent parsing.

And recursive-descent parsing is probably a very viable method to use
on Edward's small language. And it's easy to code in C. Many real
languages can be parser using it. And it's easier to insert artifices
in a recursive descent parser when the language demands it. In my
experience (which is 20 years old, the language has changed since) both
C and C++ are easy to parse using recursive-descent. (but not
necessarily LL(1)).

> Parsing context-free grammars and has nothing to do with learning or
> revising C, IMHO. My advice remain the same: code a simple shell, and
> you will learn a lot more.


Shells and parsers are completely different subject matters, unless you
use a parser to interpret shell comands.

Both are important techniques to know, and they will teach different
lessons.

-- hendrik