Can anyone please help. I have to create a program that will read in an expression from a text file eg if(x>0 && x<9), and correctly build a node tree.
So far I am able to read the line in, and read through it to create tokens.
From here I am totally lost and no amount of reading can help. I think my nest stage (from research) must be to create an Abstract Syntax Tree. Is anyone able to help ...here is what I have to date:
// CompilerTest1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <string>
#include <iostream>
#include <fstream>
#include <string> // needed for strcasecmp
using namespace std;
//typedef enum {
// IDENTIFIER,
// KEYWORD,
// NUMBER,
// LIMIT,
// REL_OP, // such as == < > =!= => =< OP, // such as = : + - * / % DELIM, // such as . ( ) , { } ; [ ]
// UNDEF, // undefined EOT // end of token
//} TokenType;
//typedef struct {
// TokenType tokenType;
// char *instance;
// int lineNum;
//} Token;
typedef struct Node {
string data;
int precedence;
struct Node* parent;
struct Node* left;
struct Node* right;
} CNode, *PNode;
//PNode CreateNode(const string& x)
PNode CreateNode(const string x)
{
PNode p = new CNode;
p->parent = p->left = p->right = NULL;
p->data = x;
cout << "I have just added this to the tree: " << x << endl;