fart/parser/parser.yy
Josh Holtrop ba7190d7d8 working on parser
git-svn-id: svn://anubis/fart/trunk@84 7f9b0f55-74a9-4bce-be96-3c2cd072584d
2009-02-08 19:42:55 +00:00

80 lines
992 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 LESS;
%token GREATER;
%token DEC_NUMBER;
%token REAL_NUMBER;
%token CAMERA;
%token COLOR;
%token POSITION;
%token SCENE;
%%
scene: /* empty */
| scene_spec { printf("Saw a number\n"); }
;
number: DEC_NUMBER
| REAL_NUMBER
;
%%
int parse(const char * fileName)
{
yyin = fopen(fileName, "r");
if (yyin == NULL)
{
cerr << "Failed to open file '" << fileName << "'" << endl;
return -1;
}
yyparse();
}