I am trying to make a simple parser that recognizes three keywords and a 
newline. 

The lexer is as follows
%{
#include <stdio.h>
#include "asm.tab.h"
%}

%%
NOP|SLEEP|RETURN {return TWO;}
%%

The parser
%{
#include <stdio.h>
#include <stdlib.h>
unsigned int PCL=0;
%}
%token TWO NEWLINE
%%
statement: TWO '\n' {PCL++;printf("Identified a line");};
%%
extern FILE *yyin;
int main(int argc, char** argv){
  int ret;
  if(argc>1){
    FILE *file;
    file=fopen(argv[1], "r");
    yyin = file;
  }
  do {
    ret = yyparse();
    printf("Number of Lines %d\t%d\n", PCL, ret);
  } while(!feof(yyin));
  return 0;
}

int yyerror(char *s) {
  fprintf(stderr, "%s\n", s);
  return 0;
}

This doesn't work with a simple file like this -
NOP
SLEEP
RETURN

The error it gives is Parse Error. The value for ret is 1 (err).

Help!
Regards
Sukrit




-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
_______________________________________________
linux-india-help mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/linux-india-help

Reply via email to