Skip to content

Commit

Permalink
Merge branch 'dev' of gdh/compiler into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Guo Duhao authored and Gogs committed Jun 24, 2018
2 parents 9b0bee2 + b4b7960 commit cf29f74
Show file tree
Hide file tree
Showing 4 changed files with 216 additions and 106 deletions.
52 changes: 51 additions & 1 deletion Node.h
@@ -1,6 +1,6 @@
#ifndef Node_h
#define Node_h

//something
#include <iostream>
#include <string>
#include "stdarg.h"
Expand All @@ -11,16 +11,61 @@

using namespace std;

enum action{
Add,
Sub,
Mul,
Div,
Greater,
Less,
Equal,
Unequal,
Iftrue,
Jump
};

struct Lable{
string curr;
string equalTo;
Lable( string c, string eq ):curr(c), equalTo(eq){}
};

struct Code{
Lable lable;
action act;
string addr1, addr2;
Code( Lable l, action a, string a1, string a2 ):lable(l.curr,l.equalTo), act(a), addr1(a1), addr2(a2) {}
};



class Node{
public:
int type;
string value;
Node *lchild, *rchild;

vector<Code> codes;
string place;

Node* next;
Node* T;
Node* F;

int addrAdditive;
int result;

Node():lchild(NULL),rchild(NULL){}

virtual bool isTerminal(){return false;};
virtual string toString(){return "";};
void addCode( Node* node ){
for(int i = 0; i < node->codes.size(); i++ )
codes.push_back(node->codes[i]);
}
void addCode( Code code ){
codes.push_back( code );
}
};

class Terminal: public Node{
Expand All @@ -47,3 +92,8 @@ class Var:public Node{
//%define parse.error verbose

#endif

/*
*/
15 changes: 8 additions & 7 deletions in.cm
@@ -1,7 +1,8 @@
int main(){
x = 5+10;
if(5){
y = 10;
}
c = 99;
}
int main(int argc, int argv[] ){
x = 5+10;
z = argv[5];
if(5){
y = 10;
}
c = 99;
}

0 comments on commit cf29f74

Please sign in to comment.