OpenCores
URL https://opencores.org/ocsvn/tms1000/tms1000/trunk

Subversion Repositories tms1000

[/] [tms1000/] [trunk/] [assembler/] [casml.l] - Rev 2

Compare with Previous | Blame | View Log

/*
casm.l: lexical analyzer specification

CASM is an assembler for the TMS1000 processor.
*/

%{
#include "y.tab.h"
#include "symtab.h"
#include "casm.h"

#ifdef OLD_FLEX
#undef yywrap
/* Only needed for versions of flex prior to 2.4.1. */
int yywrap (void);
#endif /* OLD_FLEX */

#undef YY_INPUT
#define YY_INPUT(buf,result,max_size) \
  { \
    int r = strlen (lineptr); \
    if (r > max_size) \
      r = max_size; \
    memcpy (buf, lineptr, r); \
    lineptr += r; \
    result = r; \
  }
#if 0
    fprintf (stderr, "yy_input: '%s', %d\n", lineptr, r); \

#endif
%}

octaldig        [0-7]
hexdigit    [0-9a-fA-F]
digit           [0-9]
alpha           [a-zA-Z]
alphanum        [a-zA-Z0-9_]

%%
{digit}+        { yylval.integer = atoi (yytext); return INTEGER; }

@{hexdigit}     { sscanf (yytext+1, "%x", &yylval.integer); return INTEGER; }

{alpha}{alphanum}*      {
                          if (yylval.integer = keyword (yytext))
                            return yylval.integer;
                          yylval.string = newstr (yytext);
                          return IDENT;
                        }


\;.*            ;
[ \t]+          ;
\n              ;
.               { return yytext [0]; }

%%

struct keyword
{
  char *name;
  int value;
}
keywords [] =
{
   "br",     BR ,
   "call",   CALL ,
   "calll",  CALLL,
   "clo",    CLO ,
   "comx",   COMX ,
   "ldp",    LDP  ,
   "ldx",    LDX  ,
   "sbit",   SBIT ,
   "rbit",   RBIT ,
   "retn",   RETN ,
   "rstr",   RSTR ,
   "setr",   SETR ,
   "tdo",    TDO  ,
   "alec",   ALEC ,
   "alem",   ALEM ,
   "amaac",  AMAAC,
   "a6aac",  A6AAC,
   "a8aac",  A8AAC,
   "a10aac", A10AAC,
   "cla",    CLA  ,
   "cpaiz",  CPAIZ,
   "dan",    DAN  ,
   "dman",   DMAN ,
   "dyn",    DYN  ,
   "ia",     IA   ,
   "imac",   IMAC ,
   "iyc",    IYC  ,
   "knez",   KNEZ ,
   "mnez",   MNEZ ,
   "saman",  SAMAN,
   "tam",    TAM  ,
   "tamiy",  TAMIY,
   "tamza",  TAMZA,
   "tay",    TAY  ,
   "tbit1",  TBIT1,
   "tcy",    TCY  ,
   "tcmiy",  TCMIY,
   "tka",    TKA  ,
   "tma",    TMA  ,
   "tmy",    TMY  ,
   "tya",    TYA  ,
   "xma",    XMA  ,
   "ynea",   YNEA ,
   "ynec",   YNEC ,
   "bl",     BL ,
   "rom",    ROM ,   
   "symtab", SYMTAB,
    NULL,        0,
};

int keyword (char *string)
{
  struct keyword *ptr;

  for (ptr = keywords; ptr->name; ptr++)
    if (stricmp (string, ptr->name) == 0)
      return ptr->value;
  return 0;
}

int yywrap (void)
{
#ifdef OLD_FLEX
/* Only needed for versions of flex prior to 2.4.1. */
  yyrestart (yyin);
#endif /* OLD_FLEX */
  return (1);
}

Compare with Previous | Blame | View Log

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.