[Z88dk-commits] CVS: z88dk/src/z80asm scan_rules.h, NONE, 1.1 scan_r

Bridge to the z88dk-commits mailing list
Post Reply
pauloscustodio

[Z88dk-commits] CVS: z88dk/src/z80asm scan_rules.h, NONE, 1.1 scan_r

Post by pauloscustodio »

Update of /cvsroot/z88dk/z88dk/src/z80asm
In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv21183

Modified Files:
hist.c prsline.c scan.c scan.h token.h token_def.h z80asm.h
z80asm.vcxproj z80asm.vcxproj.filters z80instr.c
Added Files:
scan_rules.h scan_rules.rl
Removed Files:
scan.rl
Log Message:
BUG_0044: binary constants with more than 8 bits not accepted
CH_0022: Added syntax to define binary numbers as bitmaps
Replaced tokenizer with Ragel based scanner.
Simplified scanning code by using ragel instead of hand-built scanner
and tokenizer.
Removed 'D' suffix to signal decimal number.
Parse AF' correctly.
Decimal numbers expressed as sequence of digits, e.g. 1234.
Hexadecimal numbers either prefixed with '0x' or '$' or suffixed with 'H',
in which case they need to start with a digit, or start with a zero,
e.g. 0xFF, $ff, 0FFh.
Binary numbers either prefixed with '0b' or '@', or suffixed with 'B',
e.g. 0b10101, @10101, 10101b.

--- NEW FILE: scan_rules.h ---












static const int asm_start = 9;
static const int asm_error = 0;

static const int asm_en_main = 9;



[...2877 lines suppressed...]
goto tr93;

case 8:
goto tr16;

case 35:
goto tr93;

case 36:
goto tr93;
}
}

_out:
{}
}


return tok;
}

--- NEW FILE: scan_rules.rl ---
/*
ZZZZZZZZZZZZZZZZZZZZ 8888888888888 00000000000
ZZZZZZZZZZZZZZZZZZZZ 88888888888888888 0000000000000
ZZZZZ 888 888 0000 0000
ZZZZZ 88888888888888888 0000 0000
ZZZZZ 8888888888888 0000 0000 AAAAAA SSSSSSSSSSS MMMM MMMM
ZZZZZ 88888888888888888 0000 0000 AAAAAAAA SSSS MMMMMM MMMMMM
ZZZZZ 8888 8888 0000 0000 AAAA AAAA SSSSSSSSSSS MMMMMMMMMMMMMMM
ZZZZZ 8888 8888 0000 0000 AAAAAAAAAAAA SSSSSSSSSSS MMMM MMMMM MMMM
ZZZZZZZZZZZZZZZZZZZZZ 88888888888888888 0000000000000 AAAA AAAA SSSSS MMMM MMMM
ZZZZZZZZZZZZZZZZZZZZZ 8888888888888 00000000000 AAAA AAAA SSSSSSSSSSS MMMM MMMM

Copyright (C) Paulo Custodio, 2011-2014

Define rules for a ragel-based scanner. Needs to be pre-preocessed before calling
ragel, to expand token definition from token_def.h.

$Header: /cvsroot/z88dk/z88dk/src/z80asm/scan_rules.rl,v 1.1 2014/03/29 00:33:29 pauloscustodio Exp $
*/

#define TOKEN(name, string) \
string <CAT> i <NL> \
{ <NL> \
<TAB> tok = name; <NL> \
<TAB> tok_text = string; <NL> \
<TAB> fbreak; <NL> \
}; <NL>

#define TOKEN2(name, string) TOKEN(name, string)

#define KEYWORD(name, parser, value) \
#name <CAT> i <NL> \
{ <NL> \
<TAB> tok = TK_NAME; <NL> \
<TAB> tok_name = #name; <NL> \
<TAB> tok_parser = parser;<NL> \
<TAB> tok_number = value; <NL> \
<TAB> fbreak; <NL> \
}; <NL>

%%{
machine asm;

/* check predicates - beginning of line */
action at_bol { at_bol }

/* Alpha numeric characters or underscore. */
alnum_u = alnum | '_';

/* Alpha characters or underscore. */
alpha_u = alpha | '_';

/* Name */
name = alpha_u alnum_u*;

/* Label */
label = "." [ \t]* name | name [ \t]* ":";

/* binary digit */
bdigit = [01];


/* STATE MACHINE */
main := |*

/* Comment */
';' [^\n]* ;

/* Whitespace is standard ws, newlines and control codes */
any - 0x21..0x7e - '\n' ;

/* Identifier */
name | "af'"i
{
tok = TK_NAME;
set_tok_name();
fbreak;
};

/* Label */
label when at_bol
{
/* remove '.' and ':' */
while ( ts[ 0] == '.' || isspace(ts[ 0]) ) ts++;
while ( te[-1] == ':' || isspace(te[-1]) ) te--;

/* copy token */
tok = TK_LABEL;
set_tok_name();
fbreak;
};

/* Numbers - do not accept 'D' */
digit+ /* 'd'i? */
{
/* remove 'D'
if ( toupper(te[-1]) == 'D' ) te--;
*/

tok = TK_NUMBER;
tok_number = scan_num( ts, te - ts, 10 );
fbreak;
};
digit xdigit* 'h'i
{
tok = TK_NUMBER;
tok_number = scan_num( ts, te - ts - 1, 16 );
fbreak;
};
"$" xdigit+
{
tok = TK_NUMBER;
tok_number = scan_num( ts + 1, te - ts - 1, 16 );
fbreak;
};
'0x'i xdigit+
{
tok = TK_NUMBER;
tok_number = scan_num( ts + 2, te - ts - 2, 16 );
fbreak;
};
bdigit+ 'b'i
{
tok = TK_NUMBER;
tok_number = scan_num( ts, te - ts - 1, 2 );
fbreak;
};
"@" bdigit+
{
tok = TK_NUMBER;
tok_number = scan_num( ts + 1, te - ts - 1, 2 );
fbreak;
};
'0b'i bdigit+
{
tok = TK_NUMBER;
tok_number = scan_num( ts + 2, te - ts - 2, 2 );
fbreak;
};
'@' '"' [\-#]+ '"'
{
tok = TK_NUMBER;
tok_number = scan_num( ts + 2, te - ts - 3, 2 );
fbreak;
};

/* Single Quote */
"'" (any - "'" - "\n") "'"
{
tok = TK_NUMBER;
tok_number = ts[1];
fbreak;
};

"'"
{
tok = TK_NUMBER;
tok_number = 0;
error_invalid_squoted_string();
skip_to_newline();
fbreak;
};

/* Double Quote */
'"' (any - '"' - "\n")* '"'
{
tok = TK_STRING;
Str_set_n( tok_string_buf, ts+1, te-ts-2 );
fbreak;
};

'"'
{
tok = TK_STRING;
Str_clear( tok_string_buf );
error_unclosed_string();
skip_to_newline();
fbreak;
};


/* import token state machines */
#include "token_def.h"

/* default */
any
{
tok = TK_NIL;
skip_to_newline();
fbreak;
};

*|;
}%%

%% write data nofinal;

static void set_scan_buf( char *text, BOOL _at_bol )
{
Str_set( input_buf, text ); /* sets p = input_buf->str */

/* init state */
at_bol = _at_bol;
pe = input_buf->str + input_buf->len;
eof = pe; /* tokens are not split acros input lines */

%% write init;
}

static tokid_t _scan_get( void )
{
%% write exec;
return tok;
}

Index: hist.c
===================================================================
RCS file: /cvsroot/z88dk/z88dk/src/z80asm/hist.c,v
retrieving revision 1.79
retrieving revision 1.80
diff -C2 -d -r1.79 -r1.80
*** hist.c 6 Mar 2014 00:29:01 -0000 1.79
--- hist.c 29 Mar 2014 00:33:28 -0000 1.80
***************
*** 25,28 ****
--- 25,43 ----
/*
* $Log$
+ * Revision 1.80 2014/03/29 00:33:28 pauloscustodio
+ * BUG_0044: binary constants with more than 8 bits not accepted
+ * CH_0022: Added syntax to define binary numbers as bitmaps
+ * Replaced tokenizer with Ragel based scanner.
+ * Simplified scanning code by using ragel instead of hand-built scanner
+ * and tokenizer.
+ * Removed 'D' suffix to signal decimal number.
+ * Parse AF' correctly.
+ * Decimal numbers expressed as sequence of digits, e.g. 1234.
+ * Hexadecimal numbers either prefixed with '0x' or '$' or suffixed with 'H',
+ * in which case they need to start with a digit, or start with a zero,
+ * e.g. 0xFF, $ff, 0FFh.
+ * Binary numbers either prefixed with '0b' or '@', or suffixed with 'B',
+ * e.g. 0b10101, @10101, 10101b.
+ *
* Revision 1.79 2014/03/06 00:29:01 pauloscustodio
* spelling
***************
*** 1388,1392 ****
modified list_get_page_nr() to return -1 after the whole source is
processed.
- - Added flex-based scanner, not yet integrated into assembler
- Decouple module name creation from parsing, define CURRENTMODULE->mname
directly instead of calling DeclModuleName()
--- 1403,1406 ----
***************
*** 1545,1549 ****
- mkinit.pl to generate new main function that calls a set of initializers
before user main()
- - Replace Flex-based lexer by a Ragel-based one.
- Move FileStack implementation to scan.c, remove FileStack.
- Move getline_File() to scan.c.
--- 1559,1562 ----
***************
*** 1641,1644 ****
--- 1654,1685 ----

-------------------------------------------------------------------------------
+ 29.03.2014 [2.1.6] (pauloscustodio)
+ -------------------------------------------------------------------------------
+ BUG_0044: binary constants with more than 8 bits not accepted
+ Limit of 8 bits removed.
+
+ CH_0022: Added syntax to define binary numbers as bitmaps, e.g.
+ defb @"--------" ; 0x00
+ defb @"---##---" ; 0x18
+ defb @"--#--#--" ; 0x24
+ defb @"-#----#-" ; 0x42
+ defb @"-######-" ; 0x7E
+ defb @"-#----#-" ; 0x42
+ defb @"-#----#-" ; 0x42
+ defb @"--------" ; 0x00
+
+ - Replaced tokenizer with Ragel based scanner.
+ Simplified scanning code by using ragel instead of hand-built scanner
+ and tokenizer.
+ Removed 'D' suffix to signal decimal number.
+ Parse AF' correctly.
+ Decimal numbers expressed as sequence of digits, e.g. 1234.
+ Hexadecimal numbers either prefixed with '0x' or '$' or suffixed with 'H',
+ in which case they need to start with a digit, or start with a zero,
+ e.g. 0xFF, $ff, 0FFh.
+ Binary numbers either prefixed with '0b' or '@', or suffixed with 'B',
+ e.g. 0b10101, @10101, 10101b.
+
+ -------------------------------------------------------------------------------
FUTURE CHANGES - require change of the object file format
-------------------------------------------------------------------------------
***************
*** 1664,1673 ****
data appears in the middle of other library modules.

- CH_0019 : Replaced tokenizer with Flex based scanner
- Simplified code by using flex instead of special-built scanner and
- tokenizer.
-
- Sections
- - Standard operators in expressions

*/
--- 1705,1709 ----
***************
*** 1677,1681 ****
#include "hist.h"

! #define VERSION "2.1.5"
#define COPYRIGHT "InterLogic 1993-2009, Paulo Custodio 2011-2014"

--- 1713,1717 ----
#include "hist.h"

! #define VERSION "2.1.6"
#define COPYRIGHT "InterLogic 1993-2009, Paulo Custodio 2011-2014"


Index: prsline.c
===================================================================
RCS file: /cvsroot/z88dk/z88dk/src/z80asm/prsline.c,v
retrieving revision 1.54
retrieving revision 1.55
diff -C2 -d -r1.54 -r1.55
*** prsline.c 18 Mar 2014 22:44:03 -0000 1.54
--- prsline.c 29 Mar 2014 00:33:28 -0000 1.55
***************
*** 22,27 ****
#include "config.h"
#include "errors.h"
- #include "init.h"
- #include "list.h"
#include "listfile.h"
#include "options.h"
--- 22,25 ----
***************
*** 43,480 ****
int CheckCondition( void );

- /* global variables */
- extern int currentline;
- extern struct module *CURRENTMODULE;
-
- /* current input buffer */
- static Str *input_buffer = NULL;
- static char *input_ptr = "";
-
- /* stack of previous contexts */
- static List *input_stack;
-
- /* current symbol */
- tokid_t tok = TK_NIL;
- static Str *tok_name_str = NULL;
- char *tok_name = ""; /* contains identifier to return with TK_NAME and TK_LABEL */
- static Str *tok_string_str = NULL;
- char *tok_string = ""; /* contains double-quoted string without quotes
- to return with a TK_STRING */
- long tok_number; /* contains number to return with a TK_NUMBER */
-
- /* scanner state */
- BOOL EOL;
-
- /*-----------------------------------------------------------------------------
- * Init functions
- *----------------------------------------------------------------------------*/
- DEFINE_init()
- {
- input_buffer = OBJ_NEW(Str);
- input_ptr = input_buffer->str;
-
- input_stack = OBJ_NEW(List);
- input_stack->free_data = xfreef;
-
- tok_name_str = OBJ_NEW(Str);
- tok_name = tok_name_str->str;
-
- tok_string_str = OBJ_NEW(Str);
- tok_string = tok_string_str->str;
- }
-
- DEFINE_fini()
- {
- OBJ_DELETE(input_buffer);
- OBJ_DELETE(input_stack);
- OBJ_DELETE(tok_name_str);
- OBJ_DELETE(tok_string_str);
- }
-
- /*-----------------------------------------------------------------------------
- *
- *----------------------------------------------------------------------------*/
-
- /* set new input buffer */
- static void set_input_buffer( char *line )
- {
- Str_set( input_buffer, line );
- input_ptr = input_buffer->str; /* point to start, to '\0' on eof */
- }
-
- /*-----------------------------------------------------------------------------
- * Update tok_name
- *----------------------------------------------------------------------------*/
- static void tok_name_clear( void )
- {
- Str_clear( tok_name_str );
- tok_name = tok_name_str->str;
- }
-
- static void tok_name_append( char c )
- {
- Str_append_char( tok_name_str, c );
- tok_name = tok_name_str->str; /* may have reallocated */
- }
-
-
-
- /* set a new input text */
- void SetTemporaryLine( char *line )
- {
- init();
-
- List_push( & input_stack, xstrdup(input_ptr) ); /* save current input */
- set_input_buffer( line );
- }
-
- /* Unget the given char */
- static void UnGet( int c )
- {
- assert( input_buffer != NULL );
- assert( input_ptr > input_buffer->str && input_ptr <= input_buffer->str + input_buffer->len );
-
- input_ptr--;
- *input_ptr = c;
- }
-
- /* save scan position and retrieve it, for back-tracking */
- char *ScanGetPos( void )
- {
- init();
-
- return input_ptr;
- }
-
- void ScanSetPos( char *pos )
- {
- init();
-
- assert( pos != NULL );
- assert( pos >= input_buffer->str && pos <= input_buffer->str + input_buffer->len );
-
- input_ptr = pos;
- }
-
- /* get a character from file */
- static int GetChar( void )
- {
- int c;
- char *line;
-
- init();
-
- while (TRUE)
- {
- /* get character from current buffer */
- c = *input_ptr;
- if ( c != '\0' )
- {
- input_ptr++;
- return c;
- }
-
- /* get last buffer from stack, if any */
- line = List_pop( input_stack );
- if ( line != NULL )
- {
- set_input_buffer( line );
- xfree( line );
- }
- else
- {
- /* get next line from input file */
- line = src_getline();
- if ( line == NULL )
- return EOF;
-
- /* got new line */
- set_input_buffer( line );
- }
- }
- }
-
- /* check for multi-char tokens */
- static BOOL GetComposed( char *expect )
- {
- size_t len = strlen(expect);
-
- if ( strncmp( input_ptr, expect, len ) == 0 )
- {
- input_ptr += len;
- return TRUE;
- }
- else
- return FALSE;
- }
-
- /* check for numbers */
- static int get_digit( char c )
- {
- c = toupper(c);
- if ( c >= '0' && c <= '9' )
- return c - '0';
- else if ( c >= 'A' && c <= 'F' )
- return 10 + c - 'A';
- else
- return -1;
- }
-
- static BOOL get_digits( int base, int start, int *pend, long *pvalue )
- {
- long value = 0;
- int i, digit;
-
- for (i = start; TRUE; i++)
- {
- digit = get_digit( input_ptr[i] );
- if (digit < 0 || digit >= base)
- break;
-
- value = base * value + digit;
- }
-
- /* no digits found */
- if (i == start)
- return FALSE;
-
- /* return value and index of end */
- *pend = i;
- *pvalue = value;
- return TRUE;
- }
-
- static int is_alnum_bar(int c) { return c == '_' || isalnum(c); }
-
- static BOOL ParseNumber( long *pvalue )
- {
- int end;
-
- /* parse prefix */
- if ( input_ptr[0] == '$' &&
- get_digits(16, 1, &end, pvalue) &&
- ! is_alnum_bar( input_ptr[end] ) )
- {
- input_ptr += end;
- return TRUE;
- }
- else if ( (input_ptr[0] == '@' || input_ptr[0] == '%') &&
- get_digits(2, 1, &end, pvalue) &&
- ! is_alnum_bar( input_ptr[end] ) )
- {
- input_ptr += end;
- return TRUE;
- }
- else if ( (input_ptr[0] == '0' && tolower(input_ptr[1]) == 'x') &&
- get_digits(16, 2, &end, pvalue) &&
- ! is_alnum_bar( input_ptr[end] ) )
- {
- input_ptr += end;
- return TRUE;
- }
- else if ( isdigit( input_ptr[0] ) &&
- get_digits(16, 0, &end, pvalue) &&
- tolower( input_ptr[end] ) == 'h' &&
- ! is_alnum_bar( input_ptr[end + 1] ) )
- {
- input_ptr += end + 1;
- return TRUE;
- }
- else if ( isdigit( input_ptr[0] ) &&
- get_digits(10, 0, &end, pvalue) &&
- tolower( input_ptr[end] ) == 'd' &&
- ! is_alnum_bar( input_ptr[end + 1] ) )
- {
- input_ptr += end + 1;
- return TRUE;
- }
- else if ( isdigit( input_ptr[0] ) &&
- get_digits(2, 0, &end, pvalue) &&
- tolower( input_ptr[end] ) == 'b' &&
- ! is_alnum_bar( input_ptr[end + 1] ) )
- {
- input_ptr += end + 1;
- return TRUE;
- }
- else if ( isdigit( input_ptr[0] ) &&
- get_digits(10, 0, &end, pvalue) &&
- ! is_alnum_bar( input_ptr[end] ) )
- {
- input_ptr += end;
- return TRUE;
- }
- else
- {
- return FALSE;
- }
- }
-
- /* get the next token */
- tokid_t GetSym( void )
- {
- int c;
-
- init();
-
- if ( EOL )
- return (tok = TK_NEWLINE); /* assign and return */
-
- for ( ;; )
- {
- /* Ignore leading white spaces, if any... */
- c = GetChar();
- if ( c == EOF )
- {
- return (tok = TK_EOF); /* assign and return */
- }
- else if ( c == '\n' )
- {
- EOL = TRUE;
- return (tok = TK_NEWLINE); /* assign and return */
- }
- else if ( !isspace( c ) )
- {
- break;
- }
- }
-
- /* comment */
- if ( c == ';' )
- {
- Skipline(); /* ignore comment line, prepare for next line */
- return (tok = TK_NEWLINE); /* assign and return */
- }
-
- /* double-quoted string */
- if ( c == '"' )
- {
- char *quote = strchr( input_ptr, '"' );
- if ( quote == NULL )
- {
- error_unclosed_string();
- quote = input_ptr + strlen(input_ptr); /* consider string up to end of input */
- if (quote > input_ptr && quote[-1] == '\n')
- quote--; /* exclude newline */
- }
-
- /* copy chars up to close quote */
- Str_set( tok_string_str, input_ptr );
- tok_string_str->str[ quote - input_ptr ] = '\0';
- Str_sync_len( tok_string_str );
-
- tok_string = tok_string_str->str;
-
- input_ptr = quote; /* advance past string */
- if ( *input_ptr == '"' )
- input_ptr++; /* advance past quote */
-
- return (tok = TK_STRING); /* assign and return */
- }
-
- /* single-quoted string */
- if ( c == '\'' )
- {
- char *quote = strchr( input_ptr, '\'' );
- if ( quote == NULL || quote - input_ptr != 1 ) /* only 1-char quoted strings */
- {
- tok_number = 0;
- error_invalid_squoted_string();
- Skipline();
- }
- else
- {
- tok_number = (byte_t) input_ptr[0];
- input_ptr = quote + 1; /* advance past string */
- }
-
- return (tok = TK_NUMBER); /* assign and return */
- }
-
- /* special cases for composed separators */
- if ( ispunct(c) )
- {
- input_ptr--;
-
- if ( GetComposed( "**" ) ) return (tok = TK_POWER); /* assign and return */
- if ( GetComposed( "==" ) ) return (tok = TK_EQUAL); /* assign and return */
- if ( GetComposed( "!=" ) ) return (tok = TK_NOT_EQ); /* assign and return */
- if ( GetComposed( "<>" ) ) return (tok = TK_NOT_EQ); /* assign and return */
- if ( GetComposed( "<=" ) ) return (tok = TK_LESS_EQ); /* assign and return */
- if ( GetComposed( ">=" ) ) return (tok = TK_GREATER_EQ); /* assign and return */
- if ( GetComposed( "<<" ) ) return (tok = TK_LEFT_SHIFT); /* assign and return */
- if ( GetComposed( ">>" ) ) return (tok = TK_RIGHT_SHIFT); /* assign and return */
- if ( GetComposed( "&&" ) ) return (tok = TK_LOG_AND); /* assign and return */
- if ( GetComposed( "||" ) ) return (tok = TK_LOG_OR); /* assign and return */
-
- input_ptr++;
- }
-
- /* single char separators */
- tok = char_token( c );
- if ( tok != TK_NIL )
- return tok;
-
- /* numbers */
- if ( isdigit( c ) || c == '$' || c == '@' || c == '%' )
- {
- input_ptr--;
-
- if ( ParseNumber(&tok_number) )
- return (tok = TK_NUMBER); /* assign and return */
-
- input_ptr++;
- }
-
- /* identifiers */
- if ( isalpha( c ) || c == '_' )
- {
- tok = TK_NAME;
-
- tok_name_clear();
- tok_name_append( toupper( c ) );
-
- while (1)
- {
- c = GetChar();
- if ( c == EOF )
- break;
-
- if ( ! is_alnum_bar( c ) )
- {
- if ( c == ':' ) /* eat ':' if any */
- tok = TK_LABEL;
- else
- UnGet( c );
- break;
- }
-
- tok_name_append( toupper( c ) );
- }
-
- return tok;
- }
-
- /* rubish */
- return (tok = TK_NIL); /* assign and return */
- }
-
-
- void Skipline( void )
- {
- init();
-
- if ( ! EOL )
- {
- while ( *input_ptr != '\0' && *input_ptr != '\n' )
- input_ptr++;
-
- if ( *input_ptr == '\n' )
- input_ptr++;
-
- EOL = TRUE;
- }
- }
-
-
struct
{
--- 41,44 ----
***************
*** 512,517 ****
uint_t len = strlen( text );

- init();
-
for ( i = 0; i < NUM_ELEMS( flags ); i++ )
{
--- 76,79 ----
***************
*** 539,544 ****
CheckRegister8( void )
{
- init();
-
if ( tok == TK_NAME )
{
--- 101,104 ----
***************
*** 669,674 ****
CheckRegister16( void )
{
- init();
-
if ( tok == TK_NAME )
{
--- 229,232 ----
***************
*** 693,696 ****
--- 251,258 ----
return REG16_AF;
}
+ else if ( strcmp( tok_name, "AF'" ) == 0 )
+ {
+ return REG16_AF1;
+ }
else if ( strcmp( tok_name, "IX" ) == 0 )
{
***************
*** 720,725 ****
int reg16;

- init();
-
GetSym();
reg16 = CheckRegister16();
--- 282,285 ----
***************
*** 759,762 ****
--- 319,337 ----
/*
* $Log$
+ * Revision 1.55 2014/03/29 00:33:28 pauloscustodio
+ * BUG_0044: binary constants with more than 8 bits not accepted
+ * CH_0022: Added syntax to define binary numbers as bitmaps
+ * Replaced tokenizer with Ragel based scanner.
+ * Simplified scanning code by using ragel instead of hand-built scanner
+ * and tokenizer.
+ * Removed 'D' suffix to signal decimal number.
+ * Parse AF' correctly.
+ * Decimal numbers expressed as sequence of digits, e.g. 1234.
+ * Hexadecimal numbers either prefixed with '0x' or '$' or suffixed with 'H',
+ * in which case they need to start with a digit, or start with a zero,
+ * e.g. 0xFF, $ff, 0FFh.
+ * Binary numbers either prefixed with '0b' or '@', or suffixed with 'B',
+ * e.g. 0b10101, @10101, 10101b.
+ *
* Revision 1.54 2014/03/18 22:44:03 pauloscustodio
* Scanner decodes a number into tok_number.
***************
*** 773,777 ****
*
* Revision 1.51 2014/03/11 23:34:00 pauloscustodio
! * Remove check for feof(z80asmfile), add token TK_EOF to return on EOF.
* Allows decoupling of input file used in scanner from callers.
* Removed TOTALLINES.
--- 348,352 ----
*
* Revision 1.51 2014/03/11 23:34:00 pauloscustodio
! * Remove check for feof(z80asmfile), add token TK_END to return on EOF.
* Allows decoupling of input file used in scanner from callers.
* Removed TOTALLINES.

Index: scan.c
===================================================================
RCS file: /cvsroot/z88dk/z88dk/src/z80asm/scan.c,v
retrieving revision 1.43
retrieving revision 1.44
diff -C2 -d -r1.43 -r1.44
*** scan.c 11 Mar 2014 22:59:20 -0000 1.43
--- scan.c 29 Mar 2014 00:33:28 -0000 1.44
***************
*** 1,4 ****
-
- //#line 1 "scan.rl"
/*
ZZZZZZZZZZZZZZZZZZZZ 8888888888888 00000000000
--- 1,2 ----
***************
*** 15,23 ****
Copyright (C) Paulo Custodio, 2011-2014

! Scanner - to be processed by: ragel -G2 scan.rl
[...2154 lines suppressed...]

/*
! * $Log$
! * Revision 1.44 2014/03/29 00:33:28 pauloscustodio
! * BUG_0044: binary constants with more than 8 bits not accepted
! * CH_0022: Added syntax to define binary numbers as bitmaps
! * Replaced tokenizer with Ragel based scanner.
! * Simplified scanning code by using ragel instead of hand-built scanner
! * and tokenizer.
! * Removed 'D' suffix to signal decimal number.
! * Parse AF' correctly.
! * Decimal numbers expressed as sequence of digits, e.g. 1234.
! * Hexadecimal numbers either prefixed with '0x' or '$' or suffixed with 'H',
! * in which case they need to start with a digit, or start with a zero,
! * e.g. 0xFF, $ff, 0FFh.
! * Binary numbers either prefixed with '0b' or '@', or suffixed with 'B',
! * e.g. 0b10101, @10101, 10101b.
! *
* Revision 1.14 2014/03/05 23:44:55 pauloscustodio
* Renamed 64-bit portability to BUG_0042

Index: scan.h
===================================================================
RCS file: /cvsroot/z88dk/z88dk/src/z80asm/scan.h,v
retrieving revision 1.31
retrieving revision 1.32
diff -C2 -d -r1.31 -r1.32
*** scan.h 16 Mar 2014 19:19:49 -0000 1.31
--- scan.h 29 Mar 2014 00:33:28 -0000 1.32
***************
*** 13,19 ****
Copyright (C) Paulo Custodio, 2011-2014

! Scanner header corresponding to scan.rl
! Note: the scanner is not reentrant. scan_get() relies on state variables that
! need to be kept across calls.

$Header$
--- 13,17 ----
Copyright (C) Paulo Custodio, 2011-2014

! Scanner. Scanning engine is built by ragel from scan_rules.rl.

$Header$
***************
*** 22,134 ****
#pragma once

- #include "xmalloc.h" /* before any other include */
-
#include "token.h"
#include "types.h"

- /* declare prsline.c externals */
- extern tokid_t GetSym( void );
- extern void SetTemporaryLine( char *line );
- extern char *ScanGetPos( void );
- extern void ScanSetPos( char *pos );
- extern void Skipline( void );
-
- extern tokid_t tok; /* current token */
- extern char *tok_name; /* contains identifier to return with TK_NAME and TK_LABEL */
- extern char *tok_string; /* contains double-quoted string without quotes
- to return with a TK_STRING */
- extern long tok_number; /* contains number to return with TK_NUMBER */
-
- extern BOOL EOL;
-
/*-----------------------------------------------------------------------------
! * A scanner token is represented as an integer that is the ascii code for
! * the single-character token.
! * 0 represents end of input.
! * Special tokens have codes that do not overlap with the above.
*----------------------------------------------------------------------------*/
! typedef enum token
! {
! T_END = 0,
!
! T_NEWLINE = '\n',
!
! T_EXCLAM = '!',
! T_HASH = '#',
! T_DOLLAR = '$',
! T_PERCENT = '%',
! T_AND = '&',
! T_LPAREN = '(',
! T_RPAREN = ')',
! T_STAR = '*',
! T_PLUS = '+',
! T_COMMA = ',',
! T_MINUS = '-',
! T_DOT = '.',
! T_SLASH = '/',
! T_COLON = ':',
! T_LT = '<',
! T_EQ = '=',
! T_GT = '>',
! T_QUESTION = '?',
! T_AT = '@',
! T_LSQUARE = '[',
! T_BSLASH = '\\',
! T_RSQUARE = ']',
! T_CARET = '^',
! T_BQUOTE = '`',
! T_LCURLY = '{',
! T_VBAR = '|',
! T_RCURLY = '}',
! T_TILDE = '~',
!
! T_EQ_EQ = 128, /* "==" */
! T_LT_GT, /* "<>" */
! T_EXCLAM_EQ, /* "!=" */
! T_LT_EQ, /* "<=" */
! T_GT_EQ, /* ">=" */
! T_VBAR_VBAR, /* "||" */
! T_AND_AND, /* "&&" */
! T_LT_LT, /* "<<" */
! T_GT_GT, /* ">>" */
! T_STAR_STAR, /* "**" */

! T_NAME, /* identifier, sets last_token_str in upper case */
! T_LABEL, /* .identifier | identifier:, sets last_token_str
! in upper case */
! T_STRING, /* double-quoted string, sets last_token_str
! excluding quotes */
! T_NUMBER, /* number or single-quoted char, sets last_token_num */
!
! /* assembly keywords */
! T_ADD,
! T_LD,
! T_NOP,
!
! } Token;

/*-----------------------------------------------------------------------------
! * Globals - last token retrieved
! * last_token_num and last_token_str keep their values until a new token
! * of the same type is retrieved.
*----------------------------------------------------------------------------*/
- extern Token last_token;
- extern long last_token_num;
- extern char *last_token_str;

! /*-----------------------------------------------------------------------------
! * Scan API
! *----------------------------------------------------------------------------*/

! /* prepare for scanning string, bol = TRUE if string is at start of a line,
! to detect label definitions */
! extern void scan_reset( char *text, BOOL _at_bol );

! /* get the next token, set last_tokenXXX as side-effect */
! extern Token scan_get( void );


/*
* $Log$
* Revision 1.31 2014/03/16 19:19:49 pauloscustodio
* Integrate use of srcfile in scanner, removing global variable z80asmfile
--- 20,75 ----
#pragma once

#include "token.h"
#include "types.h"

/*-----------------------------------------------------------------------------
! * Globals - last token retrieved
*----------------------------------------------------------------------------*/
! extern tokid_t tok; /* current token */
! extern char *tok_text; /* contains characters of the retrieved token, only for
! symbols used in the expression parser */
! extern char *tok_name; /* contains identifier to return with TK_NAME and TK_LABEL */
! extern char *tok_string; /* contains double-quoted string without quotes
! to return with a TK_STRING */
! extern long tok_number; /* contains number to return with TK_NUMBER */
! extern void (*tok_parser)(void); /* parser for this keyword as opcode */

! extern BOOL EOL; /* scanner EOL state */

/*-----------------------------------------------------------------------------
! * Scan API
*----------------------------------------------------------------------------*/

! /* get the next token, fill the corresponding tok* variables */
! extern tokid_t GetSym( void );

! /* save the current scan position and back-track to a saved position */
! extern char *ScanGetPos( void );
! extern void ScanSetPos( char *pos );

! /* insert the given text at the current scan position */
! extern void SetTemporaryLine( char *line );

+ /* skip line past the newline, set EOL */
+ extern void Skipline( void );
+ extern BOOL EOL;

/*
* $Log$
+ * Revision 1.32 2014/03/29 00:33:28 pauloscustodio
+ * BUG_0044: binary constants with more than 8 bits not accepted
+ * CH_0022: Added syntax to define binary numbers as bitmaps
+ * Replaced tokenizer with Ragel based scanner.
+ * Simplified scanning code by using ragel instead of hand-built scanner
+ * and tokenizer.
+ * Removed 'D' suffix to signal decimal number.
+ * Parse AF' correctly.
+ * Decimal numbers expressed as sequence of digits, e.g. 1234.
+ * Hexadecimal numbers either prefixed with '0x' or '$' or suffixed with 'H',
+ * in which case they need to start with a digit, or start with a zero,
+ * e.g. 0xFF, $ff, 0FFh.
+ * Binary numbers either prefixed with '0b' or '@', or suffixed with 'B',
+ * e.g. 0b10101, @10101, 10101b.
+ *
* Revision 1.31 2014/03/16 19:19:49 pauloscustodio
* Integrate use of srcfile in scanner, removing global variable z80asmfile

Index: token.h
===================================================================
RCS file: /cvsroot/z88dk/z88dk/src/z80asm/token.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** token.h 1 Mar 2014 15:45:31 -0000 1.2
--- token.h 29 Mar 2014 00:33:28 -0000 1.3
***************
*** 29,32 ****
--- 29,33 ----
*----------------------------------------------------------------------------*/
#define TOKEN(name, string) name,
+ #define TOKEN2(name, string)
typedef enum tokid_t
{
***************
*** 46,49 ****
--- 47,65 ----
/*
* $Log$
+ * Revision 1.3 2014/03/29 00:33:28 pauloscustodio
+ * BUG_0044: binary constants with more than 8 bits not accepted
+ * CH_0022: Added syntax to define binary numbers as bitmaps
+ * Replaced tokenizer with Ragel based scanner.
+ * Simplified scanning code by using ragel instead of hand-built scanner
+ * and tokenizer.
+ * Removed 'D' suffix to signal decimal number.
+ * Parse AF' correctly.
+ * Decimal numbers expressed as sequence of digits, e.g. 1234.
+ * Hexadecimal numbers either prefixed with '0x' or '$' or suffixed with 'H',
+ * in which case they need to start with a digit, or start with a zero,
+ * e.g. 0xFF, $ff, 0FFh.
+ * Binary numbers either prefixed with '0b' or '@', or suffixed with 'B',
+ * e.g. 0b10101, @10101, 10101b.
+ *
* Revision 1.2 2014/03/01 15:45:31 pauloscustodio
* CH_0021: New operators ==, !=, &&, ||, <<, >>, ?:

Index: token_def.h
===================================================================
RCS file: /cvsroot/z88dk/z88dk/src/z80asm/token_def.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** token_def.h 18 Mar 2014 22:44:03 -0000 1.17
--- token_def.h 29 Mar 2014 00:33:29 -0000 1.18
***************
*** 30,34 ****
#endif

! TOKEN( TK_EOF, "" ) /* = 0; end of file reached */
TOKEN( TK_NIL, "" ) /* returned for rubish */
TOKEN( TK_INVALID, "" ) /* used as impossible to get token */
--- 30,40 ----
#endif

! /* used for alias */
! #ifndef TOKEN2
! #define TOKEN2(name, string)
! #endif
!
!
! TOKEN( TK_END, "" ) /* = 0; end of file reached */
TOKEN( TK_NIL, "" ) /* returned for rubish */
TOKEN( TK_INVALID, "" ) /* used as impossible to get token */
***************
*** 37,40 ****
--- 43,47 ----
TOKEN( TK_NUMBER, "" )
TOKEN( TK_STRING, "" )
+ TOKEN( TK_TERN_COND, "" ) /* cond ? true : false */

TOKEN( TK_IF_STMT, "" )
***************
*** 92,97 ****
TOKEN( TK_LEFT_SHIFT, "<<" )
TOKEN( TK_LESS_EQ, "<=" )
! TOKEN( TK_NOT_EQ, "<>" ) /* != */
! TOKEN( TK_EQUAL, "=" ) /* == */
TOKEN( TK_GREATER, ">" )
TOKEN( TK_RIGHT_SHIFT, ">>" )
--- 99,106 ----
TOKEN( TK_LEFT_SHIFT, "<<" )
TOKEN( TK_LESS_EQ, "<=" )
! TOKEN( TK_NOT_EQ, "<>" )
! TOKEN2( TK_NOT_EQ, "!=" )
! TOKEN( TK_EQUAL, "=" )
! TOKEN2( TK_EQUAL, "==" )
TOKEN( TK_GREATER, ">" )
TOKEN( TK_RIGHT_SHIFT, ">>" )
***************
*** 114,117 ****
--- 123,127 ----
#ifdef __LEGACY_Z80ASM_SYNTAX
TOKEN( TK_POWER, "^" )
+ TOKEN2( TK_POWER, "**" )
#else
TOKEN( TK_BIN_XOR, "^" )
***************
*** 133,139 ****
#endif

- /* semantical tokens */
- TOKEN( TK_TERN_COND, "" ) /* cond ? true : false */
-
/* marker to get number of tokens */
TOKEN( NUM_TOKENS, "" )
--- 143,146 ----
***************
*** 143,146 ****
--- 150,168 ----
/*
* $Log$
+ * Revision 1.18 2014/03/29 00:33:29 pauloscustodio
+ * BUG_0044: binary constants with more than 8 bits not accepted
+ * CH_0022: Added syntax to define binary numbers as bitmaps
+ * Replaced tokenizer with Ragel based scanner.
+ * Simplified scanning code by using ragel instead of hand-built scanner
+ * and tokenizer.
+ * Removed 'D' suffix to signal decimal number.
+ * Parse AF' correctly.
+ * Decimal numbers expressed as sequence of digits, e.g. 1234.
+ * Hexadecimal numbers either prefixed with '0x' or '$' or suffixed with 'H',
+ * in which case they need to start with a digit, or start with a zero,
+ * e.g. 0xFF, $ff, 0FFh.
+ * Binary numbers either prefixed with '0b' or '@', or suffixed with 'B',
+ * e.g. 0b10101, @10101, 10101b.
+ *
* Revision 1.17 2014/03/18 22:44:03 pauloscustodio
* Scanner decodes a number into tok_number.

Index: z80asm.h
===================================================================
RCS file: /cvsroot/z88dk/z88dk/src/z80asm/z80asm.h,v
retrieving revision 1.49
retrieving revision 1.50
diff -C2 -d -r1.49 -r1.50
*** z80asm.h 18 Mar 2014 22:44:03 -0000 1.49
--- z80asm.h 29 Mar 2014 00:33:29 -0000 1.50
***************
*** 35,38 ****
--- 35,39 ----
#define REG16_IX 5
#define REG16_IY 6
+ #define REG16_AF1 7

#define FLAGS_NZ 0
***************
*** 60,63 ****
--- 61,79 ----
/*
* $Log$
+ * Revision 1.50 2014/03/29 00:33:29 pauloscustodio
+ * BUG_0044: binary constants with more than 8 bits not accepted
+ * CH_0022: Added syntax to define binary numbers as bitmaps
+ * Replaced tokenizer with Ragel based scanner.
+ * Simplified scanning code by using ragel instead of hand-built scanner
+ * and tokenizer.
+ * Removed 'D' suffix to signal decimal number.
+ * Parse AF' correctly.
+ * Decimal numbers expressed as sequence of digits, e.g. 1234.
+ * Hexadecimal numbers either prefixed with '0x' or '$' or suffixed with 'H',
+ * in which case they need to start with a digit, or start with a zero,
+ * e.g. 0xFF, $ff, 0FFh.
+ * Binary numbers either prefixed with '0b' or '@', or suffixed with 'B',
+ * e.g. 0b10101, @10101, 10101b.
+ *
* Revision 1.49 2014/03/18 22:44:03 pauloscustodio
* Scanner decodes a number into tok_number.
***************
*** 73,77 ****
*
* Revision 1.46 2014/03/11 23:34:00 pauloscustodio
! * Remove check for feof(z80asmfile), add token TK_EOF to return on EOF.
* Allows decoupling of input file used in scanner from callers.
* Removed TOTALLINES.
--- 89,93 ----
*
* Revision 1.46 2014/03/11 23:34:00 pauloscustodio
! * Remove check for feof(z80asmfile), add token TK_END to return on EOF.
* Allows decoupling of input file used in scanner from callers.
* Removed TOTALLINES.

Index: z80asm.vcxproj
===================================================================
RCS file: /cvsroot/z88dk/z88dk/src/z80asm/z80asm.vcxproj,v
retrieving revision 1.45
retrieving revision 1.46
diff -C2 -d -r1.45 -r1.46
*** z80asm.vcxproj 24 Feb 2014 23:08:55 -0000 1.45
--- z80asm.vcxproj 29 Mar 2014 00:33:29 -0000 1.46
***************
*** 168,172 ****
</ItemGroup>
<ItemGroup>
! <None Include="scan.rl" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
--- 168,172 ----
</ItemGroup>
<ItemGroup>
! <None Include="scan_rules.rl" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

Index: z80asm.vcxproj.filters
===================================================================
RCS file: /cvsroot/z88dk/z88dk/src/z80asm/z80asm.vcxproj.filters,v
retrieving revision 1.44
retrieving revision 1.45
diff -C2 -d -r1.44 -r1.45
*** z80asm.vcxproj.filters 24 Feb 2014 23:08:55 -0000 1.44
--- z80asm.vcxproj.filters 29 Mar 2014 00:33:29 -0000 1.45
***************
*** 257,261 ****
</ItemGroup>
<ItemGroup>
! <None Include="scan.rl">
<Filter>Resource Files</Filter>
</None>
--- 257,261 ----
</ItemGroup>
<ItemGroup>
! <None Include="scan_rules.rl">
<Filter>Resource Files</Filter>
</None>

Index: z80instr.c
===================================================================
RCS file: /cvsroot/z88dk/z88dk/src/z80asm/z80instr.c,v
retrieving revision 1.53
retrieving revision 1.54
diff -C2 -d -r1.53 -r1.54
*** z80instr.c 16 Mar 2014 23:57:06 -0000 1.53
--- z80instr.c 29 Mar 2014 00:33:29 -0000 1.54
***************
*** 121,125 ****
break;

! case TK_EOF:
case TK_NEWLINE:
append_byte( 0xC9 );
--- 121,125 ----
break;

! case TK_END:
case TK_NEWLINE:
append_byte( 0xC9 );
***************
*** 225,232 ****
break;

! case 4:
if ( GetSym() == TK_COMMA ) /* EX AF,AF' */
if ( GetSym() == TK_NAME )
! if ( CheckRegister16() == 4 )
{
append_byte( 0x08 );
--- 225,232 ----
break;

! case REG16_AF:
if ( GetSym() == TK_COMMA ) /* EX AF,AF' */
if ( GetSym() == TK_NAME )
! if ( CheckRegister16() == REG16_AF1 )
{
append_byte( 0x08 );
***************
*** 1595,1598 ****
--- 1595,1613 ----
/*
* $Log$
+ * Revision 1.54 2014/03/29 00:33:29 pauloscustodio
+ * BUG_0044: binary constants with more than 8 bits not accepted
+ * CH_0022: Added syntax to define binary numbers as bitmaps
+ * Replaced tokenizer with Ragel based scanner.
+ * Simplified scanning code by using ragel instead of hand-built scanner
+ * and tokenizer.
+ * Removed 'D' suffix to signal decimal number.
+ * Parse AF' correctly.
+ * Decimal numbers expressed as sequence of digits, e.g. 1234.
+ * Hexadecimal numbers either prefixed with '0x' or '$' or suffixed with 'H',
+ * in which case they need to start with a digit, or start with a zero,
+ * e.g. 0xFF, $ff, 0FFh.
+ * Binary numbers either prefixed with '0b' or '@', or suffixed with 'B',
+ * e.g. 0b10101, @10101, 10101b.
+ *
* Revision 1.53 2014/03/16 23:57:06 pauloscustodio
* Removed global line[]
***************
*** 1603,1607 ****
*
* Revision 1.51 2014/03/11 23:34:00 pauloscustodio
! * Remove check for feof(z80asmfile), add token TK_EOF to return on EOF.
* Allows decoupling of input file used in scanner from callers.
* Removed TOTALLINES.
--- 1618,1622 ----
*
* Revision 1.51 2014/03/11 23:34:00 pauloscustodio
! * Remove check for feof(z80asmfile), add token TK_END to return on EOF.
* Allows decoupling of input file used in scanner from callers.
* Removed TOTALLINES.

--- scan.rl DELETED ---


------------------------------------------------------------------------------
Post Reply