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(); }
compila
Description: application/shellscript
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