[BACK]Return to calclex.l CVS log [TXT][DIR] Up to [local] / OpenXM_contrib / gmp / demos

Annotation of OpenXM_contrib/gmp/demos/calclex.l, Revision 1.1

1.1     ! maekawa     1: /* Lexical analyzer for calc.y. */
        !             2:
        !             3: /*
        !             4: Copyright (C) 2000 Free Software Foundation, Inc.
        !             5:
        !             6: This file is part of the GNU MP Library.
        !             7:
        !             8: This program is free software; you can redistribute it and/or modify it under
        !             9: the terms of the GNU General Public License as published by the Free Software
        !            10: Foundation; either version 2 of the License, or (at your option) any later
        !            11: version.
        !            12:
        !            13: This program is distributed in the hope that it will be useful, but WITHOUT ANY
        !            14: WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
        !            15: PARTICULAR PURPOSE.  See the GNU General Public License for more details.
        !            16:
        !            17: You should have received a copy of the GNU General Public License along with
        !            18: this program; if not, write to the Free Software Foundation, Inc., 59 Temple
        !            19: Place - Suite 330, Boston, MA 02111-1307, USA.
        !            20: */
        !            21:
        !            22:
        !            23: %{
        !            24: #include "calc.h"
        !            25:
        !            26: #define numberof(x)  (sizeof (x) / sizeof ((x)[0]))
        !            27: %}
        !            28:
        !            29: %%
        !            30:
        !            31: [ \t\f] { /* white space is skipped */ }
        !            32:
        !            33: [;\n]   { /* semicolon or newline separates statements */
        !            34:           return EOS; }
        !            35: \\\n    { /* escaped newlines are skipped */ }
        !            36:
        !            37:
        !            38: #(([^\\\n]*)\\)+\n {
        !            39:             /* comment through to escaped newline is skipped */ }
        !            40: #[^\n]*\n { /* comment through to newline is a separator */
        !            41:             return EOS; }
        !            42: #[^\n]* {   /* comment through to EOF skipped */ }
        !            43:
        !            44:
        !            45: [-+*/%()<>^!=,] { return yytext[0]; }
        !            46: "<="    { return LE; }
        !            47: ">="    { return GE; }
        !            48: "=="    { return EQ; }
        !            49: "!="    { return NE; }
        !            50: "<<"    { return LSHIFT; }
        !            51: ">>"    { return RSHIFT; }
        !            52: "&&"    { return LAND; }
        !            53: "||"    { return LOR; }
        !            54:
        !            55: (0[xX])?[0-9A-F]+ {
        !            56:         yylval.str = yytext;
        !            57:         return NUMBER; }
        !            58:
        !            59: [a-zA-Z][a-zA-Z0-9]* {
        !            60:         static struct {
        !            61:           char  *name;
        !            62:           int   value;
        !            63:         } table[] = {
        !            64:           { "abs",       ABS },
        !            65:           { "bin",       BIN },
        !            66:           { "decimal",   DECIMAL },
        !            67:           { "fib",       FIB },
        !            68:           { "hex",       HEX },
        !            69:           { "gcd",       GCD },
        !            70:           { "lcm",       LCM },
        !            71:           { "nextprime", NEXTPRIME },
        !            72:           { "powm",      POWM },
        !            73:           { "quit",      QUIT },
        !            74:           { "root",      ROOT },
        !            75:           { "sqrt",      SQRT },
        !            76:         };
        !            77:         int  i;
        !            78:
        !            79:         for (i = 0; i < numberof (table); i++)
        !            80:           if (strcmp (yytext, table[i].name) == 0)
        !            81:             return table[i].value;
        !            82:
        !            83:         if (yytext[0] >= 'a' && yytext[0] <= 'z' && yytext[1] == '\0')
        !            84:           {
        !            85:             yylval.var = yytext[0] - 'a';
        !            86:             return VARIABLE;
        !            87:           }
        !            88:
        !            89:         return BAD;
        !            90: }
        !            91:
        !            92: . { return BAD; }
        !            93:
        !            94: %%
        !            95:
        !            96: int
        !            97: yywrap ()
        !            98: {
        !            99:   return 1;
        !           100: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>