OpenCores
URL https://opencores.org/ocsvn/raptor64/raptor64/trunk

Subversion Repositories raptor64

[/] [raptor64/] [trunk/] [software/] [c64/] [source/] [ParseEnumDeclaration.c] - Blame information for rev 53

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 37 robfinch
#include        <stdio.h>
2
#include <string.h>
3
#include        "c.h"
4
#include        "expr.h"
5
#include "Statement.h"
6
#include        "gen.h"
7
#include        "cglbdec.h"
8
 
9
/*******************************************************
10
        Modified to support Raptor64 'C64' language
11
        by Robert Finch
12
        robfinch@opencores.org
13
*******************************************************/
14
 
15
extern TABLE tagtable;
16
extern TYP *head;
17
extern TYP stdconst;
18
 
19
void enumbody(TABLE *table);
20
 
21
void ParseEnumDeclaration(TABLE *table)
22
{
23
        SYM *sp;
24
    TYP     *tp;
25
    if( lastst == id) {
26
        if((sp = search(lastid,&tagtable)) == NULL) {
27
            sp = allocSYM();
28
            sp->tp = allocTYP();
29
            sp->tp->type = bt_enum;
30
            sp->tp->size = 2;
31
            sp->tp->lst.head = 0;
32
                        sp->tp->btp = 0;
33
            sp->storage_class = sc_type;
34
            sp->name = litlate(lastid);
35
            sp->tp->sname = sp->name;
36
            NextToken();
37
            if( lastst != begin)
38
                    error(ERR_INCOMPLETE);
39
            else {
40
                                insert(sp,&tagtable);
41
                                NextToken();
42
                                ParseEnumerationList(table);
43
            }
44
        }
45
        else
46
            NextToken();
47
        head = sp->tp;
48
    }
49
    else {
50
        tp = allocTYP();        // fix here
51
        tp->type = bt_short;
52
        if( lastst != begin)
53
            error(ERR_INCOMPLETE);
54
        else {
55
            NextToken();
56
            ParseEnumerationList(table);
57
        }
58
    head = tp;
59
    }
60
}
61
 
62
void ParseEnumerationList(TABLE *table)
63
{
64
        int     evalue;
65
    SYM     *sp;
66
    evalue = 0;
67
    while(lastst == id) {
68
        sp = allocSYM();
69
        sp->name = litlate(lastid);
70
        sp->storage_class = sc_const;
71
        sp->tp = &stdconst;
72
        insert(sp,table);
73
        NextToken();
74
                if (lastst==assign) {
75
                        NextToken();
76
                        sp->value.i = GetIntegerExpression();
77
                        evalue = sp->value.i+1;
78
                }
79
                else
80
                        sp->value.i = evalue++;
81
        if( lastst == comma)
82
                NextToken();
83
        else if(lastst != end)
84
                break;
85
    }
86
    needpunc(end);
87
}
88
 

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.