CommonEnviromentParser.y

Go to the documentation of this file.
00001 /* $Id: CommonEnviromentParser.y,v 1.2 2001/04/05 08:27:10 pfb Exp $ */
00002 
00007 %{
00008 #include <stdio.h>
00009 #define YYDEBUG 1
00010   int yydebug = 0;
00011 
00012   int Java_Common_Enviroment_CommonEnviromentParser_lex();
00013   int Java_Common_Enviroment_CommonEnviromentParser_error(const char *s);
00014   extern void pusha(const char *lvalue, const char *rvalue);
00015   extern void pushn(const char *lvalue, double);
00016 
00017   int in_comment = 0;
00018 %}
00019 
00020 %union {
00021   double val;
00022   char   tstr[128];
00023 }
00024 
00025 %token LBRACE RBRACE
00026 %token EQUALS
00027 %token POUND
00028 %token EOS          /* Terminates a statement */
00029 %token EOL          /* End of line */
00030 %token LEXERROR     /* an error in yylex() */
00031 %token <tstr> ALPHA
00032 %token <val>  NUM
00033 
00034 %%
00035 
00036 file          :  /* empty */
00037               | file statement
00038               | file comment
00039               ;
00040 
00041 statement     : lvalue EQUALS ALPHA EOS
00042                 {
00043                 strcpy($<tstr>$, $<tstr>3);
00044                 pusha($<tstr>1, $<tstr>3);
00045                 }
00046               | lvalue EQUALS NUM EOS  
00047                 {
00048                 $<val>$ = $<val>3;
00049                 pushn($<tstr>1, $<val>3);
00050                 }
00051               ;
00052 
00053 comment       : POUND
00054                 {
00055                 in_comment = 1;
00056                 }
00057                 EOL
00058                 {
00059                 in_comment = 0;
00060                 }
00061               ;  
00062 
00063 lvalue        : ALPHA
00064                 {
00065                 strcpy($<tstr>$, $<tstr>1);
00066                 }
00067               ;
00068 
00069 %%
00070 
00071 #include <ctype.h>
00072 #include <stdio.h>
00073 
00074 FILE *Java_Common_Enviroment_CommonEnviromentParser_input;
00075 
00076 int Java_Common_Enviroment_CommonEnviromentParser_lex()
00077   {
00078   int c;
00079 
00080   if (in_comment == 0)
00081     {
00082     /* skip white space  */
00083     while ((c = getc(Java_Common_Enviroment_CommonEnviromentParser_input)) == ' ' ||
00084             c == '\t' ||
00085             c == '\n')
00086       ;
00087 
00088     /* return end-of-file  */
00089     if (c == EOF)                            
00090       return 0;
00091 
00092     if (c == '{')
00093       return LBRACE;
00094     if (c == '}')
00095       return RBRACE;
00096     if (c == '=')
00097       return EQUALS;
00098     if (c == ';')
00099       return EOS;
00100     if (c == '#')
00101       return POUND;
00102 
00103     /* process numbers   */
00104     if (isdigit(c))                
00105       {
00106         ungetc(c, Java_Common_Enviroment_CommonEnviromentParser_input);
00107         fscanf(Java_Common_Enviroment_CommonEnviromentParser_input,
00108                "%lf",
00109                &yylval.val);
00110         return NUM;
00111       }
00112   
00113     /* process names */
00114     if (isgraph(c))
00115       {
00116       ungetc(c, Java_Common_Enviroment_CommonEnviromentParser_input);
00117       fscanf(Java_Common_Enviroment_CommonEnviromentParser_input,
00118              "%[^; \t]s",
00119              yylval.tstr);
00120       return ALPHA;
00121       }
00122 
00123     /* return an error */
00124     return LEXERROR;
00125     }
00126   else
00127     {
00128     while((c = getc(Java_Common_Enviroment_CommonEnviromentParser_input)) != '\n')
00129       ;
00130     return EOL;
00131     }
00132   }
00133 
00134 int Java_Common_Enviroment_CommonEnviromentParser_error(const char *s)
00135   {
00136   printf("%s: %s\n", __FILE__, s);
00137   return 1;
00138   }
00139 
00140 /*
00141  * $Log: CommonEnviromentParser.y,v $
00142  * Revision 1.2  2001/04/05 08:27:10  pfb
00143  * Turned off yydebug.
00144  *
00145  * Revision 1.1  2001/04/05 08:22:57  pfb
00146  * Initial rev.
00147  *
00148  *
00149  */