亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? compiler.cpp

?? SSD6 練習4的原版正確答案
?? CPP
?? 第 1 頁 / 共 3 頁
字號:
/* compiler -- */

#include "flincl.h"
#include "stdio.h"
#include "shortstack.h"
#include "semantics.h"
#include "compiler.h"
#include "ctype.h"
#include "assert.h"
#include "string.h"

#define ctrace if (machine->trace_flag) trace

Compiler::Compiler()
{
}


bool Compiler::init(Machine_ptr m)
{
	machine = m;
	return semantics.init(machine, this);
}


void Compiler::expected_close_squote()
{
    report_error("expected close single quote");
}


void Compiler::expected_close_quote()
{
    report_error("expected close quote");
}


void Compiler::expected_char_const()
{
    report_error("expected character constant");
}


void Compiler::expected_close_paren_or_formal()
{
    report_error("expected close paren or formal parameter");
}


void Compiler::expected_close_paren()
{
    report_error("expected close paren");
}


void Compiler::expected_close_bracket()
{
    report_error("expected close bracket");
}


void Compiler::expected_equal()
{
    report_error("expected equal");
}


void Compiler::expected_indent()
{
    report_error("Compiler:: expected indent");
}


void Compiler::expected_newline()
{
    report_error("expected newline");
}


void Compiler::expected_open_paren()
{
    report_error("expected open paren");
}


void Compiler::expected_open_brace()
{
    report_error("expected open brace");
}

void Compiler::expected_to()
{
    report_error("expected to");
}


void Compiler::expected_token()
{
    report_error("expected more");
}


void Compiler::expected_colon()
{
    report_error("expected colon");
}


void Compiler::expected_comma()
{
    report_error("expected comma");
}


void Compiler::expected_statement()
{
    report_error("expected statement");
}


void Compiler::expected_method_or_field_selector()
{
    report_error("expected method or field selector");
}


void Compiler::expected_decl()
{
    report_error("expected declaration");
}


void Compiler::expected_hex_constant()
{
	report_error("expected hexadecimal constant");
}


void Compiler::expected_oct_constant()
{
	report_error("expected octal constant");
}


void Compiler::expected_number_constant()
{
	report_error("expected number constant");
}


void Compiler::no_digit_in_hex()
{
	report_error("no digits found in hexidecimal constant");
}


void Compiler::no_digit_in_exponent()
{
	report_error("no digit found in exponent");
}



void Compiler::expected_id(char *msg)
{
    char s[100];
    strcpy(s, "expected class name");
    strcat(s, msg);
    report_error(s);
}


void Compiler::expected_variable()
{
    report_error("expected variable name");
}


void Compiler::expected_expression()
{
	report_error("expected expression");
}


void Compiler::indentation_error()
{
    report_error("indentation error");
}

void Compiler::expected_equal_or_in()
{
	report_error("expected = or in after for variable");
}

void Compiler::report_error(char *s)
{
	char msg[128];
	if (!token) {
	    sprintf(msg, "Error: %s", s);
	} else {
		if (token->typ == TOKEN_INDENT) strcpy(token->str, "[indentation]");
		else if (token->typ == TOKEN_DEDENT) strcpy(token->str, "[dedentation]");
		else if (token->typ == TOKEN_NEWLINE) strcpy(token->str, "[newline]");
		sprintf(msg, "Error in line %d near \"%s\": %s", 
		         line_number, token->str, s);
	}
	machine->error_msg(msg);
	error_flag = true;
}


// get_token -- returns true if token is found
//
bool Compiler::get_token()
{
    other_token();
    if (unget_count) {
        unget_count--;
        // ctrace("Token: (ungot), %s\n", token->str);
        return true;
    }
    token->typ = TOKEN_OTHER;
    int i = 0;
    int c;
    if (dedent_count) {
        token->typ = TOKEN_DEDENT;
        dedent_count--;
        token->str[0] = 0;
        ctrace("Token: DEDENT\n");
        return true;
    }
    while ((c = getc(inf)) != EOF) { // this loops over white space
		i = 0;
        token->str[i++] = c;
		if (c == '#') {
			while ((c = getc(inf)) != EOF && c != '\n') ;
			if (c == '\n') ungetc(c, inf);
			continue;
		}
        if (c == '\n') {
			line_number++;
			if (newline_flag) { // (user types from terminal)
				if (interactive_mode) {
					// blank line generates DEDENTs in interactive mode
					while (0 < indentation[istack_top]) {
						dedent_count++;
						istack_top--;
					}
					if (0 != indentation[istack_top]) {
						indentation_error();
					}
					if (dedent_count > 0) {
						dedent_count--;
						token->typ = TOKEN_DEDENT;
						ctrace("Token: DEDENT");
					} else {
						continue; // ignore 2nd blank line
					}
					i = 0;
				} else continue; // ignore blank lines
			} else {
				token->typ = TOKEN_NEWLINE;
				newline_flag = true;
				ctrace("Token: NEWLINE");
			}
        } else if (newline_flag) {
            newline_flag = false;
            int indent = 0;
            while (isspace(c)) {
                indent++;
                if ((c = getc(inf)) == EOF) break;
            }
            ungetc(c, inf);
            if (c == '#' || c == '\n') {
                newline_flag = true;
                continue; // ignore blank lines
            }
            // generate indent or dedent?
            if (indent > indentation[istack_top]) {
                token->typ = TOKEN_INDENT;
                indentation[++istack_top] = indent;
                i = 0; // take space out of token
                ctrace("Token: INDENT");
            } else if (indent < indentation[istack_top]) {
                while (indent < indentation[istack_top]) {
                    dedent_count++;
                    istack_top--;
                }
                if (indent != indentation[istack_top]) {
                    indentation_error();
                }
                dedent_count--;
                token->typ = TOKEN_DEDENT;
                i = 0;
                ctrace("Token: DEDENT");
            } else { // no indentation, newline_flag is off
                continue;
            }
        } else if (isspace(c)) {
            continue; // ignore spaces after initial ones handled above
        } else if (__iscsymf(c)) {
            newline_flag = false;
            /* get alphanumeric */
            while ((c = getc(inf)) != EOF) {
                if (__iscsym(c)) {
                    token->str[i++] = c;
                } else {
                    ungetc(c, inf);
                    break;
                }
            }
            token->typ = TOKEN_ID;
            ctrace("Token: ID");
        } else if (isdigit(c) || c == '-') {
			char first_digit = 0;
            newline_flag = 0;  // index of first digit in string
			if (c == '-') {
				first_digit = 1;
			}
            /* get number */
            while ((c = getc(inf)) != EOF) {
                if (isdigit(c)) {
                    token->str[i++] = c;
                } else {
                    break;
                }
            }
            if (c == '.' || tolower(c) == 'e') {
                token->typ = TOKEN_DOUBLE;
                if (c == '.') token->str[i++] = c;
				else ungetc(c, inf); // unget 'e'

                while ((c = getc(inf)) != EOF) {
                    if (isdigit(c)) {
                        token->str[i++] = c;
                    } else {
                        ungetc(c, inf);
                        ctrace("Token: DOUBLE");
                        break;
                    }
                }
				// may be followed by exponent "e+006"
				if ((c = getc(inf)) != EOF) {
					if (tolower(c) == 'e') {
						token->str[i++] = 'e';
						if ((c = getc(inf)) != EOF) {
							if ((c == '+') || (c == '-')) {
								token->str[i++] = c;
							} else {
								ungetc(c, inf);
							}
							int expcount = 0;
							while ((c = getc(inf)) != EOF) {
								if (isdigit(c)) {
									expcount++;
									token->str[i++] = c;
								} else {
									ungetc(c, inf);
									if (expcount == 0) {
										token->str[i] = 0;
										no_digit_in_exponent();
									}
									break;
								}
							}
						}
					}
				}
			} else if ((i == first_digit + 1) &&           // enough for "0x"
					   (token->str[first_digit] == '0') && // got the "0"
					   (tolower(c) == 'x')) {              // got the "x"
                token->typ = TOKEN_LONG;
				token->str[i++] = c;
				int digit_count = 0;
				while ((c = getc(inf)) != EOF) {
					if (isxdigit(c)) {
						digit_count = 0;
						token->str[i++] = c;
					} else {
						if (digit_count == 0) {
							token->str[i] = 0;
							no_digit_in_hex();
						}
                        ungetc(c, inf);
                        ctrace("Token: LONG");
						break;
					}
				}
            } else {
                ungetc(c, inf);
                token->typ = TOKEN_LONG;
                ctrace("Token: LONG");
            }
        } else if (c == '"') {
            newline_flag = false;
			// leave quotes in... i = 0; // skip the quote
            int quote_count = 0;
            token->typ = TOKEN_STRING;
            while ((c = getc(inf)) != EOF) {
                token->str[i++] = c;
                if (c == '"') {
                    if (quote_count == 0) {
                        quote_count = 1;
                    } else /* quote_count == 1 */ {
                        i = i - 1; // erase second quote
                        quote_count = 0;
                    }
                } else if (quote_count == 1) {
                    // we closed the quote
                    ungetc(c, inf);
					i--;
                    ctrace("Token: STRING");
                    break;
                } else if (c == '\\') { // escape character
                    c = getc(inf);
                    if (c == EOF) break;
                    token->str[i - 1] = c;
                }
            }
            if (quote_count != 1) {
                expected_close_quote();
            } else {
				i--; // back over the close quote
			}
        } else if (c == '\'') {
            newline_flag = false;
			// leave quotes in ... i = 0; // skip the quote
            int quote_count = 0;
            token->typ = TOKEN_SYMBOL;
            while ((c = getc(inf)) != EOF) {
                token->str[i++] = c;
                if (c == '\'') {
                    if (quote_count == 0) {
                        quote_count = 1;
                    } else /* quote_count == 1 */ {
                        i = i - 1; // erase second quote
                        quote_count = 0;
                    }
                } else if (quote_count == 1) {
                    // we closed the quote
                    ungetc(c, inf);
					i--;
                    ctrace("Token: SYMBOL");
                    break;
                } else if (c == '\\') { // escape character
                    c = getc(inf);
                    if (c == EOF) break;
                    token->str[i - 1] = c;
                }
            }
            if (quote_count != 1) {
                expected_close_quote();
            } else {
				i--; // back over the close quote
			}

        } else if (c == '>' || c == '<' || c == '!' || c == '=') {
            newline_flag = false;
			if ((c = getc(inf)) != EOF) {
                if ((c == '=') ||
                    (token->str[i - 1] == '>' && c == '>') ||
                    (token->str[i - 1] == '<' && c == '<')) {
				    token->str[i++] = c;
                } else ungetc(c, inf);
            }
			ctrace("Token: OTHER");
        } else if (c == '*') {
            newline_flag = false;
            if ((c = getc(inf)) != EOF && (c == '*')) {
                token->str[i++] = c;
            } else ungetc(c, inf);
            ctrace("Token: OTHER");
        } else {
            newline_flag = false;
            ctrace("Token: OTHER");
        }
		token->str[i] = 0;
		if (token->typ != TOKEN_NEWLINE) ctrace(", '%s'\n", token->str);
		else ctrace(", '\\n'\n");
        return !error_flag;
    }
	if (istack_top > 0) {
		istack_top--;
		token->typ = TOKEN_DEDENT;
        token->str[0] = 0;
        ctrace("Token: DEDENT\n");
        return true;
	}
	ctrace("Token: none\n");
    return false; // false and no error_flag means end of file
}


// unget_token -- back up to previous token
// (currently supports up to two levels of unget)
// This is more complex than I expected. token is a pointer
// to either token1 or token2, and unget_count tells how
// many levels we have ungotten.  The key "trick" is that
// unget always changes token to the other buffer, and get
// always changes token back.
//
bool Compiler::unget_token()
{
    assert(unget_count < 2);
    // ctrace("unget_token\n");
    unget_count++;
    other_token();
    return true;
}


// compile_file -- compile from opened file handle.
//
// interactive indicates that blank lines should terminate
// compilation of a top-level statement or declaration
// (normally blank lines are ignored, but this does not 

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲欧美怡红院| 精品久久久久香蕉网| 中文字幕亚洲成人| 成人美女在线观看| 国产精品第四页| 91麻豆产精品久久久久久| 亚洲伦理在线免费看| 欧美亚洲高清一区二区三区不卡| 亚洲已满18点击进入久久| 欧美日韩亚洲高清一区二区| 喷白浆一区二区| 国产欧美一区在线| 色综合久久综合网欧美综合网| 亚洲成人免费视频| 精品国产乱码久久久久久老虎| 国产一区二区毛片| 亚洲特黄一级片| 91精品国产欧美一区二区18 | 91视频免费观看| 一区二区三区四区av| 日韩欧美综合在线| 成人精品高清在线| 日本最新不卡在线| 中文字幕第一页久久| 欧美系列日韩一区| 国产一区二区美女| 亚洲第一成年网| 久久久亚洲精品石原莉奈| 91一区二区在线| 麻豆精品在线观看| 中文字幕亚洲综合久久菠萝蜜| 在线不卡一区二区| 国产高清无密码一区二区三区| 亚洲视频在线观看一区| 精品对白一区国产伦| 色综合久久综合| 国产一区二区三区精品视频| 国产精品天美传媒| 欧美一区二区三区小说| 99在线精品免费| 激情六月婷婷久久| 亚洲午夜国产一区99re久久| 久久精品在这里| 日韩一级二级三级精品视频| 国产成人av一区二区| 日韩成人精品在线| 亚洲精品水蜜桃| 亚洲国产精品激情在线观看| 欧美一级国产精品| 91福利视频在线| 成人黄色在线视频| 国产精品一线二线三线精华| 午夜精品福利一区二区蜜股av| 国产精品久线在线观看| 69堂精品视频| 日本韩国欧美国产| 成人激情开心网| 国产91精品一区二区麻豆亚洲| 日本不卡视频在线| 日韩精品亚洲专区| 亚洲国产日韩精品| 一区二区不卡在线视频 午夜欧美不卡在 | 国产欧美日韩中文久久| 欧美一区中文字幕| 欧美美女黄视频| 在线看国产日韩| 91成人在线精品| 色哟哟亚洲精品| 91视频.com| 99久久久久久99| 北岛玲一区二区三区四区| 国产在线不卡一区| 国内精品在线播放| 九色|91porny| 国产麻豆成人精品| 国产剧情在线观看一区二区| 国产在线精品一区二区三区不卡| 日本不卡在线视频| 韩国精品一区二区| 国产主播一区二区| 国产精品一区二区在线观看不卡 | 91精品国产综合久久久久| 欧洲一区在线电影| 欧美在线观看视频在线| 欧美日韩亚洲综合一区二区三区 | jizzjizzjizz欧美| 91免费观看在线| 欧美视频一区二区在线观看| 欧美天堂亚洲电影院在线播放| 欧美性欧美巨大黑白大战| 欧美日本一区二区三区四区 | 国产成人在线看| 国产成人免费xxxxxxxx| 成人动漫视频在线| 精品视频在线视频| 欧美一级高清片在线观看| 久久蜜臀精品av| 中文字幕一区视频| 亚洲国产另类av| 美女免费视频一区| 成人免费毛片app| 91官网在线观看| 日韩一级二级三级精品视频| 亚洲国产精品二十页| 亚洲一区二区在线播放相泽| 丝袜美腿亚洲一区二区图片| 国产中文字幕精品| 色网站国产精品| 欧美一二三区在线观看| 国产欧美一区二区精品性色| 亚洲精品国产无套在线观| 日本不卡一区二区| 成人午夜激情片| 欧美日韩午夜影院| 中文字幕高清不卡| 日本系列欧美系列| 久久午夜老司机| 依依成人精品视频| 国产精品成人免费在线| 亚洲国产视频在线| 国产精品一区久久久久| 欧美唯美清纯偷拍| 久久精品人人做人人爽人人| 亚洲欧美另类久久久精品| 麻豆91小视频| 色综合久久九月婷婷色综合| 97久久精品人人爽人人爽蜜臀| 欧美日韩在线亚洲一区蜜芽| 色久优优欧美色久优优| 欧美男同性恋视频网站| 亚洲国产一区在线观看| 在线观看视频一区二区 | 国产免费成人在线视频| 国产伦精品一区二区三区免费| 欧美一激情一区二区三区| 亚洲一区二区三区四区五区中文 | 国产精品99久久久久久久vr| 精品久久久网站| 国产中文字幕一区| 久久老女人爱爱| 顶级嫩模精品视频在线看| 国产日韩精品久久久| 不卡一区二区三区四区| 亚洲欧美韩国综合色| 欧美性视频一区二区三区| 亚洲成av人片一区二区| 91精品国产91热久久久做人人| 久久精品国产成人一区二区三区| 日韩亚洲欧美一区| 国产一区91精品张津瑜| 欧美激情一区在线| 色偷偷久久人人79超碰人人澡| 亚洲妇女屁股眼交7| 91精品国产一区二区人妖| 国产剧情一区二区| 综合久久给合久久狠狠狠97色 | 欧美一区二区三区啪啪| 91一区二区在线| 亚洲永久免费av| 日韩欧美在线1卡| 国产精品一级在线| 亚洲人成人一区二区在线观看| 欧美日韩国产综合一区二区三区| 蜜臀av性久久久久蜜臀av麻豆| 国产午夜亚洲精品羞羞网站| 一本色道综合亚洲| 蜜桃视频在线观看一区二区| 国产日产欧美一区| 欧美伊人精品成人久久综合97| 日韩av不卡一区二区| 国产亚洲欧洲一区高清在线观看| 91网上在线视频| 日本不卡中文字幕| 国产精品素人一区二区| 欧美视频在线播放| 国产精品白丝av| 五月激情丁香一区二区三区| 久久久99免费| 欧美日韩一卡二卡三卡 | 精品福利在线导航| 99久久久久久| 美腿丝袜亚洲一区| 国产精品第四页| 日韩欧美国产一区二区三区| 成人av综合一区| 免费精品99久久国产综合精品| 国产精品色婷婷久久58| 欧美高清视频www夜色资源网| 国产另类ts人妖一区二区| 亚洲国产精品久久久男人的天堂| 久久奇米777| 在线综合亚洲欧美在线视频| 成年人午夜久久久| 韩国成人在线视频| 五月天国产精品| 亚洲卡通欧美制服中文| 国产日韩精品一区二区浪潮av| 欧美肥妇毛茸茸| 91同城在线观看| 国产91丝袜在线播放|