Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions sources/compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
*/

#include "form3.h"
#include "comtool.h"

/*
com1commands are the commands of which only part of the word has to
Expand Down Expand Up @@ -566,10 +567,13 @@ int CompileStatement(UBYTE *in)
First the test on the order of the statements.
This is relatively new (2.2c) and may cause some problems with old
programs. Hence the first error message should explain!

Positions of declaration statements with the WITHAUTO flag and
ModuleOption statements for $-variables have been relaxed from v4.2.
*/
if ( AP.PreAssignFlag == 0 && AM.OldOrderFlag == 0 ) {
if ( AP.PreInsideLevel ) {
if ( k->type != STATEMENT && k->type != MIXED ) {
if ( k->type != STATEMENT && k->type != MIXED && (k->type != DECLARATION || !(k->flags & WITHAUTO)) ) {
MesPrint("&Only executable and print statements are allowed in an %#inside/%#endinside construction");
return(-1);
}
Expand All @@ -582,14 +586,36 @@ int CompileStatement(UBYTE *in)
if ( TestTables() ) error1 = 1;
}
}
/*
* Exception rules of the ordering:
* - mixed statements
* - declaration statements with the WITHAUTO flag
* - the Format statement
* - the ModuleOption statement for $-variables
*/
if ( k->type == MIXED ) {
if ( AC.compiletype <= DEFINITION ) {
AC.compiletype = STATEMENT;
}
}
else if ( k->type == DECLARATION && (k->flags & WITHAUTO) ) {
if ( AC.compiletype < DECLARATION ) {
AC.compiletype = DECLARATION;
}
}
else if ( k->type > AC.compiletype ) {
if ( StrCmp((UBYTE *)(k->name),(UBYTE *)"format") != 0 )
AC.compiletype = k->type;
if ( k->type == TOOUTPUT && (StrCmp((UBYTE *)(k->name),(UBYTE *)"format") == 0) )
goto skip_new_compiletype;
if ( k->type == ATENDOFMODULE && (StrCmp((UBYTE *)(k->name),(UBYTE *)"moduleoption") == 0) ) {
UBYTE *ss = s;
SkipSpaces(&ss);
if ( ConsumeOption(&ss,"local") ||
ConsumeOption(&ss,"maximum") ||
ConsumeOption(&ss,"minimum") ||
ConsumeOption(&ss,"sum") ) goto skip_new_compiletype;
}
AC.compiletype = k->type;
skip_new_compiletype:;
}
else if ( k->type < AC.compiletype ) {
switch ( k->type ) {
Expand Down