Basic compiler is now ISO C90 compliant.

This commit is contained in:
carl 2019-03-02 01:35:09 +08:00
parent ca3e272233
commit f371f452b5
23 changed files with 452 additions and 245 deletions

View file

@ -90,6 +90,10 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include "bem.h" #include "bem.h"
#include "util.h"
#include "gencode.h"
#include "eval.h"
#include "func.h"
#include "llmess.h" #include "llmess.h"
typedef union { typedef union {

View file

@ -3,7 +3,8 @@
* See the copyright notice in the ACK home directory, in the file "Copyright". * See the copyright notice in the ACK home directory, in the file "Copyright".
*/ */
#ifndef NORSCID
#ifndef NORCSID
static char rcs_lex[] = "$Id$" ; static char rcs_lex[] = "$Id$" ;
#endif #endif
@ -151,7 +152,7 @@ Key keywords [] ={
int kex[27]; int kex[27];
/* Initialize the keyword table */ /* Initialize the keyword table */
fillkex() void fillkex(void)
{ {
Key *k; Key *k;
int i; int i;
@ -235,7 +236,7 @@ File *stream;
} }
} }
getinputline() int getinputline(void)
{ {
/* get next input line */ /* get next input line */
@ -255,7 +256,7 @@ getinputline()
typechar() int typechar(void)
{ {
switch(*cptr) switch(*cptr)
{ {
@ -277,7 +278,7 @@ typechar()
char name[SIGNIFICANT+1]; char name[SIGNIFICANT+1];
lookup() int lookup(void)
{ {
Key *k; Key *k;
Symbol *Sym; Symbol *Sym;
@ -341,7 +342,7 @@ lookup()
/* Parsing unsigned numbers */ /* Parsing unsigned numbers */
readconstant() int readconstant(void)
{ {
/* read HEX and OCTAL numbers */ /* read HEX and OCTAL numbers */
char *c; char *c;
@ -372,9 +373,7 @@ readconstant()
#ifdef ____ #ifdef ____
/* Computes base to the power exponent. This was not done in the old /* Computes base to the power exponent. This was not done in the old
compiler */ compiler */
double powr(base,exp) double powr(double base,int exp)
double base;
int exp;
{ {
int i; int i;
double result; double result;
@ -398,7 +397,7 @@ int exp;
#endif #endif
number() int number(void)
{ {
long i1; long i1;
int overflow = 0; int overflow = 0;
@ -468,7 +467,7 @@ number()
scanstring() int scanstring(void)
{ {
int i,length=0; int i,length=0;
char firstchar = *cptr; char firstchar = *cptr;
@ -532,7 +531,7 @@ scanstring()
yylex() int yylex(void)
{ {
char *c; char *c;

View file

@ -4,8 +4,12 @@
*/ */
#include "bem.h" #include "bem.h"
#include "parsepar.h"
#include "system.h"
#include "graph.h"
#ifndef NORSCID
#ifndef NORCSID
static char rcs_id[] = "$Id$" ; static char rcs_id[] = "$Id$" ;
static char rcs_bem[] = RCS_BEM ; static char rcs_bem[] = RCS_BEM ;
static char rcs_symb[] = RCS_SYMB ; static char rcs_symb[] = RCS_SYMB ;
@ -33,9 +37,11 @@ char *inpfile, *outfile;
int BEMINTSIZE = EMINTSIZE; int BEMINTSIZE = EMINTSIZE;
int BEMPTRSIZE = EMPTRSIZE; int BEMPTRSIZE = EMPTRSIZE;
int BEMFLTSIZE = EMFLTSIZE; int BEMFLTSIZE = EMFLTSIZE;
main(argc,argv)
int argc; extern void initialize(void);
char **argv; extern void compileprogram(void);
int main(int argc,char **argv)
{ {
extern int errorcnt; extern int errorcnt;

View file

@ -4,13 +4,14 @@
*/ */
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h>
#include <ctype.h> #include <ctype.h>
#include <string.h> #include <string.h>
#include <signal.h> #include <signal.h>
#include <system.h> #include "system.h"
#include <print.h> #include "print.h"
#include <em.h> #include "em.h"
#include <em_mes.h> #include "em_mes.h"
/* Author: M.L. Kersten /* Author: M.L. Kersten
** Here all the global objects are defined. ** Here all the global objects are defined.

View file

@ -3,19 +3,25 @@
* See the copyright notice in the ACK home directory, in the file "Copyright". * See the copyright notice in the ACK home directory, in the file "Copyright".
*/ */
/*#include "bem.h"*/
#include <stdio.h>
#include "system.h"
#include "gencode.h"
#include "bem.h" #include "bem.h"
#ifndef NORSCID #ifndef NORCSID
static char rcs_id[] = "$Id$" ; static char rcs_id[] = "$Id$" ;
#endif #endif
extern int getinputline(void);
extern void LLparse(void);
/* compile the next program in the list */ /* compile the next program in the list */
/* Here we should open the input file. (for the future) */ /* Here we should open the input file. (for the future) */
File *yyin; File *yyin;
compileprogram() void compileprogram(void)
{ {
extern int basicline; extern int basicline;
@ -24,7 +30,9 @@ compileprogram()
epilogcode in the new version of the compiler */ epilogcode in the new version of the compiler */
while( basicline = 0, getinputline()) while( basicline = 0, getinputline())
(void) LLparse(); {
LLparse();
}
epilogcode(); epilogcode();
sys_close(yyin); sys_close(yyin);
} }

View file

@ -4,8 +4,10 @@
*/ */
#include "bem.h" #include "bem.h"
#include "util.h"
#include "gencode.h"
#ifndef NORSCID #ifndef NORCSID
static char rcs_id[] = "$Id$" ; static char rcs_id[] = "$Id$" ;
#endif #endif
@ -14,8 +16,7 @@ static char rcs_id[] = "$Id$" ;
generate code for assignment statements generate code for assignment statements
*/ */
exprtype(ltype,rtype) static int exprtype(int ltype,int rtype)
int ltype,rtype;
{ {
/* determine the result type of an expression */ /* determine the result type of an expression */
if ( ltype==STRINGTYPE || rtype==STRINGTYPE) if ( ltype==STRINGTYPE || rtype==STRINGTYPE)
@ -31,9 +32,7 @@ int ltype,rtype;
void void conversion(int oldtype,int newtype)
conversion(oldtype,newtype)
int oldtype,newtype;
{ {
/* the value on top of the stack should be converted */ /* the value on top of the stack should be converted */
if ( oldtype==newtype) return; if ( oldtype==newtype) return;
@ -62,7 +61,10 @@ int oldtype,newtype;
C_lfr((arith)BEMINTSIZE); C_lfr((arith)BEMINTSIZE);
break; break;
} else if ( newtype==FLOATTYPE || newtype==DOUBLETYPE) } else if ( newtype==FLOATTYPE || newtype==DOUBLETYPE)
{
break; break;
}
break;
default: default:
if (debug) if (debug)
print("type n=%d o=%d\n",newtype,oldtype); print("type n=%d o=%d\n",newtype,oldtype);
@ -72,9 +74,7 @@ int oldtype,newtype;
void void extraconvert(int oldtype,int newtype,int topstack)
extraconvert(oldtype,newtype,topstack)
int oldtype,newtype,topstack;
{ {
/* the value below the top of the stack should be converted */ /* the value below the top of the stack should be converted */
if ( oldtype==newtype ) return; if ( oldtype==newtype ) return;
@ -116,8 +116,7 @@ int oldtype,newtype,topstack;
boolop(ltype,rtype,operator) int boolop(int ltype,int rtype,int operator)
int ltype,rtype,operator;
{ {
if ( operator != NOTSYM) if ( operator != NOTSYM)
{ {
@ -158,8 +157,7 @@ int ltype,rtype,operator;
genbool(operator) void genbool(int operator)
int operator;
{ {
int l1,l2; int l1,l2;
@ -186,8 +184,7 @@ int operator;
relop( ltype,rtype,operator) int relop(int ltype,int rtype,int operator)
int ltype,rtype,operator;
{ {
int result; int result;
@ -213,8 +210,7 @@ int ltype,rtype,operator;
plusmin(ltype,rtype,operator) int plusmin(int ltype,int rtype,int operator)
int ltype,rtype,operator;
{ {
int result; int result;
@ -246,8 +242,7 @@ int ltype,rtype,operator;
muldiv(ltype,rtype,operator) int muldiv(int ltype,int rtype,int operator)
int ltype,rtype,operator;
{ {
int result; int result;
@ -286,8 +281,7 @@ int ltype,rtype,operator;
negate(type) int negate(int type)
int type;
{ {
switch(type) switch(type)
{ {
@ -307,8 +301,7 @@ int type;
#ifdef ___ #ifdef ___
power(ltype,rtype) int power(int ltype,int rtype)
int ltype,rtype;
{ {
int resulttype = exprtype(ltype, rtype); int resulttype = exprtype(ltype, rtype);
@ -330,8 +323,7 @@ int ltype,rtype;
return(resulttype); return(resulttype);
} }
#else #else
power(ltype,rtype) int power(int ltype,int rtype)
int ltype,rtype;
{ {
extraconvert(ltype,DOUBLETYPE,rtype); extraconvert(ltype,DOUBLETYPE,rtype);
conversion(rtype,DOUBLETYPE); conversion(rtype,DOUBLETYPE);
@ -343,8 +335,7 @@ int ltype,rtype;
#endif #endif
int typesize(ltype) int typesize(int ltype)
int ltype;
{ {
switch( ltype) switch( ltype)
{ {
@ -364,8 +355,7 @@ int ltype;
int typestring(type) int typestring(int type)
int type;
{ {
switch(type) switch(type)
{ {
@ -384,8 +374,7 @@ int type;
loadvar(type) void loadvar(int type)
int type;
{ {
/* load a simple variable its address is on the stack*/ /* load a simple variable its address is on the stack*/
C_loi((arith)typestring(type)); C_loi((arith)typestring(type));
@ -393,8 +382,7 @@ int type;
loadint(value) int loadint(int value)
int value;
{ {
C_loc((arith)value); C_loc((arith)value);
return(INTTYPE); return(INTTYPE);
@ -402,8 +390,7 @@ int value;
loaddbl(value) int loaddbl(char* value)
char *value;
{ {
int index; int index;
@ -417,16 +404,14 @@ char *value;
loadstr(value) void loadstr(int value)
int value;
{ {
C_lae_dlb((label)value,(arith)0); C_lae_dlb((label)value,(arith)0);
} }
loadaddr(s) int loadaddr(Symbol *s)
Symbol *s;
{ {
extern Symbol *fcn; extern Symbol *fcn;
int i,j; int i,j;
@ -450,7 +435,7 @@ Symbol *s;
/* This is a new routine */ /* This is a new routine */
save_address() void save_address(void)
{ {
C_lae_dnam("dummy3",(arith)0); C_lae_dnam("dummy3",(arith)0);
C_sti((arith)BEMPTRSIZE); C_sti((arith)BEMPTRSIZE);
@ -458,8 +443,7 @@ save_address()
assign(type,lt) void assign(int type,int lt)
int type,lt;
{ {
extern int e1,e2; extern int e1,e2;
@ -472,8 +456,7 @@ int type,lt;
storevar(lab,type) void storevar(int lab,int type)
int lab,type;
{ {
/*store value back */ /*store value back */
C_lae_dlb((label)lab,(arith)0); C_lae_dlb((label)lab,(arith)0);
@ -488,8 +471,7 @@ Symbol *arraystk[MAXDIMENSIONS];
newarrayload(s) void newarrayload(Symbol *s)
Symbol *s;
{ {
if ( dimtop<MAXDIMENSIONS) dimtop++; if ( dimtop<MAXDIMENSIONS) dimtop++;
if ( s->dimensions==0) if ( s->dimensions==0)
@ -504,16 +486,14 @@ Symbol *s;
endarrayload() int endarrayload(void)
{ {
return(arraystk[dimtop--]->symtype); return(arraystk[dimtop--]->symtype);
} }
void void loadarray(int type)
loadarray(type)
int type;
{ {
int dim; int dim;
Symbol *s; Symbol *s;

54
lang/basic/src/eval.h Normal file
View file

@ -0,0 +1,54 @@
/* Copyright (c) 2019 ACK Project.
* See the copyright notice in the ACK home directory,
* in the file "Copyright".
*
*/
#ifndef __EVAL_H_INCLUDED__
#define __EVAL_H_INCLUDED__
#include "symbols.h"
/*--------------------------- Utilities -----------------------*/
/** From an internal type definition return the size in bytes of the data.
* If not a known data type return an integer size. */
extern int typesize(int ltype);
/** From an internal type definition return the size in bytes of the data. If not a
* known data type return a 0 size. */
extern int typestring(int type);
/*-------------------------- Code generation ---------------------*/
/** Emit code to convert from the old internal type to the new internal type definition.
* Generates an error if the type conversion is not allowed. */
extern void conversion(int oldtype,int newtype);
/** Emit code to store a value of the specified type from the top of stack
* into the specified variable pointed to by label.
*/
extern void storevar(int lab,int type);
/** Emit code to load a simple variable value on the stack. On input the address of the variable
* is on the stack. */
extern void loadvar(int type);
extern void extraconvert(int oldtype,int newtype,int topstack);
extern void loadstr(int value);
extern int endarrayload(void);
extern void loadarray(int type);
extern void save_address(void);
extern void assign(int type,int lt);
extern int boolop(int ltype,int rtype,int operator);
extern int relop(int ltype,int rtype,int operator);
extern int plusmin(int ltype,int rtype,int operator);
extern int muldiv(int ltype,int rtype,int operator);
extern int negate(int type);
extern int power(int ltype,int rtype);
extern int loadint(int value);
extern int loaddbl(char* value);
extern int loadaddr(Symbol *s);
extern void newarrayload(Symbol *s);
#endif /* __EVAL_H_INCLUDED */

View file

@ -4,8 +4,10 @@
*/ */
#include "bem.h" #include "bem.h"
#include "util.h"
#include "eval.h"
#ifndef NORSCID #ifndef NORCSID
static char rcs_id[] = "$Id$" ; static char rcs_id[] = "$Id$" ;
#endif #endif
@ -19,8 +21,7 @@ int exprlimit;
parm(cnt) void parm(int cnt)
int cnt;
{ {
if( cnt> exprlimit) if( cnt> exprlimit)
error("Not enough arguments"); error("Not enough arguments");
@ -30,9 +31,7 @@ int cnt;
callfcn(fcnnr,cnt,typetable) int callfcn(int fcnnr,int cnt,int *typetable)
int fcnnr,cnt;
int *typetable;
{ {
int pop=DOUBLETYPE; int pop=DOUBLETYPE;
int res=DOUBLETYPE; int res=DOUBLETYPE;

13
lang/basic/src/func.h Normal file
View file

@ -0,0 +1,13 @@
/* Copyright (c) 2019 ACK Project.
* See the copyright notice in the ACK home directory,
* in the file "Copyright".
*
*/
#ifndef __FUNC_H_INCLUDED__
#define __FUNC_H_INCLUDED__
extern int callfcn(int fcnnr,int cnt,int *typetable);
#endif /* __FUNC_H_INCLUDED__ */

View file

@ -4,9 +4,12 @@
*/ */
#include "bem.h" #include "bem.h"
#include "system.h" #include "graph.h"
#include "eval.h"
#include "util.h"
#include "gencode.h"
#ifndef NORSCID #ifndef NORCSID
static char rcs_id[] = "$Id$" ; static char rcs_id[] = "$Id$" ;
#endif #endif
@ -18,14 +21,14 @@ label err_goto_label;
genlabel() int genlabel(void)
{ {
return(emlabel++); return(emlabel++);
} }
genemlabel() int genemlabel(void)
{ {
int l; int l;
@ -39,8 +42,7 @@ genemlabel()
int tronoff=0; int tronoff=0;
newemblock(nr) void newemblock(int nr)
int nr;
{ {
C_df_ilb((label)currline->emlabel); C_df_ilb((label)currline->emlabel);
C_lin((arith)nr); C_lin((arith)nr);
@ -57,7 +59,7 @@ int nr;
/* Handle data statements */ /* Handle data statements */
List *datalist=0; List *datalist=0;
datastmt() void datastmt(void)
{ {
List *l,*l1; List *l,*l1;
@ -78,7 +80,7 @@ datastmt()
datatable() void datatable(void)
{ {
List *l; List *l;
int line=0; int line=0;
@ -100,8 +102,7 @@ datatable()
/* ERROR and exception handling */ /* ERROR and exception handling */
exceptstmt(lab) void exceptstmt(int lab)
int lab;
{ {
/* exceptions to subroutines are supported only */ /* exceptions to subroutines are supported only */
extern int gosubcnt; extern int gosubcnt;
@ -116,8 +117,7 @@ int lab;
errorstmt(exprtype) void errorstmt(int exprtype)
int exprtype;
{ {
/* convert expression to a valid error number */ /* convert expression to a valid error number */
/* obtain the message and print it */ /* obtain the message and print it */
@ -128,8 +128,7 @@ int exprtype;
/* BASIC IO */ /* BASIC IO */
openstmt(recsize) void openstmt(int recsize)
int recsize;
{ {
C_loc((arith)recsize); C_loc((arith)recsize);
C_cal("_opnchn"); C_cal("_opnchn");
@ -138,8 +137,7 @@ int recsize;
printstmt(exprtype) void printstmt(int exprtype)
int exprtype;
{ {
switch(exprtype) switch(exprtype)
{ {
@ -165,16 +163,14 @@ int exprtype;
zone(i) void zone(int i)
int i;
{ {
if ( i) C_cal("_zone"); if ( i) C_cal("_zone");
} }
writestmt(exprtype,comma) void writestmt(int exprtype, int comma)
int exprtype,comma;
{ {
if ( comma) C_cal("_wrcomma"); if ( comma) C_cal("_wrcomma");
@ -198,8 +194,7 @@ int exprtype,comma;
restore(lab) void restore(int lab)
int lab;
{ {
/* save this information too */ /* save this information too */
@ -213,8 +208,7 @@ int lab;
prompt(qst) void prompt(int qst)
int qst;
{ {
setchannel(-1); setchannel(-1);
C_cal("_prstr"); C_cal("_prstr");
@ -224,8 +218,7 @@ int qst;
linestmt(type) void linestmt(int type)
int type;
{ {
if ( type!= STRINGTYPE) if ( type!= STRINGTYPE)
error("String variable expected"); error("String variable expected");
@ -235,8 +228,7 @@ int type;
readelm(type) void readelm(int type)
int type;
{ {
switch(type) switch(type)
{ {
@ -259,8 +251,7 @@ int type;
/* Swap exchanges the variable values */ /* Swap exchanges the variable values */
swapstmt(ltype,rtype) void swapstmt(int ltype,int rtype)
int ltype, rtype;
{ {
if ( ltype!= rtype) if ( ltype!= rtype)
error("Type mismatch"); error("Type mismatch");
@ -287,9 +278,9 @@ int ltype, rtype;
/* input/output handling */ /* input/output handling */
setchannel(val) void setchannel(int val)
int val; {
{ /* obtain file descroption */ /* obtain file descroption */
C_loc((arith)val); C_loc((arith)val);
C_cal("_setchan"); C_cal("_setchan");
C_asp((arith)BEMINTSIZE); C_asp((arith)BEMINTSIZE);
@ -298,8 +289,7 @@ int val;
/* The if-then-else statements */ /* The if-then-else statements */
ifstmt(type) int ifstmt(int type)
int type;
{ {
/* This BASIC follows the True= -1 rule */ /* This BASIC follows the True= -1 rule */
int nr; int nr;
@ -322,8 +312,7 @@ int type;
thenpart( elselab) int thenpart(int elselab)
int elselab;
{ {
int nr; int nr;
@ -335,7 +324,7 @@ int elselab;
elsepart(lab)int lab; void elsepart(int lab)
{ {
C_df_ilb((label)lab); C_df_ilb((label)lab);
} }
@ -359,8 +348,7 @@ int forcnt= -1;
forinit(s) void forinit(Symbol *s)
Symbol *s;
{ {
int type; int type;
struct FORSTRUCT *f; struct FORSTRUCT *f;
@ -388,8 +376,7 @@ Symbol *s;
forexpr(type) void forexpr(int type)
int type;
{ {
/* save start value of loop variable in a save place*/ /* save start value of loop variable in a save place*/
/* to avoid clashing with final value and step expression */ /* to avoid clashing with final value and step expression */
@ -402,8 +389,7 @@ int type;
forlimit(type) void forlimit(int type)
int type;
{ {
/* save the limit value too*/ /* save the limit value too*/
int result; int result;
@ -415,8 +401,7 @@ int type;
forskipped(f) void forskipped(struct FORSTRUCT *f)
struct FORSTRUCT *f;
{ {
int type; int type;
@ -452,8 +437,7 @@ struct FORSTRUCT *f;
forstep(type) void forstep(int type)
int type;
{ {
int result; int result;
int varaddress; int varaddress;
@ -522,8 +506,7 @@ int type;
nextstmt(s) void nextstmt(Symbol *s)
Symbol *s;
{ {
if (forcnt>MAXFORDEPTH || forcnt<0 || if (forcnt>MAXFORDEPTH || forcnt<0 ||
(s && s!= fortable[forcnt].loopvar)) (s && s!= fortable[forcnt].loopvar))
@ -538,8 +521,7 @@ Symbol *s;
pokestmt(type1,type2) void pokestmt(int type1,int type2)
int type1,type2;
{ {
conversion(type1,INTTYPE); conversion(type1,INTTYPE);
conversion(type2,INTTYPE); conversion(type2,INTTYPE);
@ -553,7 +535,7 @@ int type1,type2;
int whilecnt, whilelabels[MAXDEPTH][2]; /*0=head,1=out */ int whilecnt, whilelabels[MAXDEPTH][2]; /*0=head,1=out */
whilestart() void whilestart(void)
{ {
whilecnt++; whilecnt++;
if ( whilecnt==MAXDEPTH) if ( whilecnt==MAXDEPTH)
@ -567,8 +549,7 @@ whilestart()
whiletst(exprtype) void whiletst(int exprtype)
int exprtype;
{ {
/* test expression type */ /* test expression type */
conversion(exprtype,INTTYPE); conversion(exprtype,INTTYPE);
@ -577,7 +558,7 @@ int exprtype;
wend() void wend(void)
{ {
if ( whilecnt<1) if ( whilecnt<1)
error("not part of while statement"); error("not part of while statement");
@ -591,7 +572,7 @@ wend()
/* generate code for the final version */ /* generate code for the final version */
prologcode() void prologcode(void)
{ {
/* generate the EM prolog code */ /* generate the EM prolog code */
C_df_dnam("fltnull"); C_df_dnam("fltnull");
@ -623,7 +604,7 @@ prologcode()
prolog2() void prolog2(void)
{ {
int result; int result;
label l = genlabel(), l2; label l = genlabel(), l2;
@ -659,7 +640,7 @@ prolog2()
/* NEW */ /* NEW */
gendata() void gendata(void)
{ {
C_loc((arith)0); C_loc((arith)0);
C_cal("_setchan"); C_cal("_setchan");
@ -685,7 +666,7 @@ gendata()
epilogcode() void epilogcode(void)
{ {
/* finalization code */ /* finalization code */
int nr; int nr;

64
lang/basic/src/gencode.h Normal file
View file

@ -0,0 +1,64 @@
/* Copyright (c) 2019 ACK Project.
* See the copyright notice in the ACK home directory,
* in the file "Copyright".
*
*/
#ifndef __GENCODE_H_INCLUDED__
#define __GENCODE_H_INCLUDED__
#include "symbols.h"
/*--------------------------- Utilities -----------------------*/
/** Return a global value identifier used for code generation */
extern int genlabel(void);
/*-------------------------- Code generation ---------------------*/
/** Emit a label definition and return the label identifier generated. */
extern int genemlabel(void);
void newemblock(int nr);
void newblock(int nr);
void datastmt(void);
void datatable(void);
/* ERROR and exception handling */
void exceptstmt(int lab);
void errorstmt(int exprtype);
/* BASIC IO */
void openstmt(int recsize);
void printstmt(int exprtype);
void zone(int i);
void writestmt(int exprtype, int comma);
void restore(int lab);
void prompt(int qst);
void linestmt(int type);
void readelm(int type);
/* Swap exchanges the variable values */
void swapstmt(int ltype,int rtype);
void setchannel(int val);
int ifstmt(int type);
int thenpart(int elselab);
void elsepart(int lab);
void forinit(Symbol *s);
void forexpr(int type);
void forlimit(int type);
void forstep(int type);
void nextstmt(Symbol *s);
void pokestmt(int type1,int type2);
void whilestart(void);
void whiletst(int exprtype);
void wend(void);
/* generate code for the final version */
void prologcode(void);
void prolog2(void);
void gendata(void);
void epilogcode(void);
void setchannel(int val);
void gendata(void);
#endif /* __GENCODE_H_INCLUDED__ */

View file

@ -4,8 +4,11 @@
*/ */
#include "bem.h" #include "bem.h"
#include "util.h"
#include "eval.h"
#include "gencode.h"
#ifndef NORSCID #ifndef NORCSID
static char rcs_id[] = "$Id$" ; static char rcs_id[] = "$Id$" ;
#endif #endif
@ -18,7 +21,7 @@ Linerecord *firstline,
List *newlist() List *newlist(void)
{ {
List *l; List *l;
@ -29,8 +32,7 @@ List *newlist()
/* Line management is handled here */ /* Line management is handled here */
Linerecord *srchline(nr) Linerecord *srchline(int nr)
int nr;
{ {
Linerecord *l; Linerecord *l;
@ -41,8 +43,7 @@ int nr;
List *srchforward(nr) List *srchforward(int nr)
int nr;
{ {
List *l; List *l;
@ -53,7 +54,7 @@ int nr;
linewarnings() void linewarnings(void)
{ {
List *l; List *l;
extern int errorcnt; extern int errorcnt;
@ -72,8 +73,7 @@ linewarnings()
newblock(nr) void newblock(int nr)
int nr;
{ {
Linerecord *l; Linerecord *l;
List *frwrd; List *frwrd;
@ -111,8 +111,7 @@ int nr;
gotolabel(nr) int gotolabel(int nr)
int nr;
{ {
/* simulate a goto statement in the line record table */ /* simulate a goto statement in the line record table */
Linerecord *l1; Linerecord *l1;
@ -146,8 +145,7 @@ int nr;
gotostmt(nr) void gotostmt(int nr)
int nr;
{ {
C_bra((label) gotolabel(nr)); C_bra((label) gotolabel(nr));
} }
@ -160,7 +158,7 @@ int gosubcnt=1;
List *gosublabel() List *gosublabel(void)
{ {
List *l; List *l;
@ -177,8 +175,7 @@ List *gosublabel()
gosubstmt(lab) void gosubstmt(int lab)
int lab;
{ {
List *l; List *l;
int nr,n; int nr,n;
@ -197,7 +194,7 @@ int lab;
genreturns() void genreturns(void)
{ {
int count; int count;
int nr; int nr;
@ -227,7 +224,7 @@ genreturns()
returnstmt() void returnstmt(void)
{ {
C_cal("_retstmt"); C_cal("_retstmt");
C_lfr((arith) BEMINTSIZE); C_lfr((arith) BEMINTSIZE);
@ -242,8 +239,7 @@ List *jumphead,*jumptail;
int jumpcnt; int jumpcnt;
jumpelm(nr) void jumpelm(int nr)
int nr;
{ {
List *l; List *l;
@ -260,8 +256,7 @@ int nr;
ongotostmt(type) void ongotostmt(int type)
int type;
{ {
/* generate the code itself, index in on top of the stack */ /* generate the code itself, index in on top of the stack */
/* blurh, store the number of entries in the descriptor */ /* blurh, store the number of entries in the descriptor */
@ -294,8 +289,7 @@ int type;
ongosubstmt(type) void ongosubstmt(int type)
int type;
{ {
List *l; List *l;
int firstlabel; int firstlabel;

View file

@ -3,6 +3,9 @@
* See the copyright notice in the ACK home directory, in the file "Copyright". * See the copyright notice in the ACK home directory, in the file "Copyright".
*/ */
#ifndef __GRAPH_H_INCLUDED__
#define __GRAPH_H_INCLUDED__
#ifndef NORCSID #ifndef NORCSID
# define RCS_GRAPH "$Id$" # define RCS_GRAPH "$Id$"
#endif #endif
@ -35,3 +38,18 @@ extern Linerecord *firstline,
extern List *forwardlabel; extern List *forwardlabel;
extern List *gosublabel(); extern List *gosublabel();
extern void jumpelm(int nr);
extern int gotolabel(int nr);
extern void linewarnings(void);
/*-------------------------- Code generation ---------------------*/
extern void genreturns(void);
extern void gosubstmt(int lab);
extern void gotostmt(int nr);
extern void returnstmt(void);
extern void ongosubstmt(int type);
extern void ongotostmt(int type);
#endif

View file

@ -3,9 +3,11 @@
* See the copyright notice in the ACK home directory, in the file "Copyright". * See the copyright notice in the ACK home directory, in the file "Copyright".
*/ */
#include <stdio.h>
#include "bem.h" #include "bem.h"
#include "util.h"
#ifndef NORSCID #ifndef NORCSID
static char rcs_id[] = "$Id$"; static char rcs_id[] = "$Id$";
#endif #endif
@ -13,9 +15,9 @@ static char rcs_id[] = "$Id$";
File *datfile; File *datfile;
extern void fillkex(void);
void initialize(void)
initialize()
{ {
register char *cindex, *cptr; register char *cindex, *cptr;
int result1, result2; int result1, result2;
@ -33,7 +35,7 @@ initialize()
} }
} }
cptr=datfname; cptr=datfname;
while ( *cptr++ = *cindex++ ); while ( (*cptr++ = *cindex++) !=0 );
/* Strip trailing suffix */ /* Strip trailing suffix */
if ( cptr>datfname+3 && cptr[-3]=='.' ) cptr[-3]=0; if ( cptr>datfname+3 && cptr[-3]=='.' ) cptr[-3]=0;
strcat(datfname,".d"); strcat(datfname,".d");

View file

@ -3,16 +3,17 @@
* See the copyright notice in the ACK home directory, in the file "Copyright". * See the copyright notice in the ACK home directory, in the file "Copyright".
*/ */
#include <stdio.h>
#include "tokentab.h" #include "tokentab.h"
#include "system.h"
#include "print.h"
/* Mod van gertjan */ /* Mod van gertjan */
extern int LLsymb; extern int LLsymb;
extern int toknum; extern int toknum;
error_char(format,ch) void error_char(char *format,char ch)
char *format;
char ch;
{ {
extern int listing,errorcnt; extern int listing,errorcnt;
extern int basicline; extern int basicline;
@ -24,9 +25,7 @@ char ch;
error_string(format,str) void error_string(char* format,char* str)
char *format;
char *str;
{ {
extern int listing,errorcnt; extern int listing,errorcnt;
extern int basicline; extern int basicline;
@ -38,8 +37,7 @@ char *str;
LLmessage( insertedtok ) void LLmessage(int insertedtok )
int insertedtok;
{ {
if ( insertedtok < 0 ) { if ( insertedtok < 0 ) {
error("Fatal stack overflow\n"); error("Fatal stack overflow\n");

11
lang/basic/src/options Normal file
View file

@ -0,0 +1,11 @@
User options:
D parser debugging
t line tracing
d debug information
E generate full listing
L don't generate linenumbers and filename indications
w suppress warning diagnostics
VwN set word size to N bytes
VpN set pointer size to N bytes
VfN set real size to N bytes

View file

@ -3,9 +3,15 @@
* See the copyright notice in the ACK home directory, in the file "Copyright". * See the copyright notice in the ACK home directory, in the file "Copyright".
*/ */
#include "parsepar.h"
#include "bem.h" #include "bem.h"
#include <stdio.h>
#include "print.h"
#include "system.h"
#include "util.h"
#ifndef NORSCID
#ifndef NORCSID
static char rcs_id[] = "$Id$" ; static char rcs_id[] = "$Id$" ;
#endif #endif
@ -18,9 +24,7 @@ int nolins=0; /* generate no LIN statements */
parseparams(argc,argv) void parseparams(int argc,char **argv)
int argc;
char **argv;
{ {
int files=0 ; int files=0 ;
int i; int i;

23
lang/basic/src/parsepar.h Normal file
View file

@ -0,0 +1,23 @@
/* Copyright (c) 2019 ACK Project.
* See the copyright notice in the ACK home directory,
* in the file "Copyright".
*
*/
#ifndef __PARSEPAR_H_INCLUDED__
#define __PARSEPAR_H_INCLUDED__
/** -l listing required */
extern int listing;
/** -d compiler debugging */
extern int debug;
/** -w warning flags */
extern int wflag;
/** generate line tracing code. */
extern int traceflag;
/** generate LIN statements */
extern int nolins;
void parseparams(int argc,char **argv);
#endif /* __PARSEPAR_H_INCLUDED__ */

View file

@ -3,9 +3,18 @@
* See the copyright notice in the ACK home directory, in the file "Copyright". * See the copyright notice in the ACK home directory, in the file "Copyright".
*/ */
#include "symbols.h"
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "bem.h" #include "bem.h"
#include "eval.h"
#include "gencode.h"
#include "util.h"
#ifndef NORSCID
#ifndef NORCSID
static char rcs_id[] = "$Id$" ; static char rcs_id[] = "$Id$" ;
#endif #endif
@ -15,7 +24,11 @@ int deftype[128]; /* default type declarer */
/* which may be set by OPTION BASE */ /* which may be set by OPTION BASE */
initdeftype() /* Local declarations */
static void get_space(int type,int size);
void initdeftype(void)
{ {
int i; int i;
@ -31,8 +44,7 @@ Symbol *alternate = NIL;
Symbol *srchsymbol(str) Symbol *srchsymbol(char* str)
char *str;
{ {
Symbol *s; Symbol *s;
@ -68,9 +80,7 @@ char *str;
void void dcltype(Symbol *s)
dcltype(s)
Symbol *s;
{ {
/* type declarer */ /* type declarer */
int type; int type;
@ -79,7 +89,7 @@ Symbol *s;
type=s->symtype; type=s->symtype;
if (type==DEFAULTTYPE) if (type==DEFAULTTYPE)
/* use the default rule */ /* use the default rule */
type= deftype[*s->symname]; type= deftype[(int)(*s->symname)];
/* generate the emlabel too */ /* generate the emlabel too */
if ( s->symalias==0) if ( s->symalias==0)
s->symalias= dclspace(type); s->symalias= dclspace(type);
@ -89,8 +99,7 @@ Symbol *s;
dclarray(s) void dclarray(Symbol *s)
Symbol *s;
{ {
int i; int size; int i; int size;
@ -122,8 +131,7 @@ Symbol *s;
get_space(type,size) static void get_space(int type,int size)
int type,size;
{ {
switch ( type ) { switch ( type ) {
@ -153,8 +161,7 @@ int type,size;
defarray(s) void defarray(Symbol *s)
Symbol *s;
{ {
/* array is used without dim statement, set default limits */ /* array is used without dim statement, set default limits */
int i; int i;
@ -164,7 +171,7 @@ Symbol *s;
dclspace(type) int dclspace(int type)
{ {
int nr; int nr;
@ -189,8 +196,7 @@ dclspace(type)
/* SOME COMPILE TIME OPTIONS */ /* SOME COMPILE TIME OPTIONS */
optionbase(ival) void optionbase(int ival)
int ival;
{ {
if ( ival<0 || ival>1) if ( ival<0 || ival>1)
error("illegal option base value"); error("illegal option base value");
@ -199,8 +205,7 @@ int ival;
setdefaulttype(type) void setdefaulttype(int type)
int type;
{ {
extern char *cptr; extern char *cptr;
char first,last,i; char first,last,i;
@ -233,8 +238,7 @@ Symbol *fcn;
newscope(s) void newscope(Symbol *s)
Symbol *s;
{ {
if (debug) print("new scope for %s\n",s->symname); if (debug) print("new scope for %s\n",s->symname);
alternate= firstsym; alternate= firstsym;
@ -253,7 +257,7 @@ Symbol *s;
heading( ) void heading(void)
{ {
char procname[50]; char procname[50];
@ -265,7 +269,7 @@ heading( )
int fcnsize() static int fcnsize(void)
{ {
/* generate portable function size */ /* generate portable function size */
int i,sum; /* sum is NEW */ int i,sum; /* sum is NEW */
@ -278,8 +282,7 @@ int fcnsize()
endscope(type) void endscope(int type)
int type;
{ {
Symbol *s; Symbol *s;
@ -304,8 +307,7 @@ int type;
dclparm(s) void dclparm(Symbol *s)
Symbol *s;
{ {
int size=0; int size=0;
@ -327,8 +329,7 @@ int fcnindex= -1;
fcncall(s) int fcncall(Symbol *s)
Symbol *s;
{ {
if ( !s->isfunction) if ( !s->isfunction)
error("Function not declared"); error("Function not declared");
@ -342,8 +343,7 @@ Symbol *s;
fcnend(parmcount) int fcnend(int parmcount)
int parmcount;
{ {
int type; int type;
static char concatbuf[50]; /* NEW */ static char concatbuf[50]; /* NEW */
@ -366,8 +366,7 @@ int parmcount;
callparm(ind,type) void callparm(int ind,int type)
int ind,type;
{ {
if ( fcnindex<0) error("unexpected parameter"); if ( fcnindex<0) error("unexpected parameter");
if ( ind >= fcn->dimensions) if ( ind >= fcn->dimensions)

View file

@ -3,6 +3,9 @@
* See the copyright notice in the ACK home directory, in the file "Copyright". * See the copyright notice in the ACK home directory, in the file "Copyright".
*/ */
#ifndef __SYMBOLS_H_INCLUDED__
#define __SYMBOLS_H_INCLUDED__
#ifndef NORCSID #ifndef NORCSID
# define RCS_SYMB "$Id$" # define RCS_SYMB "$Id$"
#endif #endif
@ -85,4 +88,21 @@ typedef struct SYMBOL{
int isparam; int isparam;
} Symbol; } Symbol;
extern Symbol *srchsymbol(); void initdeftype(void);
Symbol *srchsymbol(char* str);
void dcltype(Symbol *s);
void dclarray(Symbol *s);
void defarray(Symbol *s);
int dclspace(int type);
void optionbase(int ival);
void setdefaulttype(int type);
void newscope(Symbol *s);
void heading(void);
void endscope(int type);
void dclparm(Symbol *s);
int fcncall(Symbol *s);
int fcnend(int parmcount);
void callparm(int ind,int type);
#endif /* __SYMBOLS_H_INCLUDED__ */

View file

@ -3,9 +3,12 @@
* See the copyright notice in the ACK home directory, in the file "Copyright". * See the copyright notice in the ACK home directory, in the file "Copyright".
*/ */
#include "system.h"
#include "util.h"
#include "bem.h" #include "bem.h"
#ifndef NORSCID
#ifndef NORCSID
static char rcs_id[] = "$Id$" ; static char rcs_id[] = "$Id$" ;
#endif #endif
@ -16,25 +19,8 @@ int errorcnt;
void
warning(str)
char *str;
{
if (wflag) return;
Xerror("WARNING", str);
}
static void Xerror(char *type, char *str)
error(str)
char *str;
{
Xerror("ERROR", str);
errorcnt++;
}
Xerror(type, str)
char *str;
char *type;
{ {
extern int listing; extern int listing;
extern int basicline; extern int basicline;
@ -45,8 +31,23 @@ char *type;
fatal(str)
char *str; void warning(char* str)
{
if (wflag) return;
Xerror("WARNING", str);
}
void error(char* str)
{
Xerror("ERROR", str);
errorcnt++;
}
void fatal(char* str)
{ {
Xerror("FATAL",str); Xerror("FATAL",str);
C_close(); C_close();
@ -55,22 +56,21 @@ char *str;
notyetimpl() void notyetimpl(void)
{ {
warning("not yet implemented"); warning("not yet implemented");
} }
illegalcmd() void illegalcmd(void)
{ {
warning("illegal command"); warning("illegal command");
} }
char *myitoa(i) char *myitoa(int i)
int i;
{ {
static char buf[30]; static char buf[30];
@ -79,12 +79,7 @@ int i;
} }
char *salloc(unsigned int length)
char *salloc(length)
unsigned length;
{ {
char *s,*c; char *s,*c;

32
lang/basic/src/util.h Normal file
View file

@ -0,0 +1,32 @@
/* Copyright (c) 2019 ACK Project.
* See the copyright notice in the ACK home directory,
* in the file "Copyright".
*
*/
#ifndef __UTIL_H_INCLUDED__
#define __UTIL_H_INCLUDED__
/** Raises a warning with the specified message. */
void warning(char* str);
/** Raises a non fatal error with the specified message. */
void error(char* str);
/** Raises a fatal error with the specified message and
quits the application. */
void fatal(char* str);
/** Error management to raise a warning on an unimplemented
* feature. */
void notyetimpl(void);
/** Error management to raise a warning on an illegal command
line option. */
void illegalcmd(void);
char *myitoa(int i);
/** Tries to allocates a memory block of the specified number of bytes, and exits
* with a fatal error upon a failure. Upon allocation success, fills the allocated
* memory block with binary 0.
*/
char *salloc(unsigned int length);
#endif /* __UTIL_H_INCLUDED__ */

View file

@ -5,7 +5,9 @@
int toknum; int toknum;
yylexp() extern int yylex(void);
int yylexp(void)
{ {
/* als toknum != 0 dan bevat toknum een door LLmessage back-ge-pushed token */ /* als toknum != 0 dan bevat toknum een door LLmessage back-ge-pushed token */