SuivantPrec.Bas prec.BasNiv. sup.

Chapter 4 The parser 

ASET uses Lex and Yacc for Turbo Pascal (Version 2.0 by Albert Graef) to scan and parse the input.

It's hard to describe the details of the parser in other words than lex's and yacc's :-). Therefore I simply include the specifications here for anybody who is interested in the details.

 special         [-+*/%(),!<>=^']
 
 str0            [^-+*/%(),!<>=^' \t\n]+
 str1            '[^'\n]*'
 
 %%
 
 ^#.*            ;
 
 ":="            return(T_ASSIGN);
 "**"            return(ord('^'));
 "div"           return(ord(T_DIV));
 "mod"           return(ord('%'));
 "and"           return(T_AND);
 "or"            return(T_OR);
 "nand"          return(T_NAND);
 "nor"           return(T_NOR);
 "xor"           return(T_XOR);
 "not"           return(T_NOT);
 
 "!="            return(T_NE);
 "=="            return(ord('='));
 "ne"            return(T_NE);
 "eq"            return(ord('='));
 "lt"            return(ord('<'));
 "gt"            return(ord('>'));
 "le"            return(T_LE);
 "ge"            return(T_GE);
 
 ^{str0}         begin
                  { the first value will never be treated as a function,
                    because it is always the target of an assignment }
                    Passign(yylval.strg,yytext);
                    return(T_VALUE)
                 end;
 
 {str0}          begin
                   if (lookup(yytext,yylval.func)) then
                     return(T_FUNCTION)
                   else begin
                     Passign(yylval.strg,yytext);
                     return(T_VALUE)
                   end
                 end;
 
 {str1}          begin
                   Passign(yylval.strg,copy(yytext,2,yyleng-2));
                   return(T_VALUE)
                 end;
 
 [ \t]+          ;
 {special}       return(ord(yytext[1]));
 \n              return(ord(yytext[1]));
 
 %%
 ---------------------------------------------------------------------------
 %union {
   case boolean of
     false: (func: integer);
     true:  (strg: Pstrg);
   }
 
 %token <strg> T_VALUE
 %type  <strg> expr
 %type  <strg> optexpr
 %token <func> T_FUNCTION
 %token T_ASSIGN
 %left  T_AND T_OR T_NAND T_NOR T_XOR
 %left  '=' T_NE '<' T_LE '>' T_GE
 %left  '+' '-'
 %left  '^' '*' '/' '%' T_DIV
 %right T_UMINUS T_UNOT
 %token T_NOT
 
 %%
 
 input   : /* empty */
         | T_VALUE assop expr
         | T_VALUE assop
         | T_VALUE
         | error
         ;
 
 assop   : T_ASSIGN
         | '='
         ;
 expr    : expr '+' expr
         | expr '-' expr
         | expr '*' expr
         | expr '/' expr
         | expr '%' expr
         | expr '^' expr
         | expr T_DIV expr
         | expr '=' expr
         | expr '<' expr
         | expr '>' expr
         | expr T_NE expr
         | expr T_LE expr
         | expr T_GE expr
         | expr T_AND expr
         | expr T_OR expr
         | expr T_NAND expr
         | expr T_NOR expr
         | expr T_XOR expr
         | '(' expr ')'
         | T_NOT expr %prec T_UNOT
         | '-' expr %prec T_UMINUS
         | T_VALUE
         | T_VALUE T_VALUE
         | T_FUNCTION optpars
         ;
 
 optpars : /* empty */
         | '(' parlist ')'
         ;
 parlist : optexpr
         | parlist "," optexpr
         ;
 
 optexpr : /* empty */
         | expr
         ;
 
 %%
 ---------------------------------------------------------------------------
SuivantPrec.Bas prec.HautNiv. sup.