"Fossies" - the Fresh Open Source Software Archive

Member "bas-2.6/token.h" (2 Jul 2019, 10502 Bytes) of package /linux/privat/bas-2.6.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "token.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2.5_vs_2.6.

    1 #ifndef TOKEN_H
    2 #define TOKEN_H
    3 
    4 #include "autotypes.h"
    5 #include "value.h"
    6 #include "var.h"
    7 
    8 enum SymbolType { GLOBALVAR, GLOBALARRAY, LOCALVAR, BUILTINFUNCTION, USERFUNCTION };
    9 
   10 struct Symbol
   11 {
   12   char *name;
   13   enum SymbolType type;
   14   union
   15   {
   16     struct Var var; /* GLOBALVAR, GLOBALARRAY */
   17     struct
   18     {
   19       int offset; /* LOCALVAR */
   20       enum ValueType type;
   21     } local;
   22     struct
   23     {
   24       union
   25       {
   26         struct /* BUILTINFUNCTION */
   27         {
   28           struct Value *(* call)(struct Value *value, struct Auto *stack);
   29           struct Symbol *next;
   30         } bltin;
   31         struct    /* USERFUNTION */
   32         {
   33           struct Scope scope;
   34           int localLength;
   35           enum ValueType *localTypes;
   36         } def;
   37       } u;
   38       int argLength;
   39       enum ValueType *argTypes;
   40       enum ValueType retType;
   41     } sub;
   42   } u;
   43   struct Symbol *next;
   44 };
   45 
   46 #include "program.h"
   47 #include "str.h"
   48 
   49 struct Identifier
   50 {
   51   struct Symbol *sym;
   52   enum ValueType defaultType;
   53   char name[2/* ... */];
   54 };
   55 
   56 struct Next
   57 {
   58   struct Pc fr;
   59   struct Pc var;
   60   struct Pc limit;
   61   struct Pc body;
   62 };
   63 
   64 struct On
   65 {
   66   int pcLength;
   67   struct Pc *pc;
   68 };
   69 
   70 struct Selectcase
   71 {
   72   struct Pc endselect;
   73   enum ValueType type;
   74   struct Pc nextcasevalue;
   75 };
   76 
   77 struct Casevalue
   78 {
   79   struct Pc endselect;
   80   struct Pc nextcasevalue;
   81 };
   82 
   83 enum TokenType
   84 {
   85   T_NOTOKEN=0,
   86   T_ACCESS_READ,
   87   T_ACCESS_READ_WRITE,
   88   T_ACCESS_WRITE,
   89   T_AND,
   90   T_AS,
   91   T_CALL,
   92   T_CASEELSE,
   93   T_CASEVALUE,
   94   T_CHANNEL,
   95   T_CHDIR,
   96   T_CLEAR,
   97   T_CLOSE,
   98   T_CLS,
   99   T_COLON,
  100   T_COLOR,
  101   T_COMMA,
  102   T_CON,
  103   T_COPY,
  104   T_CP,
  105   T_DATA,
  106   T_DATAINPUT,
  107   T_DEC,
  108   T_DEFDBL,
  109   T_DEFFN,
  110   T_DEFINT,
  111   T_DEFPROC,
  112   T_DEFSTR,
  113   T_DELETE,
  114   T_DIM,
  115   T_DISPLAY,
  116   T_DIV,
  117   T_DO,
  118   T_DOUNTIL,
  119   T_DOWHILE,
  120   T_EDIT,
  121   T_ELSE,
  122   T_ELSEIFELSE,
  123   T_ELSEIFIF,
  124   T_END,
  125   T_ENDFN,
  126   T_ENDIF,
  127   T_ENDPROC,
  128   T_ENDSELECT,
  129   T_ENVIRON,
  130   T_EOL,
  131   T_EQ,
  132   T_EQV,
  133   T_ERASE,
  134   T_EXITDO,
  135   T_EXITFOR,
  136   T_FIELD,
  137   T_FILES,
  138   T_FNEND,
  139   T_FNEXIT,
  140   T_FNRETURN,
  141   T_FOR,
  142   T_FOR_INPUT,
  143   T_FOR_OUTPUT,
  144   T_FOR_APPEND,
  145   T_FOR_RANDOM,
  146   T_FOR_BINARY,
  147   T_FUNCTION,
  148   T_GE,
  149   T_GET,
  150   T_GOSUB,
  151   T_GOTO,
  152   T_GT,
  153   T_HEXINTEGER,
  154   T_OCTINTEGER,
  155   T_IDENTIFIER,
  156   T_IDIV,
  157   T_IDN,
  158   T_IF,
  159   T_IMAGE,
  160   T_IMP,
  161   T_INC,
  162   T_INPUT,
  163   T_INTEGER,
  164   T_INV,
  165   T_IS,
  166   T_JUNK,
  167   T_KILL,
  168   T_LE,
  169   T_LET,
  170   T_LINEINPUT,
  171   T_LIST,
  172   T_LLIST,
  173   T_LOAD,
  174   T_LOCAL,
  175   T_LOCATE,
  176   T_LOCK,
  177   T_LOCK_READ,
  178   T_LOCK_WRITE,
  179   T_LOOP,
  180   T_LOOPUNTIL,
  181   T_LPRINT,
  182   T_LSET,
  183   T_LT,
  184   T_MAT,
  185   T_MATINPUT,
  186   T_MATPRINT,
  187   T_MATREAD,
  188   T_MATREDIM,
  189   T_MATWRITE,
  190   T_MINUS,
  191   T_MKDIR,
  192   T_MOD,
  193   T_MULT,
  194   T_NAME,
  195   T_NE,
  196   T_NEW,
  197   T_NEXT,
  198   T_NOT,
  199   T_ON,
  200   T_ONERROR,
  201   T_ONERRORGOTO0,
  202   T_ONERROROFF,
  203   T_OP,
  204   T_OPEN,
  205   T_OPTIONBASE,
  206   T_OPTIONRUN,
  207   T_OPTIONSTOP,
  208   T_OR,
  209   T_OUT,
  210   T_PLUS,
  211   T_POKE,
  212   T_POW,
  213   T_PRINT,
  214   T_PUT,
  215   T_QUOTE,
  216   T_RANDOMIZE,
  217   T_READ,
  218   T_REAL,
  219   T_REM,
  220   T_RENAME,
  221   T_RENUM,
  222   T_REPEAT,
  223   T_RESTORE,
  224   T_RESUME,
  225   T_RETURN,
  226   T_RSET,
  227   T_RUN,
  228   T_SAVE,
  229   T_SELECTCASE,
  230   T_SEMICOLON,
  231   T_SHARED,
  232   T_SHELL,
  233   T_SLEEP,
  234   T_SPC,
  235   T_STEP,
  236   T_STOP,
  237   T_STRING,
  238   T_SUB,
  239   T_SUBEND,
  240   T_SUBEXIT,
  241   T_SWAP,
  242   T_SYSTEM,
  243   T_TAB,
  244   T_THEN,
  245   T_TO,
  246   T_TRN,
  247   T_TROFF,
  248   T_TRON,
  249   T_TRUNCATE,
  250   T_UNLOCK,
  251   T_UNNUM,
  252   T_UNNUMBERED,
  253   T_UNTIL,
  254   T_USING,
  255   T_WAIT,
  256   T_WEND,
  257   T_WHILE,
  258   T_WIDTH,
  259   T_WRITE,
  260   T_XOR,
  261   T_XREF,
  262   T_ZER,
  263   T_ZONE,
  264   T_LASTTOKEN=T_ZONE
  265 };
  266 
  267 struct Token
  268 {
  269   enum TokenType type;
  270   struct Value *(*statement)(struct Value *value);
  271   union
  272   {
  273     /* T_ACCESS_READ        */
  274     /* T_ACCESS_READ_WRITE  */
  275     /* T_ACCESS_WRITE       */
  276     /* T_AND                */
  277     /* T_AS                 */
  278     /* T_CALL               */
  279     /* T_CASEELSE           */ struct Casevalue *casevalue;
  280     /* T_CASEIS             */ /* struct Casevalue *casevalue; */
  281     /* T_CASEVALUE          */ /* struct Casevalue *casevalue; */
  282     /* T_CHANNEL            */
  283     /* T_CHDIR              */
  284     /* T_CLEAR              */
  285     /* T_CLOSE              */
  286     /* T_CLS                */
  287     /* T_COLON              */
  288     /* T_COLOR              */
  289     /* T_COMMA              */
  290     /* T_CON                */
  291     /* T_COPY               */
  292     /* T_CP                 */
  293     /* T_DATA               */ struct Pc nextdata;
  294     /* T_DATAINPUT          */ char *datainput;
  295     /* T_DEFFN              */ struct Symbol *localSyms;
  296     /* T_DEFDBL             */
  297     /* T_DEFINT             */
  298     /* T_DEFPROC            */ /* struct Symbol *localSyms; */
  299     /* T_DELETE             */
  300     /* T_DIM                */
  301     /* T_DIV                */
  302     /* T_DO                 */ struct Pc exitdo;
  303     /* T_DOUNTIL            */ /* struct Pc exitdo; */
  304     /* T_DOWHILE            */ /* struct Pc exitdo; */
  305     /* T_EDIT               */
  306     /* T_ELSE               */ struct Pc endifpc;
  307     /* T_ELSEIFELSE         */ /* struct Pc endifpc; */
  308     /* T_ELSEIFIF           */ struct Pc elsepc;
  309     /* T_END                */ struct Pc endpc;
  310     /* T_ENDFN              */
  311     /* T_ENDIF              */
  312     /* T_ENDPROC            */
  313     /* T_ENDSELECT          */
  314     /* T_ENVIRON            */
  315     /* T_EOL                */
  316     /* T_EQ                 */ enum ValueType type;
  317     /* T_EQV                */
  318     /* T_ERASE              */
  319     /* T_EXITDO             */ /* struct Pc exitdo; */
  320     /* T_EXITFOR            */ struct Pc exitfor;
  321     /* T_FIELD              */
  322     /* T_FNEND              */
  323     /* T_FNRETURN           */
  324     /* T_FOR                */ /* struct Pc exitfor */
  325     /* T_FOR_INPUT          */
  326     /* T_FOR_OUTPUT         */
  327     /* T_FOR_APPEND         */
  328     /* T_FOR_RANDOM         */
  329     /* T_FOR_BINARY         */
  330     /* T_FUNCTION           */ /* struct Symbol *localSyms; */
  331     /* T_GE                 */
  332     /* T_GET                */
  333     /* T_GOSUB              */ struct Pc gosubpc;
  334     /* T_GOTO               */ struct Pc gotopc;
  335     /* T_GT                 */
  336     /* T_HEXINTEGER         */ long int hexinteger;
  337     /* T_OCTINTEGER         */ long int octinteger;
  338     /* T_IDENTIFIER         */ struct Identifier *identifier;
  339     /* T_IDIV               */
  340     /* T_IDN                */
  341     /* T_IF                 */ /* struct Pc elsepc; */
  342     /* T_IMAGE              */ /* struct String *string; */
  343     /* T_IMP                */
  344     /* T_INPUT              */
  345     /* T_INTEGER            */ long int integer;
  346     /* T_INV                */
  347     /* T_IS                 */
  348     /* T_JUNK               */ char junk;
  349     /* T_KILL               */
  350     /* T_LE                 */
  351     /* T_LEN                */
  352     /* T_LET                */
  353     /* T_LINEINPUT          */
  354     /* T_LIST               */
  355     /* T_LLIST              */
  356     /* T_LOAD               */
  357     /* T_LOCAL              */
  358     /* T_LOCATE             */
  359     /* T_LOCK               */
  360     /* T_LOCK_READ          */
  361     /* T_LOCK_WRITE         */
  362     /* T_LOOP               */ struct Pc dopc;
  363     /* T_LOOPUNTIL          */ /* struct Pc dopc; */
  364     /* T_LPRINT             */
  365     /* T_LSET               */
  366     /* T_LT                 */
  367     /* T_MAT                */
  368     /* T_MATINPUT           */
  369     /* T_MATPRINT           */
  370     /* T_MATREAD            */
  371     /* T_MATREDIM           */
  372     /* T_MINUS              */
  373     /* T_MKDIR              */
  374     /* T_MOD                */
  375     /* T_MULT               */
  376     /* T_NAME               */
  377     /* T_NE                 */
  378     /* T_NEW                */
  379     /* T_NEXT               */ struct Next *next;
  380     /* T_NOT                */
  381     /* T_ON                 */ struct On on;
  382     /* T_ONERROR            */
  383     /* T_ONERRORGOTO0       */
  384     /* T_ONERROROFF         */
  385     /* T_OP                 */
  386     /* T_OPEN               */
  387     /* T_OPTIONBASE         */
  388     /* T_OR                 */
  389     /* T_OUT                */
  390     /* T_PLUS               */
  391     /* T_POKE               */
  392     /* T_POW                */
  393     /* T_PRINT              */
  394     /* T_PUT                */
  395     /* T_QUOTE              */ /* char *rem; */
  396     /* T_RANDOMIZE          */
  397     /* T_READ               */
  398     /* T_REAL               */ double real;
  399     /* T_REM                */ char *rem;
  400     /* T_RENAME             */
  401     /* T_RENUM              */
  402     /* T_REPEAT             */
  403     /* T_RESTORE            */ struct Pc restore;
  404     /* T_RESUME             */ /* struct Pc gotopc; */
  405     /* T_RETURN             */
  406     /* T_RSET               */
  407     /* T_RUN                */
  408     /* T_SAVE               */
  409     /* T_SELECTCASE         */ struct Selectcase *selectcase;
  410     /* T_SEMICOLON          */
  411     /* T_SHARED             */
  412     /* T_SHELL              */
  413     /* T_SLEEP              */
  414     /* T_SPC                */
  415     /* T_STEP               */ struct Value step;
  416     /* T_STOP               */
  417     /* T_STRING             */ struct String *string;
  418     /* T_SUB                */ /* struct Symbol *localSyms; */
  419     /* T_SUBEND             */
  420     /* T_SUBEXIT            */
  421     /* T_SWAP               */
  422     /* T_SYSTEM             */
  423     /* T_TAB                */
  424     /* T_THEN               */
  425     /* T_TO                 */
  426     /* T_TRN                */
  427     /* T_TROFF              */
  428     /* T_TRON               */
  429     /* T_TRUNCATE           */
  430     /* T_UNLOCK             */
  431     /* T_UNNUM              */
  432     /* T_UNNUMBERED         */
  433     /* T_UNTIL              */ struct Pc until;
  434     /* T_USING              */ struct Pc image;
  435     /* T_WAIT               */
  436     /* T_WEND               */ struct Pc *whilepc;
  437     /* T_WHILE              */ struct Pc *afterwend;
  438     /* T_WIDTH              */
  439     /* T_WRITE              */
  440     /* T_XOR                */
  441     /* T_XREF               */
  442     /* T_ZER                */
  443     /* T_ZONE               */
  444   } u;
  445 };
  446 
  447 extern struct Token *Token_newCode(const char *ln);
  448 extern struct Token *Token_newData(const char *ln);
  449 extern void Token_destroy(struct Token *token);
  450 extern struct String *Token_toString(struct Token *token, struct Token *spaceto, struct String *s, int *indent, int full);
  451 extern int Token_property[];
  452 #define TOKEN_ISBINARYOPERATOR(t)   (Token_property[t]&1)
  453 #define TOKEN_ISUNARYOPERATOR(t)    (Token_property[t]&(1<<1))
  454 #define TOKEN_BINARYPRIORITY(t)     ((Token_property[t]>>2)&7)
  455 #define TOKEN_UNARYPRIORITY(t)      ((Token_property[t]>>5)&7)
  456 #define TOKEN_ISRIGHTASSOCIATIVE(t) (Token_property[t]&(1<<8))
  457 extern void Token_init(int backslash_colon, int uppercase);
  458 
  459 #endif