Author: kjs
Date: Wed Apr 11 13:19:30 2007
New Revision: 18143

Modified:
   trunk/compilers/pirc/src/jsonout.c
   trunk/compilers/pirc/src/pastout.c
   trunk/compilers/pirc/src/pirlexer.c
   trunk/compilers/pirc/src/pirout.c
   trunk/compilers/pirc/src/pirparser.c
   trunk/compilers/pirc/src/pirutil.c
   trunk/compilers/pirc/src/pirvtable.c

Log:
compilers/pirc:
* a bit of refactoring
* fixed some documentation


Modified: trunk/compilers/pirc/src/jsonout.c
==============================================================================
--- trunk/compilers/pirc/src/jsonout.c  (original)
+++ trunk/compilers/pirc/src/jsonout.c  Wed Apr 11 13:19:30 2007
@@ -19,7 +19,6 @@
 #include "pirvtable.h"
 #include <stdio.h>
 #include <stdlib.h>
-#include <malloc.h>
 #include <stdarg.h>
 
 #define OUT             stdout

Modified: trunk/compilers/pirc/src/pastout.c
==============================================================================
--- trunk/compilers/pirc/src/pastout.c  (original)
+++ trunk/compilers/pirc/src/pastout.c  Wed Apr 11 13:19:30 2007
@@ -16,7 +16,7 @@
 #include "pirvtable.h"
 #include <stdio.h>
 #include <stdlib.h>
-#include <malloc.h>
+
 
 /* keep outputfile possibility easy */
 #define OUT         stderr

Modified: trunk/compilers/pirc/src/pirlexer.c
==============================================================================
--- trunk/compilers/pirc/src/pirlexer.c (original)
+++ trunk/compilers/pirc/src/pirlexer.c Wed Apr 11 13:19:30 2007
@@ -46,7 +46,6 @@
 #include "pirutil.h"
 #include <stdio.h>
 #include <stdlib.h>
-#include <malloc.h>
 #include <sys/stat.h>
 #include <ctype.h>
 #include <string.h>
@@ -1122,9 +1121,9 @@
 
   STRING-CONSTANT -> ' <characters> ' | " <characters> "
 
-  INT-CONSTANT    -> DIGIT+ | 0 [xX] DIGIT+ | 0 [bB] DIGIT+
+  INT-CONSTANT    -> [-] DIGIT+ | 0 [xX] DIGIT+ | 0 [bB] DIGIT+
 
-  NUM-CONSTANT    -> DIGIT+ '.' DIGIT*
+  NUM-CONSTANT    -> [-] DIGIT+ '.' DIGIT*
 
   DIGIT           -> [0-9]
 

Modified: trunk/compilers/pirc/src/pirout.c
==============================================================================
--- trunk/compilers/pirc/src/pirout.c   (original)
+++ trunk/compilers/pirc/src/pirout.c   Wed Apr 11 13:19:30 2007
@@ -11,8 +11,6 @@
 #include "pirvtable.h"
 #include "pirlexer.h"
 #include <stdio.h>
-#include <malloc.h>
-#include <malloc.h>
 #include <stdlib.h>
 
 

Modified: trunk/compilers/pirc/src/pirparser.c
==============================================================================
--- trunk/compilers/pirc/src/pirparser.c        (original)
+++ trunk/compilers/pirc/src/pirparser.c        Wed Apr 11 13:19:30 2007
@@ -71,7 +71,7 @@
  typedef struct parser_state {
     struct     lexer_state *lexer;     -- the lexer
     token      curtoken;               -- the current token as returned by the 
lexer
-    char     **heredoc_ids;            -- array for holding heredoc arguments. 
XXX Limited to 10 currently XXX
+    char     **heredoc_ids;            -- array for holding heredoc arguments
     unsigned   heredoc_index;          -- index to keep track of heredoc ids 
in the array
     unsigned   parse_errors;           -- counter for parse_errors
     pirvtable *vtable;                 -- vtable holding pointers for output 
routines
@@ -383,7 +383,6 @@
         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; /* store current token type to return */
             /* emit the expression */
             emit_expr(p, get_current_token(p->lexer));
@@ -560,28 +559,6 @@
 */
 static void
 arg_flags(parser_state *p) {
-    while (p->curtoken != T_NEWLINE) {
-        switch (p->curtoken) {
-            case T_FLAT_FLAG:
-                next(p);
-                break;
-            case T_NAMED_FLAG:
-                next(p);
-                if (p->curtoken == T_LPAREN) {
-                    next(p);
-                    match(p, T_STRING_CONSTANT);
-                    match(p, T_RPAREN);
-                }
-                break;
-            default:
-                syntax_error(p, 1, "':flat' or ':named' flag expected");
-                break;
-        }
-    }
-}
-
-static void
-inline_arg_flags(parser_state *p) {
     int ok = 1;
     while (ok) {
         switch (p->curtoken) {
@@ -596,18 +573,26 @@
                     match(p, T_RPAREN);
                 }
                 break;
+            case T_NEWLINE: /* for long-invocation */
+            case T_COMMA:   /* for short-invocation, comma inmplies next 
argument */
+            case T_RPAREN:  /* for short-invocation, last argument with flags 
*/
+                ok = 0; /* stop loop */
+                break;
             default:
-                ok = 0; /* quit loop */
+                ok = 0; /* stop loop */
+                syntax_error(p, 1, "':flat' or ':named' flag expected");
                 break;
         }
     }
 }
 
+
+
 /*
 
 =item *
 
-  argument -> HEREDOCID | expression | STRINGC '=>' expression
+  argument -> HEREDOCID | expression arg_flags | STRINGC ('=>' expression | 
arg_flags)
 
 =cut
 
@@ -625,7 +610,7 @@
         p->heredoc_ids[p->heredoc_index++] = 
clone_string(get_current_token(p->lexer));
         next(p);
     }
-    else { /* argument -> expression | STRINGC '=>' expression */
+    else { /* argument -> expression [arg_flags] | STRINGC ( '=>' expression | 
arg_flags )*/
         token exprtok = expression(p);
         /* allow for "stringc '=>' expression" */
         if (exprtok == T_STRING_CONSTANT) {
@@ -633,12 +618,12 @@
                 next(p);
                 expression(p);
             }
-            else {
-                inline_arg_flags(p);
+            else { /* a string argument can take arg_flags as well */
+                arg_flags(p);
             }
         }
-        else {
-            inline_arg_flags(p);
+        else { /* it was an expression (but not a stringc), may take arg_flags 
*/
+            arg_flags(p);
         }
     }
 }
@@ -668,7 +653,7 @@
 
 =item *
 
-  arguments         -> '(' [argument_list] ')' heredoc_arguments
+  arguments -> '(' [argument_list] ')' heredoc_arguments
 
   heredoc_arugments -> { HEREDOC_STRING }
 
@@ -702,7 +687,8 @@
             heredocid = NULL;
         }
 
-        /* clear heredoc index */
+        /* clear heredoc index, next time the first
+         * heredoc arg is stored at location 0 again */
         p->heredoc_index = 0;
     }
     emit_args_end(p);
@@ -1330,14 +1316,15 @@
                 }
                 break;
             /* however, if the current token is a comma or ')', then quit 
parsing flags */
-            case T_COMMA: /* huh? */
+            case T_COMMA:
             case T_RPAREN:
             case T_NEWLINE:
                 ok = 0; /* stop loop */
                 break;
             /* if none of the above, error! */
             default:
-                syntax_error(p, 2, "parameter flag or newline expected, but 
got ", find_keyword(p->curtoken));
+                syntax_error(p, 2, "parameter flag or newline expected, but 
got ",
+                             find_keyword(p->curtoken));
                 ok = 0; /* stop loop */
                 break;
         }

Modified: trunk/compilers/pirc/src/pirutil.c
==============================================================================
--- trunk/compilers/pirc/src/pirutil.c  (original)
+++ trunk/compilers/pirc/src/pirutil.c  Wed Apr 11 13:19:30 2007
@@ -10,7 +10,6 @@
 #include "pirutil.h"
 #include <assert.h>
 #include <string.h>
-#include <malloc.h>
 #include <stdio.h>
 #include <stdlib.h>
 
@@ -77,11 +76,7 @@
 
 
 
-
-
-
-
-
+/* Array holding all parrot ops */
 static char const *parrot_ops[] = {
         "yield",
         "xor",
@@ -420,6 +415,9 @@
 
     assert(id != NULL);
 
+    /* very inefficient implementation, but for now it works */
+    /* suggestions: hashtable, binary search */
+
     while (iter != NULL) {
         if (strcmp(iter, id) == 0)
             return 1;

Modified: trunk/compilers/pirc/src/pirvtable.c
==============================================================================
--- trunk/compilers/pirc/src/pirvtable.c        (original)
+++ trunk/compilers/pirc/src/pirvtable.c        Wed Apr 11 13:19:30 2007
@@ -17,7 +17,6 @@
 #include "pirvtable.h"
 #include <stdlib.h>
 #include <stdio.h>
-#include <malloc.h>
 
 
 

Reply via email to