-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Philip Herron wrote: > j...@garveydesign.com wrote: >> The processes proceed well until the compiler generated >> encounters an opening bracket. I get the following output... > >> This is the cln file Aug 2 2009 [sudo] password for joe: removing >> lex.yy.c rm: cannot remove `lex.yy.c': No such file or directory >> removing lex.yy.o rm: cannot remove `lex.yy.o': No such file or >> directory removing parse.tab.h removing parse.tab.c removing >> parse.tab.o ---> calling bison_program ---> calling flex_program >> lex.l:75: negative range in character class ---> compiling lexer >> gcc: lex.yy.c: No such file or directory gcc: no input files ---> >> compiling parser parse.tab.c: In function yyparse: >> parse.tab.c:1391: warning: implicit declaration of function >> yylex ---> linking gcc: lex.yy.o: No such file or directory > >> V.1 started > > >> project Compiler (c) 2009 > > >> Initialising symbol table > > >> Calling yyparse(), there should be debug outputs > >> domain line is D0 11 0 10 domain line is D1 10 11 20 ln 97. >> Constant line is X0 D0 1 ln 97. Constant line is X1 D1 12 ln 97. >> Constant line is X2 D0 2 ln 97. Constant line is X3 D1 15 ln 97. >> Constant line is X4 D0 6 ln 97. Constant line is X5 D1 20 In lex >> 40, found an OR syntax error > >> Completed yyparse() > >> ---------------------------------------- After 'Calling >> yyparse()...' the compiler reads infile.i and simply confirms >> the parsing of the domains and constants. Things get mysterious >> after 'In lex 40, found an OR'. This simply confirms that the >> first token of the predicates following the above domains and >> constants has started. But then as you see above, the program >> stalls with a 'syntax error'. > >> At this point the next token in the input.i stream is and opening >> bracket. But it doesn't seem to get read. There is provision >> for the brackets in parse.y as... %token '(' ')' /* left > parenthesis, >> r parenthesis @ line 59*/ and in lex.l as... "(" > {printf("found a >> (\n");return '(';} /*line 48 */... but it never gets to this in >> lex.l There is a line of code at lex.l 75 which may or may not be >> causing a problem... [^a-ca-ce-ze-...@~\n] { /* error, > unexpected >> char */.... it's an intended exclusion list. > >> I have included all the relevant files associated with this small >> project, and if you copy them into a directory, then calling >> ./compile should cause execution of the shell scripts to build >> and execute the eventual compiler which is generated. > >> The list of files attached are... lex.l THE SOURCE FOR THE LEXER >> parse.y THE SOURCE FOR THE PARSER symtable.h THE SYMBOL TABLE >> header file. infile.i THE SOURCE FILE TO FEED TO OUR GENERATED >> COMPILER IT COMPRISES 2 DOMAIN LINES, 6 CONSTANTS LINES followed >> by a LIST OF PREDICATES. cln WHICH CLEANS OFF THE OLD OBJECT >> FILES ETC READY FOR A NEW COMPILATION. compile WHICH PROCESSES >> THE FLEX AND BISON SOURCES THEN LINKS, AND EXECUTES. > >> Once the files are into a separate directory, then simply >> entering 'compile' will attempt to build and execute the >> consequent files generated. You should get output same as down to >> the -------------------- separator. > >> Any help is appreciated, thanks. Joe Garvey, Cork, Ireland > >> ---------------------------------------------------------------------- >> > > >> _______________________________________________ >> help-bison@gnu.org >> http://lists.gnu.org/mailman/listinfo/help-bison > > Hi > > Ah i see your from ireland so am I :-) . > > Anyways yeah looking at your lexer it wouldn't generate for me but > i just changed that line 75 instead of hard-coding a token that > will cause a syntax fail just stuck '.' in. > > Anyways your problem is probably with your parser, i am not quite > sure what this language is or is meant to be. > > Is the structure having to be Domain (what ever you mean by that), > constants and predicates. > > So anyways the problem is your exp: rule, you have exp can be of > the form: > > ( expression ) or MAX ( number, number ) .... > > What you have your .i file is > > 'or(lt(mul(X0,X1),X2),ge(abs(sub(X3,X4)),X5))' > > So that is an > > OR ( exp ) > > The way i would do this would be something like splitting it up > alot, > > OPERATION: OR | LE | EQ ... ; > > predicate: OPERATION '( ' expr ')' > > //wait do these accept numbers or does it have to be an X0 or D0 in > that cause your going to want to make sure you have a hash table > to lookup to make sure they are defined symbols before running on > null pointers anyways.. > > param: NUM ',' NUM | DOMAIN ',' DOMAIN | expr ',' expr ... ; > > expr: OPERATION '(' param ')' | OPERATION '(' expr ')' > > hmm... something like that i am not sure if that will work properly > but give it ago maby gives you something to think about :) > > Also you might want to check out automake to generate yourself a > makefile instead of a compile script. > > To make an automake for your project would be > > Makefile.am: > > bin_PROGRAMS = parser parser_SOURCES = parse.y lex.l bla.c .... > > done :) > > Hope this helps > > --Phil http://redbrain.co.uk
Just looking at it again this would work better: OPERATION: OR | LE | EQ ... ; predicate: OPERATION '(' param ')' ; param: NUM ',' NUM | DOMAIN ',' DOMAIN | predicate ',' predicate ... all the mixes i guess ; That might work a little nicer, i hope it is seen as a terminated rule but give it ago :) -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkp/rjwACgkQAhcOgIaQQ2FlBwCfajYl0pTeBfSsTTtD5RsGDOFR Su4AnRgw0EcyIWHSlzCzfagToiyxjsmq =TexD -----END PGP SIGNATURE----- _______________________________________________ help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison