Matt Wette writes:

> I believe C99 parser is complete.  There may be errors, but I think
> all the elements are there.

Great!  As it turns out, I was using some GNU extensions (anonymous
unions inside structs.

I have now picked-up my work on Mes's simple C compiler backend, using
Nyacc.  I have already replaced my LALR parser with Nyacc's AST[0].

How far is the Nyacc's C99 preprocessor?  I have two problems with it.

It would be very helpful if it would disregard anything inside a false
conditional directive.  It seems I cannot conditionally comment things
out that Nyacc does not parse, like

--8<---------------cut here---------------start------------->8---
    #if __GNUC__
    void
    _start ()
    {
      puts ("Hello micro-mes!\n");

      ///int r = main (0,0);
      int r;
      asm (
           "push $0\n\t"
           "push $0\n\t"
           "call main\n\t"
           "movl %%eax,%0\n\t"
           : "=r" (r)
           : //no inputs "" (&main)
           );
    #endif // GNUC
--8<---------------cut here---------------end--------------->8---

==>  micro-mes.c:199: parse failed at state 379, on input ":"

or like GCC headers that Nyacc does not parse, like <assert.h>, which is
a bit of a pain.

Also, it seems like it doesn't like it if an #includ'ed file is meant to
go inside a function, like (simplified example)

--8<---------------cut here---------------start------------->8---
    // main.i
    r = 3;
--8<---------------cut here---------------end--------------->8---

--8<---------------cut here---------------start------------->8---
    // main.c
    int
    main ()
    {
      int r;
      #include "main.i"
      return r;
    } 
--8<---------------cut here---------------end--------------->8---


==> ./main.i:2: parse failed at state 43, on input "r"

Greetings,
Jan

[0] https://gitlab.com/janneke/mes/tree/wip-mescc

-- 
Jan Nieuwenhuizen <jann...@gnu.org> | GNU LilyPond http://lilypond.org
Freelance IT http://JoyofSource.com | AvatarĀ®  http://AvatarAcademy.nl  

Reply via email to