What's new? | Help | Directory | Sign in
Google
heron-language
Heron is an object-oriented programming language for model driven architecture
  
  
  
  
    
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
Authour: Christopher Diggins
License: MIT Licence 1.0

Utility functions
*/

using namespace std;
using namespace yard;

typedef TreeBuildingParser<char> Parser;
typedef Parser::Tree Tree;
typedef Tree::AbstractNode Node;

void OutputExpr(Node* node);
void OutputStatement(Node* node);
void OutputStatementList(Node* node);

int nIndent = 0;
const char* outputPath = "";

void RedirectOutput(const char* x)
{
fflush(stdout);
char buffer[255];
sprintf(buffer, "%s\\%s.java", outputPath, x);
freopen(buffer, "w", stdout);
}

void Unimplemented()
{
assert(false);
}

void AstError(const char* x)
{
perror(x);
assert(false);
}

string NodeToStr(Node* pNode)
{
string ret = string(pNode->GetFirstToken(), pNode->GetLastToken());
/*
// TEMP: used for debugging
for (size_t i=0; i < ret.length(); ++i) {
if (ret[i] == ' ')
ret[i] = '#';
}*/
return ret;
}

void OutputParseTree(Node* pNode, int n = 0)
{
for (int i=0; i < n; ++i) printf(" ");
printf("%s\n", pNode->GetRuleTypeInfo().name());
for (Node* p = pNode->GetFirstChild(); p != NULL; p = p->GetSibling())
OutputParseTree(p, n + 1);
}

void Output(const string& s)
{
for (size_t i=0; i < s.length(); ++i) {
if (s[i] == '{')
++nIndent;
else if (s[i] == '}')
--nIndent;
}
printf("%s", s.c_str());
}

void OutputInt(int n)
{
printf("%d", n);
}

void OutputRawNode(Node* pNode)
{
if (pNode == NULL)
printf("missing node!\n");
Output(NodeToStr(pNode));
}

void OutputLine()
{
printf("\n");
for (int i=0; i < nIndent; ++i)
printf(" ");
}

void OutputLine(string s)
{
Output(s);
OutputLine();
}

void OutputLine(Node* node)
{
assert(node != NULL);
OutputLine(NodeToStr(node));
}

Show details Hide details

Change log

r29 by cdiggins on Feb 19, 2008   Diff
OMG it works!!
Go to: 
Project members, sign in to write a code review

Older revisions

r26 by cdiggins on Feb 17, 2008   Diff
Slowly getting there.
r25 by cdiggins on Feb 17, 2008   Diff
I need to make each class go into a
separate file.
r22 by cdiggins on Feb 17, 2008   Diff
Generating some working Java.
All revisions of this file

File info

Size: 1782 bytes, 102 lines