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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? 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 

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
av高清不卡在线| 精品国产百合女同互慰| 日韩一区二区三区视频在线观看| 久久嫩草精品久久久精品| 综合自拍亚洲综合图不卡区| 久久99精品久久只有精品| 成人高清免费观看| 欧美大片日本大片免费观看| 亚洲乱码精品一二三四区日韩在线| 另类专区欧美蜜桃臀第一页| 欧美日韩一区在线| 亚洲欧洲三级电影| 国内精品视频666| 欧美日韩大陆一区二区| 中文字幕色av一区二区三区| 国产精品影视在线观看| 欧美一级理论片| 天天操天天干天天综合网| 一本色道a无线码一区v| 国产精品丝袜在线| 国产伦精一区二区三区| 欧美成人伊人久久综合网| 日韩二区三区四区| 欧美人妇做爰xxxⅹ性高电影 | 亚洲成av人片在线| 成人动漫一区二区在线| 中文字幕第一区综合| 国产呦精品一区二区三区网站| 91精品综合久久久久久| 五月婷婷综合在线| 欧美日产国产精品| 午夜精品视频在线观看| 欧美揉bbbbb揉bbbbb| 亚洲一级在线观看| 欧美日韩一区二区欧美激情| 亚洲电影在线播放| 欧美精选一区二区| 日韩av一区二区三区四区| 在线观看91av| 久久国产精品无码网站| 亚洲精品一区二区三区影院| 国产一区二区三区美女| 欧美极品xxx| 99精品久久99久久久久| 最新日韩av在线| 色婷婷综合五月| 亚洲国产欧美在线| 欧美日韩成人一区二区| 美日韩一级片在线观看| 337p日本欧洲亚洲大胆色噜噜| 狠狠色丁香久久婷婷综合_中| 久久蜜桃一区二区| www.性欧美| 亚洲国产一区二区a毛片| 欧美精品乱人伦久久久久久| 精品中文字幕一区二区| 中文字幕第一区二区| 日本高清不卡视频| 视频精品一区二区| 久久精品亚洲一区二区三区浴池| 成人一区二区视频| 亚洲二区在线观看| 久久影院视频免费| 色猫猫国产区一区二在线视频| 午夜久久电影网| 久久久精品综合| 在线视频观看一区| 狠狠色狠狠色综合日日91app| 国产精品久久久久久久蜜臀| 欧美日韩精品福利| 国产成人在线免费观看| 亚洲网友自拍偷拍| 国产日韩精品久久久| 欧美午夜宅男影院| 高清在线不卡av| 婷婷久久综合九色综合绿巨人| 26uuu国产在线精品一区二区| 99久久免费视频.com| 天堂久久久久va久久久久| 欧美国产精品劲爆| 51精品国自产在线| 91色.com| 国产精品中文字幕日韩精品| 香蕉久久一区二区不卡无毒影院| 久久精品人人做人人综合| 欧美日韩精品专区| www.欧美亚洲| 国产精品99久久久久久似苏梦涵| 亚洲第一综合色| 成人欧美一区二区三区视频网页 | 日本电影亚洲天堂一区| 国产中文字幕一区| 日韩和欧美一区二区三区| 亚洲激情欧美激情| 中文字幕一区二区三区乱码在线| 日韩美女主播在线视频一区二区三区| 色老汉一区二区三区| 成人毛片在线观看| 国产一区日韩二区欧美三区| 日本网站在线观看一区二区三区| 一区二区三区**美女毛片| 中文字幕第一区综合| 国产午夜三级一区二区三| 日韩免费成人网| 日韩一本二本av| 91精品国产综合久久福利软件| 在线观看av一区二区| 色哟哟一区二区| 一本一本久久a久久精品综合麻豆| 国产69精品久久久久毛片| 国产一区二区三区免费观看| 国产又黄又大久久| 国产一区二区在线看| 狠狠色丁香婷婷综合| 国产一区二区三区四区在线观看| 免费视频一区二区| 激情小说欧美图片| 国产精品99久久久| 成人免费视频网站在线观看| 国产成人精品一区二区三区网站观看| 国产乱人伦偷精品视频不卡| 国产精品综合二区| 成人性生交大片免费 | 韩国精品免费视频| 精品无人码麻豆乱码1区2区| 精品系列免费在线观看| 久久国产精品无码网站| 国产精品乡下勾搭老头1| 成人黄色大片在线观看| 91香蕉视频污在线| 欧亚洲嫩模精品一区三区| 欧美日韩国产综合草草| 日韩欧美电影在线| 日本一区二区三区四区在线视频| 国产精品久久一卡二卡| 亚洲综合一区二区| 日本在线播放一区二区三区| 精品亚洲成a人在线观看| 国产精品亚洲综合一区在线观看| 99久久99久久精品免费观看| 欧美色图一区二区三区| 精品乱人伦小说| 亚洲三级视频在线观看| 亚州成人在线电影| 国产真实乱子伦精品视频| 成人激情午夜影院| 欧美日韩亚洲高清一区二区| 久久免费视频一区| 夜夜嗨av一区二区三区中文字幕 | 最新热久久免费视频| 日韩黄色在线观看| 国产成人av电影免费在线观看| 91女人视频在线观看| 91精品国产综合久久久久久| 欧美激情资源网| 水蜜桃久久夜色精品一区的特点| 国产麻豆日韩欧美久久| 欧美三级电影网站| 国产日韩精品视频一区| 日韩电影在线一区二区| 99久久精品99国产精品| 日韩一区二区三区视频在线观看 | 亚洲影视在线播放| 久久精品国产免费| 91麻豆福利精品推荐| 精品粉嫩aⅴ一区二区三区四区| 亚洲乱码国产乱码精品精98午夜| 久久99热这里只有精品| 欧洲国内综合视频| 欧美激情中文字幕一区二区| 蜜桃视频在线观看一区二区| av成人免费在线观看| 精品国产露脸精彩对白| 日韩专区欧美专区| 欧美午夜一区二区三区免费大片| 亚洲综合在线第一页| 国产乱对白刺激视频不卡| 在线综合+亚洲+欧美中文字幕| 亚洲欧美综合色| 国产乱子轮精品视频| 91精品国产91久久久久久最新毛片 | 国产精品国产三级国产普通话蜜臀| 日韩精品亚洲一区二区三区免费| 99re热这里只有精品免费视频| 久久一夜天堂av一区二区三区| 麻豆精品一区二区三区| 这里只有精品电影| 日日摸夜夜添夜夜添国产精品| 91久久国产最好的精华液| 国产精品国产三级国产三级人妇 | 美国三级日本三级久久99 | 欧美草草影院在线视频| 三级一区在线视频先锋 | 久久一夜天堂av一区二区三区| 日韩精品色哟哟| 欧美日韩一区二区三区在线| 亚洲美女一区二区三区| 99视频在线观看一区三区| 国产精品久久久久久久岛一牛影视| 国产精品资源在线|