🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.api
Article #2300

Please Help with ANTLR or JavaCC

#2300
From: WunZnXeroZ
Date: Mon, 26 Mar 2001 01:57
51 lines
2227 bytes
I am a total beginner using tools like YACC, JavaCC and ANTLR. Can any
expert show me how I can use ANTLR to create compiler for an EASY
grammar like so.. 

<prog>  := PROGRAM <prog-name> BEGIN <stmt-list> END 
<prog-name>  := id 
<stmt-list>  := <stmt> | <stmt-list>;<stmt> 
<stmt>   := <assign> | <for> 
<assign>  := id := <exp> 
<exp>  := <term> | <exp> + <term> | <exp> - <term> 
<term>  := <factor> | <term> * <factor> | <term> DIV <factor> 
<factor>   := digit | (expr) | id 
<for>  := FOR <index-exp> DO <body> 
<index-exp>  := id := <exp> to <exp> 
<body>  := <stmt> | BEGIN <stmt-list> END 


I have tried to read through the users manual, and even a tutorial on
it using a different 

grammar. I am not doing ver well with this at all. Please help.



I am trying to write a compiler for a small language.   If I can at
first get it to 

read in 

A = beer + water * 250 

as a statement and then produce the Object code of.

LOAD  beer
STORE @(-sp) <---push to stack beer
LOAD  water
STORE @(-sp) <---push to stack water
LOAD  #250   
STORE @(-sp) <---push to stack 250
LOAD  @(+sp) 
MOVAB        <---move 250 to B registry
LOAD  @(+sp) <---pop from stack water
MULAB        <--Multiply water * 250
STORE @(-sp) 
LOAD  @(+sp) <--pops water * 250 from stack
MOVAB        <--moves it to B registry again
LOAD  @(+sp) <---pop from stack beer
ADDAB        <--add beer to water * 250
STORE A

Thanks very much in advance
Technical Details
Message-ID: <8f8tbton14h1dqldecbib1gjo0772tgt77@4ax.com>
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!sn-post-01!supernews.com!corp.supernews.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 1089d0,a611cdc19daa928e,start
X-Google-Attributes: gid1089d0,public
X-Google-ArrivalTime: 2001-03-25 18:03:00 PST
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!sn-post-01!supernews.com!corp.supernews.com!not-for-mail
From: WunZnXeroZ <WunZnXeroZ@hotmail.com>
Newsgroups: borland.public.jbuilder.java.api
Subject: Please Help with ANTLR or JavaCC
Date: Sun, 25 Mar 2001 20:57:00 -0500
Organization: Posted via Supernews, http://www.supernews.com
Message-ID: <8f8tbton14h1dqldecbib1gjo0772tgt77@4ax.com>
X-Newsreader: Forte Agent 1.8/32.548
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Complaints-To: newsabuse@supernews.com
Lines: 51