C++ parser

Закрито

Опис

#include "p2lex.h"

#include <string>

#include <istream>

#include <fstream>

using namespace std;

/////////

//// this class can be used to represent the parse result

//// the various different items that the parser might recognize can be

//// subclasses of ParseTree

class ParseTree {

private:

ParseTree *leftChild;

ParseTree *rightChild;

int whichLine;

public:

ParseTree(ParseTree *left = 0, ParseTree *right = 0) : leftChild(left),rightChild(right) {

whichLine = linenum;

}

int onWhichLine() { return whichLine; }

};

//// for example, an integer...

class Integer : public ParseTree {

private:

Token iTok;

public:

Integer(const Token& iTok) : ParseTree(), iTok(iTok) {}

int getInteger() { return stoi( [url removed, login to view]() ); }

};

int linenum = 0;

int globalErrorCount = 0;

/// error handler

void error(string msg)

{

cout << linenum << ": " << msg << endl;

++globalErrorCount;

}

/// function prototypes

ParseTree *Program(istream *in);

ParseTree *StmtList(istream *in);

ParseTree *Stmt(istream *in);

ParseTree *Expr(istream *in);

ParseTree *Term(istream *in);

ParseTree *Primary(istream *in);

ParseTree *String(istream *in);

ParseTree *Program(istream *in)

{

ParseTree *result = StmtList(in);

// make sure there are no more tokens...

if( getToken(in).getTok() != DONE )

return 0;

return result;

}

ParseTree *StmtList(istream *in)

{

return 0;

}

ParseTree *Stmt(istream *in)

{

Token t;

t = getToken(in);

if( [url removed, login to view]() == PRINT ) {

// process PRINT

}

else if( [url removed, login to view]() == SET ) {

// process SET

}

else

error("Invalid statement");

return 0;

}

ParseTree *Expr(istream *in)

{

return 0;

}

ParseTree *Term(istream *in)

{

return 0;

}

ParseTree *Primary(istream *in)

{

Token t = getToken(in);

if( [url removed, login to view]() == ID ) {

}

else if( [url removed, login to view]() == INT ) {

return new Integer(t);

}

else if( [url removed, login to view]() == STR ) {

}

else if( [url removed, login to view]() == LPAREN ) {

ParseTree *ex = Expr(in);

if( ex == 0 )

return 0;

t = getToken(in);

if( [url removed, login to view]() != RPAREN ) {

error("expected right parens");

return 0;

}

return ex;

}

return 0;

}

ParseTree *String(istream *in)

{

return 0;

}

main()

{

ParseTree *prog = Program(&cin);

if( prog == 0 || globalErrorCount != 0 ) {

cout << "Parse failed, exiting" << endl;

return 0;

}

cout << "Success. Congrats!" << endl;

return 0;

}

Навички: Програмування на C++, Архітектура ПЗ

Показати більше: c++ done asap, c done asap, real life example failed project, free html parser example, ticker example done flash, example registration form done word, parser txt java example, example works can done project photoshop, example bank transaction system done cnet, example inventory sheet done excel, example payment done authorizenet php, example program using parser class parse text java, example java parser, vb6 text file parser project example

ID проекту: #12161733

Доручено:

wangbeizou

Hello. Employer. I have read and understood the project. I'm an Expert in Data Structures and Algorithms. And I know well ; Java ,C/C++, Python ,PHP. I'm interested this project. So, firstly I want to discuss Більше

$50 USD за 2 дні(-в)
(45 відгуків(-и))
5.2

2 фрілансерів(-а) подали заявки на цю роботу; середня заявка - $45

amariitism

Hello We are highly motivated young technocrats from IIT(ISM) Dhanbad, India. We are approachable, you can come to us if you have a struggle, we are happy to help. Expertise:- Syllabus, Virtual Assistance, Data Більше

$40 USD за 3 дні(-в)
(3 відгуків(-и))
2.8