fart/parser/parser.yy
Josh Holtrop 1fe251f27d added -lfl to LDFLAGS in main Makefile, added parser/parser.{lex,yy} and parser/Makefile (for real this time)
git-svn-id: svn://anubis/fart/trunk@79 7f9b0f55-74a9-4bce-be96-3c2cd072584d
2009-02-04 18:45:55 +00:00

77 lines
982 B
Plaintext

%{
#include <stdio.h>
#include <iostream>
using namespace std;
extern "C" {
int yylex(void);
}
extern FILE * yyin;
void yyerror(const char * str)
{
fprintf(stderr, "error: %s\n", str);
}
int yywrap()
{
return 1;
}
%}
%token PLUS;
%token MINUS;
%token STAR;
%token DIVIDE;
%token MOD;
%token SEMICOLON;
%token COLON;
%token QUESTION;
%token DOLLAR;
%token DOT;
%token DQUOTE;
%token SQUOTE;
%token COMMA;
%token LCURLY;
%token RCURLY;
%token LBRACKET;
%token RBRACKET;
%token LPAREN;
%token RPAREN;
%token BIN_NUMBER;
%token HEX_NUMBER;
%token OCT_NUMBER;
%token DEC_NUMBER;
%%
program: /* empty */
| number program { printf("Saw a number\n"); }
;
number: BIN_NUMBER
| OCT_NUMBER
| DEC_NUMBER
| HEX_NUMBER
;
%%
int parse(const char * fileName)
{
yyin = fopen(fileName, "r");
if (yyin == NULL)
{
cerr << "Failed to open file '" << fileName << "'" << endl;
return -1;
}
yyparse();
}