source: git/factory/readcf.yy @ b7d64b

spielwiese
Last change on this file since b7d64b was ee668e, checked in by Jan Engelhardt <jengelh@…>, 12 years ago
factory/build: restore out-of-tree build support When attempting an OOT build, it fails to find <factory/cplusplus.h>, because cplusplus.h is always (even in in-tree builds) produced in "${builddir}", and not "${top_srcdir}/../factory". Furthermore, one must not rely on the basename of ${top_srcdir}, and going above ${top_srcdir} is undefined and may lead to spurious build failures. (Consider a hypothetical chroot on ${top_srcdir}). Therefore, create a directory include/factory and use -Iinclude such that <factory/*> yields a buildable state, move all exported header files there. Previous OOT build log: 17:22 seven:../factory/obj > make CXX cplusplus.o CXXLD cplusplus ./cplusplus > ./cplusplus.h ../bin/makeheader ../factory.template factory.h ../bin/makeheader ../factoryconf.template factoryconf.h YACC readcf.cc make all-am make[1]: Entering directory `/home/jengelh/obs/zu/home/jengelh/science/singsource/factory/obj' CXX libfactory_a-algext.o CXX libfactory_a-canonicalform.o In file included from ../cf_factory.h:12:0, from ../canonicalform.cc:7: ../../factory/cf_gmp.h:14:33: fatal error: factory/cplusplus.h: Ingen slik fil eller filkatalog compilation terminated. make[1]: *** [libfactory_a-canonicalform.o] Error 1 make[1]: Leaving directory `/home/jengelh/obs/zu/home/jengelh/science/singsource/factory/obj' make: *** [all] Error 2
  • Property mode set to 100644
File size: 4.5 KB
RevLine 
[ba1fde]1/* emacs edit mode for this file is -*- C++ -*- */
[341696]2/* $Id$ */
[ba1fde]3
4%{
[311803]5
6#include "config.h"
[ee668e]7#include <factory/factoryconf.h>
[311803]8
[049c4f]9#if defined(WINNT) && ! defined(__GNUC__)
[311803]10# include <malloc.h>
11# include <memory.h>
12# define alloca _alloca
[9c9e2a4]13#endif
14
[16466a]15#include <cstring> // we need this for gcc 4.3
[d8d9e9]16#include <config.h>
17
[ba1fde]18#include <ctype.h>
[311803]19
[1dc616]20#ifdef HAVE_IOSTREAM
[311803]21# include <iostream>
22# define ISTREAM std::istream
23# define CERR std::cerr
[1dc616]24#elif defined(HAVE_IOSTREAM_H)
[311803]25# include <iostream.h>
26# define ISTREAM istream
27# define CERR cerr
[1dc616]28#endif
29
[ba1fde]30
[650f2d8]31#include "cf_assert.h"
[d8d9e9]32
[a472b9]33#include "canonicalform.h"
[ba1fde]34#include "cf_defs.h"
[a1b6b0f]35#include "gfops.h"
[ba1fde]36#include "parseutil.h"
37#include "variable.h"
38
39#ifndef BISONPP
[311803]40# define YYSTYPE ParseUtil
[ba1fde]41#else
[311803]42# define YY_parse_USE_GOTO 1
43# define YY_parse_STYPE ParseUtil
[ba1fde]44#endif
45
[181148]46static char* readString( ISTREAM& );
[ba1fde]47
48#ifndef BISONPP
49void yyerror( char * s );
50int yylex();
51#endif
52
[181148]53static ISTREAM * defaultin = 0;
[ba1fde]54
55static CanonicalForm * retvalue = 0;
56
57%}
58
59/* BISON Declarations */
60
61%token NUM
62%left '-' '+'
63%left '*' '/'
64%left NEG
65%right '^'
66
67/* Grammar follows */
68
69%%
[806c18]70input:        /* empty string */
71        | input line
[ba1fde]72;
73
[806c18]74line:        ';'
75        | exp ';' { *retvalue = $1.getval(); return 0; }
[ba1fde]76;
77
[806c18]78exp:        NUM                        { $$ = $1; }
79        | exp '+' exp                { $$ = $1.getval() + $3.getval(); }
80        | exp '-' exp                { $$ = $1.getval() - $3.getval(); }
81        | exp '*' exp                { $$ = $1.getval() * $3.getval(); }
82        | exp '/' exp                { $$ = $1.getval() / $3.getval(); }
83        | '-' exp %prec NEG        { $$ = -$2.getval(); }
84        | '+' exp %prec NEG        { $$ = $2.getval(); }
85        | exp '^' NUM                { $$ = power( $1.getval(), $3.getintval() ); }
86        | '(' exp ')'                { $$ = $2.getval(); }
[ba1fde]87;
88
89%%
90
91#ifdef BISONPP
92void YY_parse_CLASS::yyerror( char * s )
93#else
94void yyerror( char * s )
95#endif
96{
[181148]97    CERR << s << "\n";
[ba1fde]98}
99
100#ifdef BISONPP
101int YY_parse_CLASS::yylex()
102#else
103int yylex()
104#endif
105{
106    int c;
107
108    while ((c = defaultin->get()) == ' ' || c == '\t' || c == '\n' ) ;
109    if ( isdigit( c ) ) {
[806c18]110        defaultin->putback( c );
111        yylval = ParseUtil( readString( *defaultin ) );
112        return NUM;
[ba1fde]113    }
114    else if ( isalpha( c ) ) {
[806c18]115        // look for generators of GF(q)
116        if ( getCharacteristic() > 0 && getGFDegree() > 1 && c == gf_name ) {
[a1b6b0f]117#ifdef BISONPP
[806c18]118            this->yylval = getGFGenerator();
[a1b6b0f]119#else
[806c18]120            yylval = getGFGenerator();
[a1b6b0f]121#endif
[806c18]122        }
123        else if ( c == getDefaultVarName() ) {
124            int cc;
125            cc = defaultin->get();
126            if ( cc == '_' ) {
127                ParseUtil index( readString( *defaultin ) );
[ba1fde]128#ifdef BISONPP
[806c18]129                this->yylval = Variable( index.getintval() );
[ba1fde]130#else
[806c18]131                yylval = Variable( index.getintval() );
[ba1fde]132#endif
[806c18]133            }
134            else {
135                defaultin->putback( cc );
[ba1fde]136#ifdef BISONPP
[806c18]137                this->yylval = Variable( (char)c );
[ba1fde]138#else
[806c18]139                yylval = Variable( (char)c );
[ba1fde]140#endif
[806c18]141            }
142        }
143        else {
[ba1fde]144#ifdef BISONPP
[806c18]145            this->yylval = Variable( (char)c );
[ba1fde]146#else
[806c18]147            yylval = Variable( (char)c );
[ba1fde]148#endif
[806c18]149        }
150        return NUM;
[ba1fde]151    }
152    return c;
153}
154
[181148]155CanonicalForm readCF( ISTREAM& str )
[ba1fde]156{
157    CanonicalForm theRetvalue;
158    retvalue = new CanonicalForm();
159#ifdef BISONPP
160    YY_parse_CLASS my_parser;
161    defaultin = &str;
162    if ( my_parser.yyparse() == 0 ) {
[806c18]163        theRetvalue = *retvalue;
164        delete retvalue;
165        return theRetvalue;
[ba1fde]166    }
167    else {
[806c18]168        delete retvalue;
169        return 0;
[ba1fde]170    }
171#else
172    defaultin = &str;
173    if ( yyparse() == 0 ) {
[806c18]174        theRetvalue = *retvalue;
175        delete retvalue;
176        return theRetvalue;
[ba1fde]177    }
178    else {
[806c18]179        delete retvalue;
180        return 0;
[ba1fde]181    }
182#endif
183}
184
[181148]185char* readString( ISTREAM& s )
[ba1fde]186{
187    static char * buffer = 0;
188    static int bufsize = 0;
189
190    if ( buffer == 0 ) {
[806c18]191        bufsize = 10000;
192        buffer = new char[bufsize];
[ba1fde]193    }
194    int i = 0, c, goon = 1;
195    while ( goon ) {
[806c18]196        while ( isdigit( c = s.get() ) && i < bufsize - 2 ) {
197            buffer[i] = c;
198            i++;
199        }
200        if ( isdigit( c ) ) {
201            bufsize += 1000;
202            char * newbuffer = (char*)memcpy( new char[bufsize], buffer, bufsize - 1000 );
203            delete [] buffer;
204            buffer = newbuffer;
205            buffer[i] = c;
206            i++;
207        }
208        else {
209            goon = 0;
210            buffer[i] = '\0';
211            s.putback( c );
212        }
[ba1fde]213    }
214    return buffer;
215}
[e4fe2b]216
Note: See TracBrowser for help on using the repository browser.