~ubuntu-branches/ubuntu/hoary/malaga/hoary

« back to all changes in this revision

Viewing changes to source/value_parser.c

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Bushnell, BSG
  • Date: 2004-08-20 12:58:50 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040820125850-rx9s8bn0ep8jgist
Tags: 6.13-4
This should have been urgency=high, because it is an important and
long-delayed accomodation to new upstream with a bajillion bug fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* This file is part of Malaga, a system for Natural Language Analysis.
2
 
 * Copyright (C) 1995-1999 Bjoern Beutel
3
 
 *
4
 
 * Bjoern Beutel
5
 
 * Universitaet Erlangen-Nuernberg
6
 
 * Abteilung fuer Computerlinguistik
7
 
 * Bismarckstrasse 12
8
 
 * D-91054 Erlangen
9
 
 * e-mail: malaga@linguistik.uni-erlangen.de 
10
 
 *
11
 
 * This program is free software; you can redistribute it and/or modify
12
 
 * it under the terms of the GNU General Public License as published by
13
 
 * the Free Software Foundation; either version 2 of the License, or
14
 
 * (at your option) any later version.
15
 
 *
16
 
 * This program is distributed in the hope that it will be useful,
17
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 
 * GNU General Public License for more details.
20
 
 *
21
 
 * You should have received a copy of the GNU General Public License
22
 
 * along with this program; if not, write to the Free Software
23
 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
24
 
 
25
 
/* description ==============================================================*/
26
 
 
27
 
/* This module parses Malaga values. */
28
 
 
29
 
/* includes =================================================================*/
30
 
 
31
 
#include <stdio.h>
32
 
#include "basic.h"
33
 
#include "pools.h"
34
 
#include "values.h"
35
 
#include "symbols.h"
36
 
#include "scanner.h"
37
 
 
38
 
#ifdef HANGUL
39
 
#include "hangul.h"
40
 
#endif
41
 
 
42
 
#undef GLOBAL
43
 
#define GLOBAL
44
 
 
45
 
#include "value_parser.h"
46
 
 
47
 
/* functions ================================================================*/
48
 
 
49
 
LOCAL void parse_symbol (void)
50
 
/* Parse a symbol and push it on the value stack. */
51
 
{
52
 
  test_token (TOK_IDENT);
53
 
  push_symbol_value (find_symbol (token_name));
54
 
  read_next_token ();
55
 
}
56
 
 
57
 
/*---------------------------------------------------------------------------*/
58
 
 
59
 
LOCAL void parse_simple_value (void)
60
 
/* Parse a value and leave it on the value_stack. */
61
 
{
62
 
  int_t n; /* number of values in list or record */
63
 
  
64
 
  switch (next_token) 
65
 
  {
66
 
  case '<': /* Parse a list. */
67
 
    read_next_token ();
68
 
    n = 0;
69
 
    if (next_token != '>') 
70
 
    {
71
 
      parse_simple_value ();
72
 
      n++;
73
 
      while (next_token == ',') 
74
 
      {
75
 
        read_next_token ();
76
 
        parse_simple_value ();
77
 
        n++;
78
 
      }
79
 
    }
80
 
    parse_token ('>');
81
 
    build_list (n);
82
 
    break;
83
 
    
84
 
  case '[': /* Parse a record. */
85
 
    read_next_token ();
86
 
    n = 0;
87
 
    if (next_token != ']') 
88
 
    {
89
 
      parse_symbol ();
90
 
      parse_token (':');
91
 
      parse_simple_value ();
92
 
      n++;
93
 
      while (next_token == ',') 
94
 
      {
95
 
        read_next_token ();
96
 
        parse_symbol ();
97
 
        parse_token (':');
98
 
        parse_simple_value ();
99
 
        n++;
100
 
      }
101
 
    }
102
 
    parse_token (']');
103
 
    build_record (n);
104
 
    break;
105
 
    
106
 
  case TOK_IDENT: /* Parse a symbol. */
107
 
    parse_symbol ();
108
 
    break;
109
 
    
110
 
  case TOK_STRING: /* Parse a string. */
111
 
#ifdef HANGUL
112
 
    encode_hangul (&token_string);
113
 
#endif
114
 
    push_string_value (token_string, NULL);
115
 
    read_next_token ();
116
 
    break;
117
 
      
118
 
  case TOK_NUMBER: /* Parse a number value. */
119
 
    push_number_value (token_number);
120
 
    read_next_token ();
121
 
    break;
122
 
    
123
 
  default:
124
 
    error ("value expected, not %s", token_as_text (next_token));
125
 
  }
126
 
}
127
 
 
128
 
/*---------------------------------------------------------------------------*/
129
 
 
130
 
GLOBAL void parse_value_string (string_t value_string)
131
 
/* STACK EFFECTS: (nothing) -> <new_value>. *
132
 
 * Parse <value_string> which must contain a value in text format.
133
 
 * <new_value> is the content of <value_string>. */
134
 
{
135
 
  set_scanner_input (value_string);
136
 
  parse_simple_value ();
137
 
  parse_token (EOF);
138
 
}
139
 
 
140
 
/* end of file ==============================================================*/