{\rtf1\ansi\ansicpg1252\cocoartf1187\cocoasubrtf390 {\fonttbl\f0\fmodern\fcharset0 Courier;} {\colortbl;\red255\green255\blue255;} \margl1440\margr1440\vieww10800\viewh8400\viewkind0 \deftab720 \pard\pardeftab720 \f0\fs26 \cf0 /* DJ PARSER */\ \ %\{\ #include \ #include "lex.yy.c"\ \ void yyerror(const char *str) \{\ printf("Syntax error on line %d at token %s\\n",yylineno,yytext);\ printf("(This version of the compiler exits after finding the first ");\ printf("syntax error.)\\n");\ exit(-1);\ \}\ %\}\ \ %token MAIN CLASS EXTENDS NATTYPE IF ELSE WHILE\ %token PRINTNAT READNAT THIS NEW NUL NATLITERAL \ %token ID ASSIGN PLUS MINUS TIMES EQUALITY GREATER \ %token AND NOT DOT SEMICOLON COMMA LBRACE RBRACE \ %token LPAREN RPAREN ENDOFFILE\ \ %start pgm\ \ %right ASSIGN\ \ %%\ \ pgm : ENDOFFILE \ \{ return 0; \}\ ;\ \ %%\ \ int main(int argc, char **argv) \{\ if(argc!=2) \{\ printf("Usage: dj-parse filename\\n");\ exit(-1);\ \}\ yyin = fopen(argv[1],"r");\ if(yyin==NULL) \{\ printf("ERROR: could not open file %s\\n",argv[1]);\ exit(-1);\ \}\ /* parse the input program */\ return yyparse();\ \}\ }