Fixed the extern char *yytext issue once and for all.
authorMilind Bhandarkar <milind@cs.uiuc.edu>
Tue, 15 Jun 1999 23:15:56 +0000 (23:15 +0000)
committerMilind Bhandarkar <milind@cs.uiuc.edu>
Tue, 15 Jun 1999 23:15:56 +0000 (23:15 +0000)
src/langs/sdag/xlator/CLexer.C
src/langs/sdag/xlator/CLexer.h
src/langs/sdag/xlator/sdag-main.C
src/langs/sdag/xlator/trans.l

index 930e4fc618b187688779233a093af3c741b87359..36e09c295e40ae7d63b4b9e3c74b6dfd9b08d49c 100644 (file)
@@ -32,7 +32,7 @@ CToken *CLexer::lookAhead(void)
       delete cToken;
       continue;
     } else {
-      char *yycopy = strdup(yytext);
+      char *yycopy = strdup(myyytext);
       for(int i=strlen(yycopy)-1; i>=0; i-- ) {
         charNum--;
         Unput(yycopy[i]) ;
@@ -53,17 +53,17 @@ CToken *CLexer::getNextToken(void)
     type = yylex();
     if ((int)type == 0)
       return (CToken *) 0;
-    charNum += strlen(yytext);
+    charNum += strlen(myyytext);
     if(type == NEW_LINE) {
       lineNum++;
       charNum = 1;
       if (wsSignificant)
-        return new CToken(type, yytext);
+        return new CToken(type, myyytext);
       else
         continue;
     }
     if((type != WSPACE) || wsSignificant) {
-      cToken = new CToken(type, yytext);
+      cToken = new CToken(type, myyytext);
       // cToken->print(0);
       return cToken;
     }
@@ -149,9 +149,9 @@ CToken *CLexer::getIntExpr(EToken term)
         break;
     }
     if(cToken->type == term && !numBraces && !numParens && !numBrackets) {
-      for(int i=strlen(yytext)-1; i>=0; i-- ) {
+      for(int i=strlen(myyytext)-1; i>=0; i-- ) {
         charNum--;
-        Unput(yytext[i]) ;
+        Unput(myyytext[i]) ;
       }
       endExpr = 1;
     } else {
index 2c59fd7093089d8080750a75e86f87f03d270b60..d2b6ab6752b734c5c44f3dfe30dd9f14538e25e1 100644 (file)
@@ -7,7 +7,7 @@
 #include "string.h"
 
 extern "C" EToken yylex();
-extern "C" char yytext[];
+extern char *myyytext;
 extern "C" void Unput(char);
 
 class CLexer {
index a391f565e297f8ea6fa01db1c0c12dd64528727f..4e1cfac7d02683a2cb07e57e5cc56f496738033f 100644 (file)
@@ -19,7 +19,7 @@ int main(int argc, char *argv[])
   }
   for(int i=1; i<argc; i++) {
     resetNumbers();
-    printf("%s:\n", argv[i]);
+    // printf("%s:\n", argv[i]);
     CParser *cParser = new CParser(argv[i]);
     CParsedFile *parsedFile = cParser->doParse();
     parsedFile->doProcess();
index db3e837dad2fdedbbad439045a93cf7dca8d2e41..7d5f864dfbfb62925df562ad0a76e304da4fde48 100644 (file)
@@ -2,6 +2,10 @@
 #include "EToken.h"
 
 /* Assume that the C-style comments are not present in the source */
+char *myyytext;
+
+#define Return(x) { myyytext = (char *) malloc(strlen(yytext)+1); \
+                    strcpy(myyytext, yytext); return (x); }
 
 %}
 
@@ -30,60 +34,60 @@ octal_constant "0"[0-7]*{integer_suffix_opt}
 hex_constant "0"[xX][0-9a-fA-F]+{integer_suffix_opt}
 %%
 
-{comment}              {return WSPACE;}
-
-{hwhite}+              {return WSPACE;}
-({vt}|{cret}|{ff})+    {return WSPACE;}
-({hwhite}|{vt}|{cret}|{ff})*"\n"       {return(NEW_LINE);}
-
-
-class                  {return(CLASS);}
-sdagentry              {return(SDAGENTRY);}
-overlap                        {return(OVERLAP);}
-when                   {return(WHEN);}
-if                     {return(IF);}
-else                   {return(ELSE);}
-while                  {return(WHILE);}
-forall                 {return(FORALL);}
-for                    {return(FOR);}
-atomic                 {return(ATOMIC);}
-
-{identifier}           {return(IDENT);}
-
-"L"?[']{c_char}+[']    {return(CHAR);}
-"L"?["]{s_char}*["]    {return(STRING);}
-
-"("                    {return(LP);}
-")"                    {return(RP);}
-"["                    {return(LB);}
-"]"                    {return(RB);}
-"{"                    {return(LBRACE);}
-"}"                    {return(RBRACE);}
-"*"                    {return(STAR);}
-":"                    {return(COLON);}
-","                    {return(COMMA);}
-";"                    {return(SEMICOLON);}
-
-"#"                    {return(DEFAULT);}
-"."                    {return(DEFAULT);}
-"&"                    {return(DEFAULT);}
-"+"                    {return(DEFAULT);}
-"-"                    {return(DEFAULT);}
-"~"                    {return(DEFAULT);}
-"!"                    {return(DEFAULT);}
-"/"                    {return(DEFAULT);}
-"%"                    {return(DEFAULT);}
-"<"                    {return(DEFAULT);}
-">"                    {return(DEFAULT);}
-"^"                    {return(DEFAULT);}
-"|"                    {return(DEFAULT);}
-"?"                    {return(DEFAULT);}
-"="                    {return(DEFAULT);}
-
-{decimal_constant}     {return(DEFAULT);}
-{octal_constant}       {return(DEFAULT);}
-{hex_constant}         {return(DEFAULT);}
-{floating_constant}    {return(DEFAULT);}
+{comment}              {Return(WSPACE);}
+
+{hwhite}+              {Return(WSPACE);}
+({vt}|{cret}|{ff})+    {Return(WSPACE);}
+({hwhite}|{vt}|{cret}|{ff})*"\n"       {Return(NEW_LINE);}
+
+
+class                  {Return(CLASS);}
+sdagentry              {Return(SDAGENTRY);}
+overlap                        {Return(OVERLAP);}
+when                   {Return(WHEN);}
+if                     {Return(IF);}
+else                   {Return(ELSE);}
+while                  {Return(WHILE);}
+forall                 {Return(FORALL);}
+for                    {Return(FOR);}
+atomic                 {Return(ATOMIC);}
+
+{identifier}           {Return(IDENT);}
+
+"L"?[']{c_char}+[']    {Return(CHAR);}
+"L"?["]{s_char}*["]    {Return(STRING);}
+
+"("                    {Return(LP);}
+")"                    {Return(RP);}
+"["                    {Return(LB);}
+"]"                    {Return(RB);}
+"{"                    {Return(LBRACE);}
+"}"                    {Return(RBRACE);}
+"*"                    {Return(STAR);}
+":"                    {Return(COLON);}
+","                    {Return(COMMA);}
+";"                    {Return(SEMICOLON);}
+
+"#"                    {Return(DEFAULT);}
+"."                    {Return(DEFAULT);}
+"&"                    {Return(DEFAULT);}
+"+"                    {Return(DEFAULT);}
+"-"                    {Return(DEFAULT);}
+"~"                    {Return(DEFAULT);}
+"!"                    {Return(DEFAULT);}
+"/"                    {Return(DEFAULT);}
+"%"                    {Return(DEFAULT);}
+"<"                    {Return(DEFAULT);}
+">"                    {Return(DEFAULT);}
+"^"                    {Return(DEFAULT);}
+"|"                    {Return(DEFAULT);}
+"?"                    {Return(DEFAULT);}
+"="                    {Return(DEFAULT);}
+
+{decimal_constant}     {Return(DEFAULT);}
+{octal_constant}       {Return(DEFAULT);}
+{hex_constant}         {Return(DEFAULT);}
+{floating_constant}    {Return(DEFAULT);}
 
 %%