00001
00002
00007 %{
00008
00009 int Java_Common_Parser_FileParser_lex();
00010
00011 %}
00012
00013 %union {
00014 double val;
00015 char tstr[128];
00016 }
00017
00018 %token LBRACE RBRACE
00019 %token EQUALS
00020 %token <tstr> ALPHA
00021 %token <val> NUM
00022
00023
00024
00025 %%
00026
00027 file :
00028 | blocks
00029 ;
00030
00031 blocks : LBRACE blocks RBRACE
00032 | LBRACE statements RBRACE
00033 ;
00034
00035 statements : lvalue EQUALS rvalue
00036 ;
00037
00038 lvalue : ALPHA
00039 {
00040 printf("lvalue = %s\n", $<tstr>1);
00041 }
00042 ;
00043
00044 rvalue : ALPHA
00045 {
00046 printf("rvalue = %s\n", $<tstr>1);
00047 }
00048 | NUM
00049 {
00050 printf("rvalue = %f\n", $<val>1);
00051 }
00052 ;
00053
00054 %%
00055
00056 #include <ctype.h>
00057 #include <stdio.h>
00058
00059 FILE *Java_Common_Parser_FileParser_input;
00060
00061 int Java_Common_Parser_FileParser_lex()
00062 {
00063 int c;
00064
00065
00066 while ((c = getc(Java_Common_Parser_FileParser_input)) == ' ' ||
00067 c == '\t' ||
00068 c == '\n')
00069 ;
00070
00071 if (c == '{')
00072 return LBRACE;
00073 if (c == '}')
00074 return RBRACE;
00075 if (c == '=')
00076 return EQUALS;
00077
00078
00079 if (isdigit(c))
00080 {
00081 ungetc(c, Java_Common_Parser_FileParser_input);
00082 fscanf(Java_Common_Parser_FileParser_input, "%lf", &yylval.val);
00083 return NUM;
00084 }
00085
00086
00087 if (isalpha(c))
00088 {
00089 ungetc(c, Java_Common_Parser_FileParser_input);
00090 fscanf(Java_Common_Parser_FileParser_input, "%s", &yylval.tstr);
00091 return ALPHA;
00092 }
00093
00094
00095 if (c == EOF)
00096 return 0;
00097
00098 return c;
00099 }
00100
00101 int Java_Common_Parser_FileParser_error(const char *s)
00102 {
00103 printf("%s: %s\n", __FILE__, s);
00104 return 1;
00105 }
00106
00107
00108
00109
00110
00111
00112
00113