Stefano, You should recognize the entire comment in one lexical pass, and should NOT return the '#' token. In other words, treat the '#' begun comment as whitespace - do the same for it that you do for whitespace. Write a regular expression for single-line comments that matches everything to the end of the line (\n char).
Kelly ----- Original Message ---- From: Stefano Simonucci <[EMAIL PROTECTED]> To: help-bison@gnu.org Sent: Tuesday, May 8, 2007 11:30:08 AM Subject: Language with comments Hi! I try to make a syntactic recognizer. In the language can be included also comments of the type " # <comment> ". I have made two files: prova.lex and prova.y for flex and bison. A comment consists of a list (also empty) of identifier. But I get always syntax errors. We enclose the files prova.lex, prova.y, a file for the compilation (compila) and an input file (prova.E) Thank you. Stefano -- Stefano Simonucci GNU/Linux User: #81790 http://counter.li.org %{ #include <string.h> %} delim [ \t\n] ws {delim}+ letter [A-Za-z] digit [0-9] id {letter}({letter}|{digit})* num {digit}+|{digit}+\.{digit}*|{digit}+\.{digit}*{digit}*e\-{digit}+ %% {ws} { printf("\n"); return '\n'; } {id} { strcpy(yylval.lexeme, yytext); printf("%s ",yytext); return ID; } {num} { strcpy(yylval.lexeme, yytext); return NUM; } "+" return '+'; "-" return '-'; "*" return '*'; "/" return '/'; "(" return '('; ")" return ')'; "," return ','; "=" return '='; "#" { printf("#"); return '#'; } %{ #include <stdio.h> %} %union { char lexeme[100+1]; } %token <lexeme> ID %token <lexeme> NUM %left '+' '-' %left '*' '/' %right UNIMINUS UNIPLUS '#' %start init %type <lexeme> term %% init : /* empty */ | init line ; line : '\n' | '#' comment '\n' ; comment : /* empty line */ | comment term term : ID {sprintf($$,"%s",$1); } | NUM {sprintf($$,"%s",$1); } ; %% #include "lex.yy.c" int main() { return yyparse(); } reticolo=set(vecX,vecY); typefunction fespace(reticolo Q) { double A(Q.Nx,Q.Ny); symbol R=Q; } reticolo Q; VQ=fespace(Q); _______________________________________________ help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison _______________________________________________ help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison