Author: kjs
Date: Tue Mar 27 01:58:21 2007
New Revision: 17783

Modified:
   trunk/compilers/pirc/src/pirlexer.c
   trunk/compilers/pirc/src/pirout.c
   trunk/compilers/pirc/src/pirparser.c

Log:
compilers/pirc:
* add support for parrot ops 'PIR style'
(op A, B -> A = op B)
* improve pirout

Modified: trunk/compilers/pirc/src/pirlexer.c
==============================================================================
--- trunk/compilers/pirc/src/pirlexer.c (original)
+++ trunk/compilers/pirc/src/pirlexer.c Tue Mar 27 01:58:21 2007
@@ -587,6 +587,7 @@
 is_op(char *word) {
     if (strcmp(word, "add") == 0) return 1; /* FIX */
     if (strcmp(word, "print") == 0) return 1;
+    if (strcmp(word, "new") == 0) return 1;
     return 0;
 }
 
@@ -720,6 +721,7 @@
 read_token(lexer_state *lexer) {
     char c;
     int ok = 1;
+    int count;
 
     /* before reading a new token, first clear the buffer */
     clear_buffer(lexer);
@@ -792,24 +794,42 @@
 =cut
 
 */
-        /* now start checking for real tokens */
+        /* now start checking for real tokens */        
         switch(c) {
             case 'P':
-                read_digits(lexer);
-                return T_PASM_PREG;
+                count = read_digits(lexer);
+                buffer_char(lexer, c);
+                c = read_char(lexer->curfile);
+                if (count > 0 && isspace(c) ) return T_PASM_PREG;
+                //else unread_char(lexer->curfile);
+                break;
             case 'S':
-                read_digits(lexer);
-                return T_PASM_SREG;
+                count = read_digits(lexer);
+                buffer_char(lexer, c);
+                c = read_char(lexer->curfile);
+                if (count > 0 && isspace(c) ) return T_PASM_SREG;
+                //else unread_char(lexer->curfile);
+                break;
             case 'I':
-                read_digits(lexer);
-                return T_PASM_IREG;
+                count = read_digits(lexer);
+                buffer_char(lexer, c);
+                c = read_char(lexer->curfile);
+                if (count > 0 && isspace(c) ) return T_PASM_IREG;
+                //else unread_char(lexer->curfile);
+                break;
             case 'N':
-                read_digits(lexer);
-                return T_PASM_NREG;
-            default:
+                count = read_digits(lexer);
+                buffer_char(lexer, c);
+                c = read_char(lexer->curfile);
+                if (count > 0 && isspace(c) ) return T_PASM_NREG;
+                //else unread_char(lexer->curfile);                    
+                break;
+            default:                
                 break; /* continue below */
         }
 
+
+        
         /* it was not a PASM register */
 
 /*
@@ -1543,3 +1563,4 @@
  * End:
  * vim: expandtab shiftwidth=4:
  */
+

Modified: trunk/compilers/pirc/src/pirout.c
==============================================================================
--- trunk/compilers/pirc/src/pirout.c   (original)
+++ trunk/compilers/pirc/src/pirout.c   Tue Mar 27 01:58:21 2007
@@ -12,29 +12,34 @@
 pirout(struct parser_state *p) {
     struct lexer_state *l = get_lexer(p);
     token t = get_token(p);
-
+    
     switch (t) {
         case T_RPAREN:            /* HACK */
             fprintf(stderr, ")"); /* and print newline as well, nec. for 
macros */
         case T_NEWLINE:
             fprintf(stderr, "\n");
-            break;
+            break;  
+        case T_INTEGER_CONSTANT:
+        case T_NUMBER_CONSTANT:
+        case T_DOUBLE_QUOTED_STRING:
+        case T_SINGLE_QUOTED_STRING:            
+        case T_PARROT_OP:            
         case T_IDENTIFIER:
         case T_PASM_PREG:
-        case T_PASM_NREG:
+        case T_PASM_NREG:                                
         case T_PASM_IREG:
         case T_PASM_SREG:
         case T_PREG:
         case T_NREG:
-        case T_SREG:
-        case T_IREG:
-            fprintf(stderr, " %s ", get_current_token(l));
+        case T_SREG:    
+        case T_IREG:    
+            fprintf(stderr, " %s ", get_current_token(l));                     
              
             break;
-        default:
+        default:            
             fprintf(stderr, "%s ", find_keyword(t));
             break;
     }
-
+       
 }
 
 /*

Modified: trunk/compilers/pirc/src/pirparser.c
==============================================================================
--- trunk/compilers/pirc/src/pirparser.c        (original)
+++ trunk/compilers/pirc/src/pirparser.c        Tue Mar 27 01:58:21 2007
@@ -265,6 +265,7 @@
         case T_PASM_NREG: case T_NREG:
         case T_PASM_IREG: case T_IREG:
         case T_PASM_SREG: case T_SREG:
+        case T_MACRO_IDENT:
             exprtok = p->curtoken;
             next(p);
             break;
@@ -588,6 +589,7 @@
                     | heredocstring
                     | methodcall
                     | 'null'
+                    | PARROT_OP [ expression { ',' expression } ]
                     )
 
   unop       -> '-' | '!' | '~'
@@ -643,6 +645,16 @@
         case T_NULL:
             next(p);
             break;
+        case T_PARROT_OP:
+            next(p);
+            if (p->curtoken != T_NEWLINE) {
+                expression(p);
+                while (p->curtoken == T_COMMA) {
+                    next(p);
+                    expression(p);            
+                }
+            }            
+            break;            
         case T_HEREDOC_ID: { /* parse heredoc string */
             char *heredocid = clone_string(get_current_token(p->lexer));
             /* read_heredoc() returns a special token */

Reply via email to