[llvm-commits] CVS: llvm-test/MultiSource/Benchmarks/Prolangs-C/fixoutput/Makefile fixoutput.c scanner.h stringI.c

Chris Lattner lattner at cs.uiuc.edu
Tue Oct 5 12:30:54 PDT 2004



Changes in directory llvm-test/MultiSource/Benchmarks/Prolangs-C/fixoutput:

Makefile added (r1.1)
fixoutput.c added (r1.1)
scanner.h added (r1.1)
stringI.c added (r1.1)
---
Log message:

This program fixes the output of something.


---
Diffs of the changes:  (+462 -0)

Index: llvm-test/MultiSource/Benchmarks/Prolangs-C/fixoutput/Makefile
diff -c /dev/null llvm-test/MultiSource/Benchmarks/Prolangs-C/fixoutput/Makefile:1.1
*** /dev/null	Tue Oct  5 14:30:53 2004
--- llvm-test/MultiSource/Benchmarks/Prolangs-C/fixoutput/Makefile	Tue Oct  5 14:30:43 2004
***************
*** 0 ****
--- 1,6 ----
+ LEVEL = ../../../..
+ 
+ PROG = fixoutput
+ #STDIN_FILENAME = $(SourceDir)/testset
+ include $(LEVEL)/MultiSource/Makefile.multisrc
+ 


Index: llvm-test/MultiSource/Benchmarks/Prolangs-C/fixoutput/fixoutput.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/Prolangs-C/fixoutput/fixoutput.c:1.1
*** /dev/null	Tue Oct  5 14:30:54 2004
--- llvm-test/MultiSource/Benchmarks/Prolangs-C/fixoutput/fixoutput.c	Tue Oct  5 14:30:43 2004
***************
*** 0 ****
--- 1,320 ----
+ 
+ #include "scanner.h"                /* Useful Macro Definitions */
+ #include <stdio.h>
+ 
+ /* File I/O Variables and Functions in file stringIO.c */
+ extern char CH;            /* current input character */
+ extern char *LEXEME;       /* string read in since the last flush */
+ 
+ extern char *FRONT,*BACK;  /* FRONT: pointer to current input character in
+ 			         LEXEME.
+ 			      BACK: pointer to the first input character in
+ 			      LEXEME, in fact equal to LEXEME */
+ extern unsigned LEX_LEN;   /* current size of LEXEME buffer. Will change. */
+ 
+ extern void FLUSH();       /* a function that sets LEXEME to null */
+ extern void GETCHR();      /* a function that gets the next character and 
+ 			      updates LEXEME,FRONT,and BACK appropriately */
+ extern void BACKUP();      /* a function that undoes the last not undone 
+ 			      GETCHR */
+ 
+ static EOF_FLAG = 1, ERROR_CNT = 0;   /* End Of File Flag and ERROR CouNT */
+ 
+ static void GETSTR(void)   /* read in a string from the input stream */
+ {
+   GETCHR();
+   if (CH == ' ') {
+     FLUSH();
+     GETCHR();
+   }
+   else {
+     ERROR_CNT ++;
+     printf("------------>ERROR: Expected a SPACE between Token Code and\n");
+     printf("                    the string following it <--------\n");
+   }
+   while (CH != '\n' && CH != EOF) GETCHR();
+   if (CH == '\n')
+     BACKUP();
+   else
+     EOF_FLAG = 0;
+ }
+ 
+ void main(void)
+ {
+   int CODE;     /* TOKEN CODE */
+   int I1,I2;    /* temp storage */
+   double D1;    /* temp storage */
+ /* intialization */
+   LEXEME = (char *) calloc(LEX_LEN,1);
+   FLUSH();
+ 
+ /* main */
+   while (EOF_FLAG) {
+     scanf("%d",&CODE);
+ 
+     if (!feof(stdin)) {
+       switch (CODE) {
+ 
+          case ERRORMSG_1:
+             GETSTR();
+ 	    printf("Scanner ERROR: %s\n",LEXEME);
+ 	    break;
+ 
+          case LINE_1:
+ 	    scanf("%d",&I1);
+ 	    printf("===================> LINE NUMBER: %d\n",I1);
+ 	    break;
+ 
+ 	 case ADDOP_1:
+ 	    scanf("%d",&I1);
+ 	    printf("   ADDOP: ");
+ 	    switch (I1) {
+ 	       case PLUS_1:
+ 	         printf("+\n");
+ 		 break;
+ 	       case MINUS_1:
+ 		 printf("-\n");
+ 		 break;
+ 	       case OR_1:
+ 		 printf("OR\n");
+ 		 break;
+ 	       default: {
+ 		 ERROR_CNT ++;
+ 		 printf("---------->ERROR: Expected an ADDOP Found: %d\n",I1);
+ 	         }
+ 	       }
+ 	    break;
+ 
+ 	 case MULOP_1:
+ 	    scanf("%d",&I1);
+ 	    printf("   MULOP: ");
+ 	    switch (I1) {
+ 	       case TIMES_1:
+ 	         printf("*\n");
+ 		 break;
+ 	       case SLASH_1:
+ 		 printf("/\n");
+ 		 break;
+ 	       case AND_1:
+ 		 printf("AND\n");
+ 		 break;
+ 	       case DIV_1:
+ 		 printf("DIV\n");
+ 		 break;
+ 	       default: {
+ 		 ERROR_CNT ++;
+ 		 printf("---------->ERROR: Expected an MULOP Found: %d\n",I1);
+ 	         }
+ 	       }
+ 	    break;
+ 
+ 	 case RELOP_1:
+ 	    scanf("%d",&I1);
+ 	    printf("   RELOP: ");
+ 	    switch (I1) {
+ 	       case EQUAL_1:
+ 	         printf("=\n");
+ 		 break;
+ 	       case NOTEQUAL_1:
+ 		 printf("<>\n");
+ 		 break;
+ 	       case LESSTHANOREQUAL_1:
+ 		 printf("<=\n");
+ 		 break;
+ 	       case LESSTHAN_1:
+ 		 printf("<\n");
+ 		 break;
+ 	       case GREATERTHANOREQUAL_1:
+ 		 printf(">=\n");
+ 		 break;
+ 	       case GREATERTHAN_1:
+ 		 printf(">\n");
+ 		 break;
+ 	       default: {
+ 		 ERROR_CNT ++;
+ 		 printf("---------->ERROR: Expected an RELOP Found: %d\n",I1);
+ 	         }
+ 	       }
+ 	    break;
+ 
+ 	 case ASSIGN_1:
+ 	    printf("   ASSIGN (:=) \n");
+ 	    break;
+ 
+ 	 case COLON_1:
+ 	    printf("   COLON (:) \n");
+ 	    break;
+ 
+ 	 case DOTDOT_1:
+ 	    printf("   DOTDOT (..) \n");
+ 	    break;
+ 
+ 	 case DOT_1:
+ 	    printf("   DOT (.) \n");
+ 	    break;
+ 
+ 	 case INTEGER_NUMBER_1:
+ 	    scanf("%d",&I1);
+ 	    printf("   Integer: ");
+ 	    if (I1 == ILLEGAL_1)
+ 	      printf("illegal\n");
+ 	    else
+ 	      if (I1 == VALID_1) {
+ 		scanf("%d",&I2);
+ 		printf("%d\n",I2);
+ 	      }
+ 	      else {
+ 		ERROR_CNT ++;
+ 		printf("---------->ERROR: Expected a VALID/ILLEGAL Code \n");
+ 	        printf("                  found: %d\n",I1);
+ 	      }
+ 	    break;
+ 
+ 	 case REAL_NUMBER_1:
+ 	    scanf("%d",&I1);
+ 	    printf("   Real: ");
+ 	    if (I1 == ILLEGAL_1)
+ 	      printf("illegal\n");
+ 	    else
+ 	      if (I1 == VALID_1) {
+ 		scanf("%lf",&D1);
+ 		printf("%g\n",D1);
+ 	      }
+ 	      else {
+ 		ERROR_CNT ++;
+ 		printf("---------->ERROR: Expected a VALID/ILLEGAL Code \n");
+ 	        printf("                  found: %d\n",I1);
+ 	      }
+ 	    break;
+ 
+ 	 case PROGRAM_1:
+ 	    printf("   PROGRAM \n");
+ 	    break;
+ 
+ 	 case VAR_1:
+ 	    printf("   VAR \n");
+ 	    break;
+ 
+ 	 case INTEGER_1:
+ 	    printf("   INTEGER (KEYWORD) \n");
+ 	    break;
+ 
+ 	 case REAL_1:
+ 	    printf("   REAL (KEYWORD) \n");
+ 	    break;
+ 
+ 	 case ARRAY_1:
+ 	    printf("   ARRAY \n");
+ 	    break;
+ 
+ 	 case OF_1:
+ 	    printf("   OF \n");
+ 	    break;
+ 
+ 	 case PROCEDURE_1:
+ 	    printf("   PROCEDURE \n");
+ 	    break;
+ 
+ 	 case FORWARD_1:
+ 	    printf("   FORWARD \n");
+ 	    break;
+ 
+ 	 case FUNCTION_1:
+ 	    printf("   FUNCTION \n");
+ 	    break;
+ 
+ 	 case BEGIN_1:
+ 	    printf("   BEGIN \n");
+ 	    break;
+ 
+ 	 case END_1:
+ 	    printf("   END \n");
+ 	    break;
+ 
+ 	 case READ_1:
+ 	    printf("   READ \n");
+ 	    break;
+ 
+ 	 case WRITE_1:
+ 	    printf("   WRITE \n");
+ 	    break;
+ 
+ 	 case WRITELN_1:
+ 	    printf("   WRITELN \n");
+ 	    break;
+ 
+ 	 case IF_1:
+ 	    printf("   IF \n");
+ 	    break;
+ 
+ 	 case THEN_1:
+ 	    printf("   THEN \n");
+ 	    break;
+ 
+ 	 case ELSE_1:
+ 	    printf("   ELSE \n");
+ 	    break;
+ 
+ 	 case WHILE_1:
+ 	    printf("   WHILE \n");
+ 	    break;
+ 
+ 	 case DO_1:
+ 	    printf("   DO \n");
+ 	    break;
+ 
+ 	 case NOT_1:
+ 	    printf("   NOT \n");
+ 	    break;
+ 
+ 	 case ID_1:
+ 	    printf("   Identifier:  ");
+ 	    GETSTR();
+ 	    printf("%s\n",LEXEME);
+ 	    break;
+ 
+ 	 case LEFT_PAREN_1:
+ 	    printf("   LEFT PAREN '(' \n");
+ 	    break;
+ 
+ 	 case RIGHT_PAREN_1:
+ 	    printf("   RIGHT PAREN ')' \n");
+ 	    break;
+ 
+ 	 case LEFT_BRACKET_1:
+ 	    printf("   LEFT BRACKET ([) \n");
+ 	    break;
+ 
+ 	 case RIGHT_BRACKET_1:
+ 	    printf("   RIGHT BRACKET (]) \n");
+ 	    break;
+ 
+ 	 case COMMA_1:
+ 	    printf("   COMMA (,) \n");
+ 	    break;
+ 
+ 	 case SEMICOLON_1:
+ 	    printf("   SEMICOLON (;) \n");
+ 	    break;
+ 
+          default: 
+ 	    ERROR_CNT ++;
+ 	    printf("------------>ERROR: A Valid TOKEN Code is not the\n");
+ 	    printf("                    first item on the input line.");
+ 	    printf(" <--------\n");
+ 	    GETSTR();
+ 	  }
+       GETCHR();
+       if (CH != '\n' && EOF_FLAG) {
+ 	ERROR_CNT ++;
+ 	printf("------------>ERROR: Expected a Newline Character <--------\n");
+       }
+       FLUSH();
+     }
+     else EOF_FLAG = 0;
+   } /* end while (EOF_FLAG) */
+   printf("EOF\n");
+   if (ERROR_CNT)
+     printf("****** %d format errors found in output of your scanner.\n",
+ 	   ERROR_CNT);
+ }


Index: llvm-test/MultiSource/Benchmarks/Prolangs-C/fixoutput/scanner.h
diff -c /dev/null llvm-test/MultiSource/Benchmarks/Prolangs-C/fixoutput/scanner.h:1.1
*** /dev/null	Tue Oct  5 14:30:54 2004
--- llvm-test/MultiSource/Benchmarks/Prolangs-C/fixoutput/scanner.h	Tue Oct  5 14:30:43 2004
***************
*** 0 ****
--- 1,57 ----
+ 
+ /*         USEFUL MACRO DEFINITIONS    */
+ 
+ #define ERRORMSG_1               0
+ #define LINE_1                   1
+ #define ADDOP_1                  2
+ #define PLUS_1                   '+'
+ #define MINUS_1                  '-'
+ #define OR_1                     260
+ #define MULOP_1                  3
+ #define TIMES_1                  '*'
+ #define SLASH_1                  '/'
+ #define AND_1                    259
+ #define DIV_1                    261
+ #define RELOP_1                  4
+ #define EQUAL_1                  '='
+ #define NOTEQUAL_1               256
+ #define LESSTHANOREQUAL_1        257
+ #define LESSTHAN_1               '<'
+ #define GREATERTHANOREQUAL_1     258
+ #define GREATERTHAN_1            '>'
+ #define ASSIGN_1                 5
+ #define COLON_1                  6
+ #define DOTDOT_1                 7
+ #define DOT_1                    8
+ #define INTEGER_NUMBER_1         9
+ #define ILLEGAL_1                0
+ #define VALID_1                  1
+ #define REAL_NUMBER_1            10
+ #define PROGRAM_1                11
+ #define VAR_1                    12
+ #define INTEGER_1                13
+ #define REAL_1                   14
+ #define ARRAY_1                  15
+ #define OF_1                     16
+ #define FORWARD_1                17
+ #define PROCEDURE_1              18
+ #define FUNCTION_1               19
+ #define BEGIN_1                  20
+ #define END_1                    21
+ #define READ_1                   22
+ #define WRITE_1                  23
+ #define WRITELN_1                24
+ #define IF_1                     25
+ #define THEN_1                   26
+ #define ELSE_1                   27
+ #define WHILE_1                  28
+ #define DO_1                     29
+ #define NOT_1                    30
+ #define ID_1                     31
+ #define LEFT_PAREN_1             32
+ #define RIGHT_PAREN_1            33
+ #define LEFT_BRACKET_1           34
+ #define RIGHT_BRACKET_1          35
+ #define COMMA_1                  36
+ #define SEMICOLON_1              37
+ 


Index: llvm-test/MultiSource/Benchmarks/Prolangs-C/fixoutput/stringI.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/Prolangs-C/fixoutput/stringI.c:1.1
*** /dev/null	Tue Oct  5 14:30:54 2004
--- llvm-test/MultiSource/Benchmarks/Prolangs-C/fixoutput/stringI.c	Tue Oct  5 14:30:43 2004
***************
*** 0 ****
--- 1,79 ----
+ /* To compile use:
+ cc stringI.c lex.o -lm
+ */
+ 
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include "scanner.h"  /* Useful Macro Definitions */
+ 
+ #define LEX_LEN_INCR          256
+ #define PERROR_1                 0
+ 
+ char CH;                         /* Current input Character */
+ char *LEXEME;                    /* Input String */
+ 
+ char *FRONT,*BACK;               /* FRONT and BACK characters of Input String*/
+ unsigned LEX_LEN = 0;            /* Size of the Input String Buffer */
+ 
+ /* FORWORD function definitions */
+ /* extern char *calloc();       */
+  
+ void FLUSH(void)
+ /* Clear input string (LEXEME), reset buffer to correct size, and reset
+    pointers */
+ {
+ /* reset buffer to correst size if necessary */
+   if (LEX_LEN > LEX_LEN_INCR)
+     {
+       cfree(LEXEME);
+       LEX_LEN = LEX_LEN_INCR;
+       LEXEME = calloc(LEX_LEN,sizeof(CH));
+     }
+ /* Clear input string */
+   *LEXEME = 0;
+ /* reset pointers */
+   BACK = LEXEME;
+   FRONT = BACK - 1;
+ }
+ 
+ void GETCHR(void)
+ /* gets the next character form input file and expands buffer if needed */
+ {
+   char *TEMP;
+   int I;
+ 
+ /* expand buffer if needed */
+   if (FRONT-BACK >= LEX_LEN-3)
+     {
+       LEX_LEN = LEX_LEN + LEX_LEN_INCR;
+       TEMP = calloc(LEX_LEN,sizeof(CH));
+       for (I = 0; I < LEX_LEN - LEX_LEN_INCR; I ++)
+ 	TEMP[I] = LEXEME[I];
+     }
+   
+ /* get next character */
+   CH = getc(stdin);
+ /* update input string appropriately */
+   FRONT ++;
+   *FRONT = CH;
+   *(FRONT+1) = 0;
+ }
+ 
+ void BACKUP(void)
+ /* backups input string to last character of input and writes current 
+    character back on input file */
+ {
+   if (FRONT < BACK)
+     (void) printf(
+ 	  "%D SCANNER ERROR: Tried to BACKUP past beginning of a Token\n",
+ 	   PERROR_1);
+   else
+     {
+ /* put current char back on input file */
+       (void) ungetc(CH,stdin);
+ /* backup input string one character */
+       *FRONT = 0;
+       FRONT --;
+       CH = *FRONT;
+     }
+ }






More information about the llvm-commits mailing list