Re: [cc65] C Compiler Semantic Analysis

From: Payton Byrd <kingdurin1yahoo.com>
Date: 2006-01-16 23:44:29
Ullrich von Bassewitz <uz@musoftware.de> wrote: 
Hi!

On Mon, Jan 16, 2006 at 06:40:28AM -0800, Payton Byrd wrote:
> I haven't dug into the code for CC65, so this is more of a general
> question. Does CC65 has a generic rules engine that it uses to interpret
> the C grammar, or is the semantic analysis done with hard-coded functions?

The compiler uses a hardcoded recursive descent parser.

This is what I was wondering.  I'll have to write a recursive descent parser for Commodore BASIC (and with some extensions I call MacroBasic).  

> I've been doing some reading on compiler design for the 64/128 and was
> wondering if the CC65 framework would be a good starting point to create a
> BASIC compiler.  BASIC and C are so different from a grammatical
> standpoint that I don't think a hard-coded semantic analysis would offer
> much reuse. I'm sure I could do sometime with YACC, but was hoping to be
> able to reuse the assembly generation already existing in CC65.

The problem I have with scanner and parser generators is that they do only
offer help with the easiest part of writing a compiler. On the other side,
lex/yacc aren't readily available on some machines (windows comes to mind), so
using them will push the margin for anyone trying to compile the software.

Anyway, I don't think that parts of cc65 cannot be reused for a BASIC compiler
without much work.
From a compiler perspective, I don't really need to worry about start addresses and such if I target CA65 with my assembly, correct?  The linker configs for the individual platforms would handle those details.  

As for LEX and YACC, I believe that anyone who would use CC65 would be willing to set up a package with LEX and YACC included.  Then the majority of my work is defining the regular expressions for LEX and the grammer for YACC, followed by the assembly generation.  I do know that YACC is C oriented and have not yet studied the feasibility of using it for a BASIC language.  I think I'll start with a recursive descent parser that handles some simple use cases, such as:

10 for i = 1 to 10
20 gosub 100
30 next i
99 end
100 print "hello, world ["; i; "] ";
110 if i / 2 = int(i / 2) then 200
120 print "ODD!"
199 return
200 print "EVEN!"
299 return

That should cause enough BASIC spaghetti ugliness to see how my grammar shapes up and then apply it in YACC.  



Payton Byrd
<http://www.paytonbyrd.com>
<http://blogs.ittoolbox.com/visualbasic/dotnet/>
		
---------------------------------
Yahoo! Photos
 Ring in the New Year with Photo Calendars. Add photos, events, holidays, whatever.
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Mon, 16 Jan 2006 14:44:29 -0800 (PST)

This archive was generated by hypermail 2.1.8 : 2006-01-16 23:44:44 CET