本文整理汇总了C++中parsetree_t::pop方法的典型用法代码示例。如果您正苦于以下问题:C++ parsetree_t::pop方法的具体用法?C++ parsetree_t::pop怎么用?C++ parsetree_t::pop使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类parsetree_t
的用法示例。
在下文中一共展示了parsetree_t::pop方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Label
void parser_t::Label()
{
parsetree.push(NT_Label);
if(scanner.next_token() == T_label)
{
eat_token(T_label);
current = c_code_main;
scanner.next_token();
current = current + "\n L" + scanner.get_token_value() + ":\n ";
// printf("current:\n%s\n", current.c_str());
eat_token(T_num);
eat_token(T_colon);
LabelStatements();
// printf("current:\n%s\n", current.c_str());
c_code_main = current;
current = c_code_main;
printf("%s\n", c_code_main.c_str());
}
else { syntax_error(NT_Label); }
parsetree.pop();
}
示例2: Start
//Here is an example
void parser_t::Start()
{
//push this non-terminal onto the parse tree.
//the parsetree class is just for drawing the finished
//parse tree, and should in should have no effect the actual
//parsing of the data.
parsetree.push(NT_Start);
code_printf("#include <stdio.h>\n");
code_printf("inline int intPow(int num, int e) {\n");
code_printf("\tint res = 1;\n");
code_printf("\tif(e>=0){\n");
code_printf("\t\tfor(;e>0;e--)res = res*num;\n");
code_printf("\t\treturn res;\n");
code_printf("\t}\n");
code_printf("\tif(num == 1) return 1;\n"); /* if e is negative 1^-a is 1*/
code_printf("\treturn 0;\n"); /* if e is negative floor(1 ^-a) is 0*/
code_printf("}\n");
code_printf("int main(int argc, char *argv[]){\n");
code_printf("\tint m[101];\n");
// code_printf("\tint m[101];\n");
Statements();
code_printf("\treturn 0;\n");
code_printf("}\n");
parsetree.pop();
}
示例3: Jump
string parser_t::Jump(string s)
{
token_type watch = scanner.next_token();
parsetree.push(NT_Jump);
if(watch == T_goto){
eat_token(T_goto);
s = Forward(s);
}else{
syntax_error(NT_Jump);
}
watch = scanner.next_token();
switch(watch){
case T_eof:
case T_label:
case T_goto:
case T_m:
case T_print:
break;
default:
syntax_error(NT_Jump);
break;
}
parsetree.pop();
return s;
}
示例4: Label
string parser_t::Label(string s)
{
token_type watch = scanner.next_token();
parsetree.push(NT_Label);
if(watch == T_label){
s.append("L");
eat_token(T_label);
eat_token(T_num);
char buf[100];
snprintf(buf, 100, "%d", scanner.nextNumber);
s.append(buf);
s.append(":");
eat_token(T_colon);
}else{
syntax_error(NT_Label);
}
watch = scanner.next_token();
switch(watch){
case T_eof:
case T_label:
case T_goto:
case T_m:
case T_print:
break;
default:
syntax_error(NT_Label);
break;
}
parsetree.pop();
return s;
}
示例5: Statement
void parser_t::Statement()
{
string s;
token_type watch = scanner.next_token();
parsetree.push(NT_Statement);
if(watch == T_label){
s = Label(s);
}else if(watch == T_goto){
s = Jump(s);
}else if(watch == T_m){
s = Assignment(s);
}else if(watch == T_print){
s = Print(s);
}else{
syntax_error(NT_Statement);
}
cerr<<s<<";"<<endl;
watch = scanner.next_token();
switch(watch){
case T_eof:
case T_label:
case T_goto:
case T_m:
case T_print:
break;
default:
syntax_error(NT_Statement);
break;
}
parsetree.pop();
}
示例6: Factor
void parser_t::Factor(){
token_type token;
parsetree.push(NT_Factor);
code_printf("intPow(");
switch(token = scanner.next_token()){
case T_openparen:
eat_token(T_openparen);
code_printf("(");
Expression();
code_printf(")");
eat_token(T_closeparen);
break;
case T_m:
code_printf("m[");
eat_token(T_m);
eat_token(T_opensquare);
Expression();
eat_token(T_closesquare);
code_printf("]");
break;
case T_num:
code_printf("%d",scanner.get_num());
eat_token(T_num);
break;
default:
syntax_error(NT_Factor);
/*
fprintf(stderr, "%d Invalid factor: %s\n", scanner.get_line(), token_to_string(token));
assert(0);
*/
}
Power();
parsetree.pop();
}
示例7: Assignment
string parser_t::Assignment(string s)
{
token_type watch = scanner.next_token();
parsetree.push(NT_Assignment);
if(watch == T_m){
s.append("m");
eat_token(T_m);
s.append("[");
eat_token(T_opensquare);
s = Expression(s);
s.append("]");
eat_token(T_closesquare);
s.append("=");
eat_token(T_equals);
s = Expression(s);
}else{
syntax_error(NT_Print);
}
watch = scanner.next_token();
switch(watch){
case T_eof:
case T_label:
case T_goto:
case T_m:
case T_print:
break;
default:
syntax_error(NT_Print);
break;
}
parsetree.pop();
return s;
}
示例8: Statement
void parser_t::Statement()
{
parsetree.push(NT_Statement);
code_printf("\t");
switch(scanner.next_token()){
case T_label:
Label();
break;
case T_goto:
Jump();
code_printf(";\n");
break;
case T_m:
Assignment();
code_printf(";\n");
break;
case T_print:
Print();
code_printf(";\n");
break;
default:
syntax_error(NT_Start);
break;
}
parsetree.pop();
}
示例9: LabelStatements
void parser_t::LabelStatements()
{
parsetree.push(NT_LabelStatements);
switch(scanner.next_token())
{
case T_m:
case T_print:
LabelStatement();
LabelStatements();
break;
case T_goto:
case T_label:
case T_eof:
parsetree.drawepsilon();
break;
default:
syntax_error(NT_LabelStatement);
break;
}
parsetree.pop();
}
示例10: Factor
void parser_t::Factor()
{
parsetree.push(NT_Factor);
if(scanner.next_token() == T_num)
{
current = current + scanner.get_token_value();
// printf("%s\n", current.c_str());
eat_token(T_num);
}
else if(scanner.next_token() == T_m)
{
eat_token(T_m);
eat_token(T_opensquare);
current = current + "m[";
Expression();
eat_token(T_closesquare);
current = current + "]";
}
else { syntax_error(NT_Factor); }
parsetree.pop();
}
示例11: Statement
void parser_t::Statement()
{
parsetree.push(NT_Statement);
current = c_code_main;
// printf("%s\n", current.c_str());
switch(scanner.next_token())
{
case T_label:
Label();
break;
case T_goto:
Jump();
break;
case T_m:
Assignment();
break;
case T_print:
Print();
break;
default:
syntax_error(NT_Statement);
break;
}
c_code_main = current;
// printf("%s\n", c_code_main.c_str());
parsetree.pop();
}
示例12: Jump
void parser_t::Jump()
{
parsetree.push(NT_Jump);
if(scanner.next_token() == T_goto)
{
eat_token(T_goto);
scanner.next_token();
std::string tmp = scanner.get_token_value();
eat_token(T_num);
//If there's an if statement, handle it it.
if(scanner.next_token() == T_if) {
eat_token(T_if);
current = current + "if(";
Expression();
current = current + " != 0) { ";
current = current + "goto L" + tmp + "; }\n ";
}
else {
current = current + " goto L" + tmp + ";\n ";
}
}
else { syntax_error(NT_Jump); }
parsetree.pop();
}
示例13: BracketTerm
void parser_t::BracketTerm() {
parsetree.push(NT_BracketTerm);
switch (scanner.next_token()) {
case T_openparen:
scanner.eat_token(T_openparen);
cerr_buffer.push_back("(");
Expression();
scanner.eat_token(T_closeparen);
cerr_buffer.push_back(")");
break;
case T_m:
scanner.eat_token(T_m);
scanner.eat_token(T_opensquare);
cerr_buffer.push_back("m[");
Expression();
scanner.eat_token(T_closesquare);
cerr_buffer.push_back("]");
break;
case T_num:
scanner.eat_token(T_num);
cerr_buffer.push_back(scanner.get_number());
break;
default:
syntax_error(NT_BracketTerm);
}
parsetree.pop();
}
示例14: Print
void parser_t::Print(){
parsetree.push(NT_Print);
eat_token(T_print);
code_printf("printf(\"%%d\\n\", ");
Expression();
code_printf(")");
parsetree.pop();
}
示例15: Term
void parser_t::Term() {
parsetree.push(NT_Term);
ExponentialTerm();
TermRight();
parsetree.pop();
}