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 <stdio.h>
#include "bem.h"
#include "util.h"
#include "gencode.h"
#include "eval.h"
#include "func.h"
#include "llmess.h"
typedef union {

View file

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

View file

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

View file

@ -4,13 +4,14 @@
*/
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <signal.h>
#include <system.h>
#include <print.h>
#include <em.h>
#include <em_mes.h>
#include "system.h"
#include "print.h"
#include "em.h"
#include "em_mes.h"
/* Author: M.L. Kersten
** 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".
*/
/*#include "bem.h"*/
#include <stdio.h>
#include "system.h"
#include "gencode.h"
#include "bem.h"
#ifndef NORSCID
#ifndef NORCSID
static char rcs_id[] = "$Id$" ;
#endif
extern int getinputline(void);
extern void LLparse(void);
/* compile the next program in the list */
/* Here we should open the input file. (for the future) */
File *yyin;
compileprogram()
void compileprogram(void)
{
extern int basicline;
@ -24,7 +30,9 @@ compileprogram()
epilogcode in the new version of the compiler */
while( basicline = 0, getinputline())
(void) LLparse();
{
LLparse();
}
epilogcode();
sys_close(yyin);
}

View file

@ -4,8 +4,10 @@
*/
#include "bem.h"
#include "util.h"
#include "gencode.h"
#ifndef NORSCID
#ifndef NORCSID
static char rcs_id[] = "$Id$" ;
#endif
@ -14,8 +16,7 @@ static char rcs_id[] = "$Id$" ;
generate code for assignment statements
*/
exprtype(ltype,rtype)
int ltype,rtype;
static int exprtype(int ltype,int rtype)
{
/* determine the result type of an expression */
if ( ltype==STRINGTYPE || rtype==STRINGTYPE)
@ -31,9 +32,7 @@ int ltype,rtype;
void
conversion(oldtype,newtype)
int oldtype,newtype;
void conversion(int oldtype,int newtype)
{
/* the value on top of the stack should be converted */
if ( oldtype==newtype) return;
@ -62,6 +61,9 @@ int oldtype,newtype;
C_lfr((arith)BEMINTSIZE);
break;
} else if ( newtype==FLOATTYPE || newtype==DOUBLETYPE)
{
break;
}
break;
default:
if (debug)
@ -72,9 +74,7 @@ int oldtype,newtype;
void
extraconvert(oldtype,newtype,topstack)
int oldtype,newtype,topstack;
void extraconvert(int oldtype,int newtype,int topstack)
{
/* the value below the top of the stack should be converted */
if ( oldtype==newtype ) return;
@ -116,8 +116,7 @@ int oldtype,newtype,topstack;
boolop(ltype,rtype,operator)
int ltype,rtype,operator;
int boolop(int ltype,int rtype,int operator)
{
if ( operator != NOTSYM)
{
@ -158,8 +157,7 @@ int ltype,rtype,operator;
genbool(operator)
int operator;
void genbool(int operator)
{
int l1,l2;
@ -186,8 +184,7 @@ int operator;
relop( ltype,rtype,operator)
int ltype,rtype,operator;
int relop(int ltype,int rtype,int operator)
{
int result;
@ -213,8 +210,7 @@ int ltype,rtype,operator;
plusmin(ltype,rtype,operator)
int ltype,rtype,operator;
int plusmin(int ltype,int rtype,int operator)
{
int result;
@ -246,8 +242,7 @@ int ltype,rtype,operator;
muldiv(ltype,rtype,operator)
int ltype,rtype,operator;
int muldiv(int ltype,int rtype,int operator)
{
int result;
@ -286,8 +281,7 @@ int ltype,rtype,operator;
negate(type)
int type;
int negate(int type)
{
switch(type)
{
@ -307,8 +301,7 @@ int type;
#ifdef ___
power(ltype,rtype)
int ltype,rtype;
int power(int ltype,int rtype)
{
int resulttype = exprtype(ltype, rtype);
@ -330,8 +323,7 @@ int ltype,rtype;
return(resulttype);
}
#else
power(ltype,rtype)
int ltype,rtype;
int power(int ltype,int rtype)
{
extraconvert(ltype,DOUBLETYPE,rtype);
conversion(rtype,DOUBLETYPE);
@ -343,8 +335,7 @@ int ltype,rtype;
#endif
int typesize(ltype)
int ltype;
int typesize(int ltype)
{
switch( ltype)
{
@ -364,8 +355,7 @@ int ltype;
int typestring(type)
int type;
int typestring(int type)
{
switch(type)
{
@ -384,8 +374,7 @@ int type;
loadvar(type)
int type;
void loadvar(int type)
{
/* load a simple variable its address is on the stack*/
C_loi((arith)typestring(type));
@ -393,8 +382,7 @@ int type;
loadint(value)
int value;
int loadint(int value)
{
C_loc((arith)value);
return(INTTYPE);
@ -402,8 +390,7 @@ int value;
loaddbl(value)
char *value;
int loaddbl(char* value)
{
int index;
@ -417,16 +404,14 @@ char *value;
loadstr(value)
int value;
void loadstr(int value)
{
C_lae_dlb((label)value,(arith)0);
}
loadaddr(s)
Symbol *s;
int loadaddr(Symbol *s)
{
extern Symbol *fcn;
int i,j;
@ -450,7 +435,7 @@ Symbol *s;
/* This is a new routine */
save_address()
void save_address(void)
{
C_lae_dnam("dummy3",(arith)0);
C_sti((arith)BEMPTRSIZE);
@ -458,8 +443,7 @@ save_address()
assign(type,lt)
int type,lt;
void assign(int type,int lt)
{
extern int e1,e2;
@ -472,8 +456,7 @@ int type,lt;
storevar(lab,type)
int lab,type;
void storevar(int lab,int type)
{
/*store value back */
C_lae_dlb((label)lab,(arith)0);
@ -488,8 +471,7 @@ Symbol *arraystk[MAXDIMENSIONS];
newarrayload(s)
Symbol *s;
void newarrayload(Symbol *s)
{
if ( dimtop<MAXDIMENSIONS) dimtop++;
if ( s->dimensions==0)
@ -504,16 +486,14 @@ Symbol *s;
endarrayload()
int endarrayload(void)
{
return(arraystk[dimtop--]->symtype);
}
void
loadarray(type)
int type;
void loadarray(int type)
{
int dim;
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 "util.h"
#include "eval.h"
#ifndef NORSCID
#ifndef NORCSID
static char rcs_id[] = "$Id$" ;
#endif
@ -19,8 +21,7 @@ int exprlimit;
parm(cnt)
int cnt;
void parm(int cnt)
{
if( cnt> exprlimit)
error("Not enough arguments");
@ -30,9 +31,7 @@ int cnt;
callfcn(fcnnr,cnt,typetable)
int fcnnr,cnt;
int *typetable;
int callfcn(int fcnnr,int cnt,int *typetable)
{
int pop=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 "system.h"
#include "graph.h"
#include "eval.h"
#include "util.h"
#include "gencode.h"
#ifndef NORSCID
#ifndef NORCSID
static char rcs_id[] = "$Id$" ;
#endif
@ -18,14 +21,14 @@ label err_goto_label;
genlabel()
int genlabel(void)
{
return(emlabel++);
}
genemlabel()
int genemlabel(void)
{
int l;
@ -39,8 +42,7 @@ genemlabel()
int tronoff=0;
newemblock(nr)
int nr;
void newemblock(int nr)
{
C_df_ilb((label)currline->emlabel);
C_lin((arith)nr);
@ -57,7 +59,7 @@ int nr;
/* Handle data statements */
List *datalist=0;
datastmt()
void datastmt(void)
{
List *l,*l1;
@ -78,7 +80,7 @@ datastmt()
datatable()
void datatable(void)
{
List *l;
int line=0;
@ -100,8 +102,7 @@ datatable()
/* ERROR and exception handling */
exceptstmt(lab)
int lab;
void exceptstmt(int lab)
{
/* exceptions to subroutines are supported only */
extern int gosubcnt;
@ -116,8 +117,7 @@ int lab;
errorstmt(exprtype)
int exprtype;
void errorstmt(int exprtype)
{
/* convert expression to a valid error number */
/* obtain the message and print it */
@ -128,8 +128,7 @@ int exprtype;
/* BASIC IO */
openstmt(recsize)
int recsize;
void openstmt(int recsize)
{
C_loc((arith)recsize);
C_cal("_opnchn");
@ -138,8 +137,7 @@ int recsize;
printstmt(exprtype)
int exprtype;
void printstmt(int exprtype)
{
switch(exprtype)
{
@ -165,16 +163,14 @@ int exprtype;
zone(i)
int i;
void zone(int i)
{
if ( i) C_cal("_zone");
}
writestmt(exprtype,comma)
int exprtype,comma;
void writestmt(int exprtype, int comma)
{
if ( comma) C_cal("_wrcomma");
@ -198,8 +194,7 @@ int exprtype,comma;
restore(lab)
int lab;
void restore(int lab)
{
/* save this information too */
@ -213,8 +208,7 @@ int lab;
prompt(qst)
int qst;
void prompt(int qst)
{
setchannel(-1);
C_cal("_prstr");
@ -224,8 +218,7 @@ int qst;
linestmt(type)
int type;
void linestmt(int type)
{
if ( type!= STRINGTYPE)
error("String variable expected");
@ -235,8 +228,7 @@ int type;
readelm(type)
int type;
void readelm(int type)
{
switch(type)
{
@ -259,8 +251,7 @@ int type;
/* Swap exchanges the variable values */
swapstmt(ltype,rtype)
int ltype, rtype;
void swapstmt(int ltype,int rtype)
{
if ( ltype!= rtype)
error("Type mismatch");
@ -287,9 +278,9 @@ int ltype, rtype;
/* input/output handling */
setchannel(val)
int val;
{ /* obtain file descroption */
void setchannel(int val)
{
/* obtain file descroption */
C_loc((arith)val);
C_cal("_setchan");
C_asp((arith)BEMINTSIZE);
@ -298,8 +289,7 @@ int val;
/* The if-then-else statements */
ifstmt(type)
int type;
int ifstmt(int type)
{
/* This BASIC follows the True= -1 rule */
int nr;
@ -322,8 +312,7 @@ int type;
thenpart( elselab)
int elselab;
int thenpart(int elselab)
{
int nr;
@ -335,7 +324,7 @@ int elselab;
elsepart(lab)int lab;
void elsepart(int lab)
{
C_df_ilb((label)lab);
}
@ -359,8 +348,7 @@ int forcnt= -1;
forinit(s)
Symbol *s;
void forinit(Symbol *s)
{
int type;
struct FORSTRUCT *f;
@ -388,8 +376,7 @@ Symbol *s;
forexpr(type)
int type;
void forexpr(int type)
{
/* save start value of loop variable in a save place*/
/* to avoid clashing with final value and step expression */
@ -402,8 +389,7 @@ int type;
forlimit(type)
int type;
void forlimit(int type)
{
/* save the limit value too*/
int result;
@ -415,8 +401,7 @@ int type;
forskipped(f)
struct FORSTRUCT *f;
void forskipped(struct FORSTRUCT *f)
{
int type;
@ -452,8 +437,7 @@ struct FORSTRUCT *f;
forstep(type)
int type;
void forstep(int type)
{
int result;
int varaddress;
@ -522,8 +506,7 @@ int type;
nextstmt(s)
Symbol *s;
void nextstmt(Symbol *s)
{
if (forcnt>MAXFORDEPTH || forcnt<0 ||
(s && s!= fortable[forcnt].loopvar))
@ -538,8 +521,7 @@ Symbol *s;
pokestmt(type1,type2)
int type1,type2;
void pokestmt(int type1,int type2)
{
conversion(type1,INTTYPE);
conversion(type2,INTTYPE);
@ -553,7 +535,7 @@ int type1,type2;
int whilecnt, whilelabels[MAXDEPTH][2]; /*0=head,1=out */
whilestart()
void whilestart(void)
{
whilecnt++;
if ( whilecnt==MAXDEPTH)
@ -567,8 +549,7 @@ whilestart()
whiletst(exprtype)
int exprtype;
void whiletst(int exprtype)
{
/* test expression type */
conversion(exprtype,INTTYPE);
@ -577,7 +558,7 @@ int exprtype;
wend()
void wend(void)
{
if ( whilecnt<1)
error("not part of while statement");
@ -591,7 +572,7 @@ wend()
/* generate code for the final version */
prologcode()
void prologcode(void)
{
/* generate the EM prolog code */
C_df_dnam("fltnull");
@ -623,7 +604,7 @@ prologcode()
prolog2()
void prolog2(void)
{
int result;
label l = genlabel(), l2;
@ -659,7 +640,7 @@ prolog2()
/* NEW */
gendata()
void gendata(void)
{
C_loc((arith)0);
C_cal("_setchan");
@ -685,7 +666,7 @@ gendata()
epilogcode()
void epilogcode(void)
{
/* finalization code */
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 "util.h"
#include "eval.h"
#include "gencode.h"
#ifndef NORSCID
#ifndef NORCSID
static char rcs_id[] = "$Id$" ;
#endif
@ -18,7 +21,7 @@ Linerecord *firstline,
List *newlist()
List *newlist(void)
{
List *l;
@ -29,8 +32,7 @@ List *newlist()
/* Line management is handled here */
Linerecord *srchline(nr)
int nr;
Linerecord *srchline(int nr)
{
Linerecord *l;
@ -41,8 +43,7 @@ int nr;
List *srchforward(nr)
int nr;
List *srchforward(int nr)
{
List *l;
@ -53,7 +54,7 @@ int nr;
linewarnings()
void linewarnings(void)
{
List *l;
extern int errorcnt;
@ -72,8 +73,7 @@ linewarnings()
newblock(nr)
int nr;
void newblock(int nr)
{
Linerecord *l;
List *frwrd;
@ -111,8 +111,7 @@ int nr;
gotolabel(nr)
int nr;
int gotolabel(int nr)
{
/* simulate a goto statement in the line record table */
Linerecord *l1;
@ -146,8 +145,7 @@ int nr;
gotostmt(nr)
int nr;
void gotostmt(int nr)
{
C_bra((label) gotolabel(nr));
}
@ -160,7 +158,7 @@ int gosubcnt=1;
List *gosublabel()
List *gosublabel(void)
{
List *l;
@ -177,8 +175,7 @@ List *gosublabel()
gosubstmt(lab)
int lab;
void gosubstmt(int lab)
{
List *l;
int nr,n;
@ -197,7 +194,7 @@ int lab;
genreturns()
void genreturns(void)
{
int count;
int nr;
@ -227,7 +224,7 @@ genreturns()
returnstmt()
void returnstmt(void)
{
C_cal("_retstmt");
C_lfr((arith) BEMINTSIZE);
@ -242,8 +239,7 @@ List *jumphead,*jumptail;
int jumpcnt;
jumpelm(nr)
int nr;
void jumpelm(int nr)
{
List *l;
@ -260,8 +256,7 @@ int nr;
ongotostmt(type)
int type;
void ongotostmt(int type)
{
/* generate the code itself, index in on top of the stack */
/* blurh, store the number of entries in the descriptor */
@ -294,8 +289,7 @@ int type;
ongosubstmt(type)
int type;
void ongosubstmt(int type)
{
List *l;
int firstlabel;

View file

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

View file

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

View file

@ -3,6 +3,9 @@
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
#ifndef __SYMBOLS_H_INCLUDED__
#define __SYMBOLS_H_INCLUDED__
#ifndef NORCSID
# define RCS_SYMB "$Id$"
#endif
@ -85,4 +88,21 @@ typedef struct SYMBOL{
int isparam;
} 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".
*/
#include "system.h"
#include "util.h"
#include "bem.h"
#ifndef NORSCID
#ifndef NORCSID
static char rcs_id[] = "$Id$" ;
#endif
@ -16,25 +19,8 @@ int errorcnt;
void
warning(str)
char *str;
{
if (wflag) return;
Xerror("WARNING", str);
}
error(str)
char *str;
{
Xerror("ERROR", str);
errorcnt++;
}
Xerror(type, str)
char *str;
char *type;
static void Xerror(char *type, char *str)
{
extern int listing;
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);
C_close();
@ -55,22 +56,21 @@ char *str;
notyetimpl()
void notyetimpl(void)
{
warning("not yet implemented");
}
illegalcmd()
void illegalcmd(void)
{
warning("illegal command");
}
char *myitoa(i)
int i;
char *myitoa(int i)
{
static char buf[30];
@ -79,12 +79,7 @@ int i;
}
char *salloc(length)
unsigned length;
char *salloc(unsigned int length)
{
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;
yylexp()
extern int yylex(void);
int yylexp(void)
{
/* als toknum != 0 dan bevat toknum een door LLmessage back-ge-pushed token */