66 lines
776 B
Plaintext
66 lines
776 B
Plaintext
|
|
%{
|
|
#include <stdio.h>
|
|
|
|
extern FILE * yyin;
|
|
|
|
void yyerror(const char * str)
|
|
{
|
|
fprintf(stderr, "error: %s\n", str);
|
|
}
|
|
|
|
int yywrap()
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
int main(int argc, char * argv[])
|
|
{
|
|
if (argc > 0)
|
|
{
|
|
yyin = fopen(argv[1], "r");
|
|
}
|
|
yyparse();
|
|
}
|
|
|
|
%}
|
|
|
|
%token ASSIGN;
|
|
%token EQUAL;
|
|
%token LEQ;
|
|
%token GEQ;
|
|
|
|
%token LSHIFT;
|
|
%token RSHIFT;
|
|
|
|
%token INCREMENT;
|
|
%token DECREMENT;
|
|
|
|
%token PLUS;
|
|
%token MINUS;
|
|
%token TIMES;
|
|
%token DIVIDE;
|
|
|
|
%token BIN_NUMBER;
|
|
%token HEX_NUMBER;
|
|
%token OCT_NUMBER;
|
|
%token DEC_NUMBER;
|
|
|
|
%token RETURN;
|
|
|
|
%token ID;
|
|
|
|
%%
|
|
|
|
program: /* empty */
|
|
| number program { printf("Saw a number\n"); }
|
|
|
|
number: BIN_NUMBER
|
|
| OCT_NUMBER
|
|
| DEC_NUMBER
|
|
| HEX_NUMBER
|
|
{
|
|
printf("Saw a number\n");
|
|
}
|
|
;
|