]> mj.ucw.cz Git - umpf.git/blobdiff - lex.c
print parse tree
[umpf.git] / lex.c
diff --git a/lex.c b/lex.c
index 4ee876d0e2f7d995b0e5559f08ca1b8db19b27fd..35b5b00f67073f012ad45ad9f68e72fb75610a88 100644 (file)
--- a/lex.c
+++ b/lex.c
@@ -115,18 +115,13 @@ is_alpha(int c)
 int
 yylex(void)
 {
-       int c, nl = 0;
+       int c;
        
        while ((c = getchar ()) == ' ' || c == '\t' || c =='\n'){
-               if (c == '\n'){
-                       nl = 1;
+               if (c == '\n')
                        line++;
-               }
        }
        
-       if (nl)
-               return '\n';
-       
        if (c == EOF)
                return 0;
        
@@ -134,13 +129,13 @@ yylex(void)
        int d = getchar();
        if (d >= 0) {
                switch (CC(c,d)) {
-               case CC('!','='): return NEQ;
-               case CC('!','~'): return NRE;
-               case CC('<','='): return LE;
-               case CC('>','='): return GE;
-               case CC('=','='): return EQ;
-               case CC('~','~'): return RE;
-               case CC('-','>'): return ARROW;
+               case CC('!','='): yylval.n = CC('!','='); return NEQ;
+               case CC('!','~'): yylval.n = CC('!','='); return NRE;
+               case CC('<','='): yylval.n = CC('<','='); return LE;
+               case CC('>','='): yylval.n = CC('>','='); return GE;
+               case CC('=','='): yylval.n = CC('=','='); return EQ;
+               case CC('~','~'): yylval.n = CC('~','~'); return RE;
+               case CC('-','>'): yylval.n = CC('-','>'); return ARROW;
                }
                ungetc(d,stdin);
        }
@@ -158,6 +153,9 @@ yylex(void)
                case '<':
                case '>':
                case '=':
+               case ';':
+               case '.':
+                       yylval.n = c;
                        return c;
                
                case '"':
@@ -182,6 +180,7 @@ yylex(void)
                        if (i >= BUFSIZE-1)
                                parse_err("Too long identifier, max allowed length is %d",BUFSIZE-1);   
                }
+               ungetc(c,stdin);
                buf[i] = 0;
                yylval.str = xstrdup(buf);
 
@@ -199,6 +198,7 @@ yylex(void)
                                parse_err("Keyword too long");
                }
                buf[i] = 0;
+               ungetc(c,stdin);
 
                n = (sizeof(k)/sizeof(struct keys));
                for (i = 0; i < n; i++){