I have to create a lexical and syntax analyzer for a c-like language. In this language we define as comment "everything that exists after the symbol % until the end of line". Are the following declarations correct?
Flex
...
[%][^
]*[
] { return T_COMMENT; }
[
] { return T_NEWLINE; }
Bison
...
comment:com text newline;
text: |name text|digit text;
...
com: T_COMMENT { printf("%s",yytext); };
newline: T_NEWLINE { printf("%s",yytext); };
I also need to define the quote symbol ". Is the following correct (flex)?
""" { return T_QUOTE; }
There is no compile error in the flex and bison input files but when I use a program written in this c-like language as a test input I get as a result lexical error in line 1. There is no lexical error in this line. My program has to start with like this: PROGRAM name_of_program and a compalsory new line I make the following declarations: Flex
"PROGRAM" { return T_PROGRAM; }
Bison
%start programma
%token T_PROGRAM
...
programma:PROGRAM name newline function STARTMAIN dec_var command ENDMAIN eof;
...
PROGRAM: T_PROGRAM { printf("%s",yytext); };
...
(words in upper case are defined like PROGRAM as they are part of the language) Do I write anything wrong? I think that the problem is with newline definition but I am not sure.
Thank you in advance for any answer. Sorry for the long post.