Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/tools/build/jam_src/parse.c @ 12

Last change on this file since 12 was 12, checked in by landauf, 17 years ago

added boost

File size: 2.5 KB
Line 
1/*
2 * Copyright 1993, 2000 Christopher Seiwald.
3 *
4 * This file is part of Jam - see jam.c for Copyright information.
5 */
6
7/*  This file is ALSO:
8 *  Copyright 2001-2004 David Abrahams.
9 *  Distributed under the Boost Software License, Version 1.0.
10 *  (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
11 */
12
13# include "jam.h"
14# include "lists.h"
15# include "parse.h"
16# include "scan.h"
17# include "newstr.h"
18# include "modules.h"
19# include "frames.h"
20
21/*
22 * parse.c - make and destroy parse trees as driven by the parser
23 *
24 * 09/07/00 (seiwald) - ref count on PARSE to avoid freeing when used,
25 *              as per Matt Armstrong.
26 * 09/11/00 (seiwald) - structure reworked to reflect that (*func)()
27 *              returns a LIST *.
28 */
29
30static PARSE *yypsave;
31
32void
33parse_file( char *f, FRAME* frame )
34{
35        /* Suspend scan of current file */
36        /* and push this new file in the stream */
37
38        yyfparse(f);
39
40        /* Now parse each block of rules and execute it. */
41        /* Execute it outside of the parser so that recursive */
42        /* calls to yyrun() work (no recursive yyparse's). */
43
44        for(;;)
45        {
46            PARSE *p;
47
48            /* Filled by yyparse() calling parse_save() */
49
50            yypsave = 0;
51
52            /* If parse error or empty parse, outta here */
53
54            if( yyparse() || !( p = yypsave ) )
55                break;
56
57            /* Run the parse tree. */
58
59            parse_evaluate( p, frame );
60            parse_free( p );
61        }
62}
63
64void
65parse_save( PARSE *p )
66{
67        yypsave = p;
68}
69
70PARSE *
71parse_make( 
72        LIST    *(*func)( PARSE *p, FRAME *args ),
73        PARSE   *left,
74        PARSE   *right,
75        PARSE   *third,
76        char    *string,
77        char    *string1,
78        int     num )
79{
80        PARSE   *p = (PARSE *)malloc( sizeof( PARSE ) );
81
82        p->func = func;
83        p->left = left;
84        p->right = right;
85        p->third = third;
86        p->string = string;
87        p->string1 = string1;
88        p->num = num;
89        p->refs = 1;
90        p->rulename = 0;
91       
92        if ( left )
93        {
94            p->file = left->file;
95            p->line = left->line;
96        }
97        else
98        {
99            yyinput_stream( &p->file, &p->line );
100        }
101
102        return p;
103}
104
105void
106parse_refer( PARSE *p )
107{
108        ++p->refs;
109}
110
111void
112parse_free( PARSE *p )
113{
114        if( --p->refs )
115            return;
116
117        if( p->string )
118            freestr( p->string );
119        if( p->string1 )
120            freestr( p->string1 );
121        if( p->left )
122            parse_free( p->left );
123        if( p->right )
124            parse_free( p->right );
125        if( p->third )
126            parse_free( p->third );
127        if ( p->rulename )
128            freestr( p->rulename );
129       
130        free( (char *)p );
131}
132
133LIST* parse_evaluate( PARSE *p, FRAME* frame )
134{
135    frame->procedure = p;
136    return (*p->func)(p, frame);
137}
Note: See TracBrowser for help on using the repository browser.