⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jikespg.g

📁 一个非常好的检索工具
💻 G
📖 第 1 页 / 共 3 页
字号:
%Options nogoto-default,esc=$,os=100,action,actfile=lpgact.i,noem%Options fp=lpg,gp,nodefer,suffix=_TK,stack_size=21,hactfile=lpgact.h-- $Id: jikespg.g,v 1.2 1999/11/04 14:02:22 shields Exp $-- This software is subject to the terms of the IBM Jikes Compiler-- License Agreement available at the following URL:-- http://www.ibm.com/research/jikes.-- Copyright (C) 1983, 1999, International Business Machines Corporation-- and others.  All Rights Reserved.-- You must accept the terms of that agreement to use this software.-- This grammar has been augmented with productions that captures-- most errors that a user is likely to make. This saves the need-- to have an error recovery system.--$Define ----------------------------------------------------------------$offset /.    ./$location/./* $rule_text */#line $next_line "$input_file"./$action/.act$rule_number, /* $rule_number */./$null_action/.$offset null_action, /* $rule_number */./$no_action/.$offset null_action, /* $rule_number */./------------------------------------------------------------------------$Terminals    DEFINE_KEY TERMINALS_KEY ALIAS_KEY START_KEY RULES_KEY    NAMES_KEY END_KEY    EQUIVALENCE ARROW OR    EMPTY_SYMBOL ERROR_SYMBOL EOL_SYMBOL EOF_SYMBOL    MACRO_NAME SYMBOL BLOCK HBLOCK    EOF------------------------------------------------------------------------$Alias    '::=' ::= EQUIVALENCE    '->'  ::= ARROW    '|'   ::= OR    $EOF  ::= EOF------------------------------------------------------------------------$Rules/:static void (*rule_action[]) (void) = {NULL,://.#line $next_line "$input_file"#define SYM1 terminal[stack_top + 1]#define SYM2 terminal[stack_top + 2]#define SYM3 terminal[stack_top + 3]static void null_action(void){    return;}static void add_macro_definition(char *name, struct terminal_type *term){    if (num_defs >= (int)defelmt_size)    {        defelmt_size += DEFELMT_INCREMENT;        defelmt = (struct defelmt_type *)            (defelmt == (struct defelmt_type *) NULL             ? malloc(defelmt_size * sizeof(struct defelmt_type))             : realloc(defelmt, defelmt_size * sizeof(struct defelmt_type)));        if (defelmt == (struct defelmt_type *) NULL)            nospace(__FILE__, __LINE__);    }    defelmt[num_defs].length       = (*term).length;    defelmt[num_defs].start_line   = (*term).start_line;    defelmt[num_defs].start_column = (*term).start_column;    defelmt[num_defs].end_line     = (*term).end_line;    defelmt[num_defs].end_column   = (*term).end_column;    strcpy(defelmt[num_defs].name, name);    num_defs++;    return;}static void add_block_definition(struct terminal_type *term){    if (num_acts >= (int) actelmt_size)    {        actelmt_size += ACTELMT_INCREMENT;        actelmt = (struct actelmt_type *)            (actelmt == (struct actelmt_type *) NULL             ? malloc(actelmt_size * sizeof(struct actelmt_type))             : realloc(actelmt, actelmt_size * sizeof(struct actelmt_type)));        if (actelmt == (struct actelmt_type *) NULL)            nospace(__FILE__, __LINE__);    }    actelmt[num_acts].rule_number  = num_rules;    actelmt[num_acts].start_line   = (*term).start_line;    actelmt[num_acts].start_column = (*term).start_column;    actelmt[num_acts].end_line     = (*term).end_line;    actelmt[num_acts].end_column   = (*term).end_column;    actelmt[num_acts].header_block = ((*term).kind == HBLOCK_TK);    num_acts++;    return;}./    LPG_INPUT ::= [define_block]                  [terminals_block]                  [alias_block]                  [start_block]                  [rules_block]                  [names_block]                  [%END]/:$no_action:/                | bad_symbol/:$no_action:/    bad_symbol ::= EQUIVALENCE/:$offset bad_first_symbol, /* $rule_number */://.$locationstatic void bad_first_symbol(void){    sprintf(msg_line,            "First symbol: \"%s\" found in file is illegal. "            "Line %d, column %d",            SYM1.name, SYM1.start_line, SYM1.start_column);    PRNTERR(msg_line);    exit(12);}./                 | ARROW/:$offset bad_first_symbol, /* $rule_number */:/                 | OR/:$offset bad_first_symbol, /* $rule_number */:/                 | EMPTY_SYMBOL/:$offset bad_first_symbol, /* $rule_number */:/                 | ERROR_SYMBOL/:$offset bad_first_symbol, /* $rule_number */:/                 | MACRO_NAME/:$offset bad_first_symbol, /* $rule_number */:/                 | SYMBOL/:$offset bad_first_symbol, /* $rule_number */:/                 | BLOCK/:$offset $action://.$locationstatic void act$rule_number(void){    sprintf(msg_line,            "Action block cannot be first object in file. "            "Line %d, column %d",            SYM1.start_line, SYM1.start_column);    PRNTERR(msg_line);    exit(12);}./    define_block ::= DEFINE_KEY/:$no_action:/                   | DEFINE_KEY macro_list/:$no_action:/    macro_list ::= macro_name_symbol macro_block/:$offset $action://.$locationstatic void act$rule_number(void){    if (action_bit)        add_macro_definition(SYM1.name, &(SYM2));    return;}./                 | macro_list macro_name_symbol macro_block/:$offset $action://.$locationstatic void act$rule_number(void){    if (action_bit)        add_macro_definition(SYM2.name, &(SYM3));    return;}./    macro_name_symbol ::= MACRO_NAME/:$no_action:/                        | SYMBOL          -- Warning, Escape missing !/:$offset $action://.$locationstatic void act$rule_number(void){    sprintf(msg_line,            "Macro name \"%s\" does not start with the "            "escape character. Line %d, column %d",            SYM1.name, SYM1.start_line, SYM1.start_column);    PRNTWNG(msg_line);     return;}./                        | '|'             -- No Good !!!/:$offset bad_macro_name, /* $rule_number */://.$locationstatic void bad_macro_name(void){    sprintf(msg_line,            "Reserved symbol cannot be used as macro name. "            "Line %d, column %d",            SYM1.start_line, SYM1.start_column);    PRNTERR(msg_line);    exit(12);}./                        | EMPTY_SYMBOL    -- No good !!!/:$offset bad_macro_name, /* $rule_number */:/                        | ERROR_SYMBOL    -- No good !!!/:$offset bad_macro_name, /* $rule_number */:/                        | produces        -- No good !!!/:$offset bad_macro_name, /* $rule_number */:/                        | BLOCK           -- No good !!!/:$offset $action://.$locationstatic void act$rule_number(void){    sprintf(msg_line,            "Macro name not supplied for macro definition. "            "Line %d, column %d",            SYM1.start_line, SYM1.start_column);    PRNTERR(msg_line);    exit(12);}./                        | DEFINE_KEY         -- No good !!!/:$offset $action://.$locationstatic void act$rule_number(void){    sprintf(msg_line,            "Macro keyword misplaced. Line %d, column %d",            SYM1.start_line, SYM1.start_column);    PRNTERR(msg_line);    exit(12);}./    macro_block ::= BLOCK/:$no_action:/                  | '|'            -- No Good !!!/:$offset definition_expected, /* $rule_number */://.$locationstatic void definition_expected(void){    sprintf(msg_line,            "Definition block expected where symbol found. "            "Line %d, column %d",            SYM1.start_line, SYM1.start_column);    PRNTERR(msg_line);    exit(12);}./                  | EMPTY_SYMBOL   -- No good !!!/:$offset definition_expected, /* $rule_number */:/                  | ERROR_SYMBOL   -- No good !!!/:$offset definition_expected, /* $rule_number */:/                  | produces       -- No good !!!/:$offset definition_expected, /* $rule_number */:/                  | SYMBOL         -- No good !!!/:$offset definition_expected, /* $rule_number */:/                  | keyword        -- No good !!!/:$offset definition_expected, /* $rule_number */:/                  | END_KEY        -- No good !/:$offset definition_expected, /* $rule_number */:/    terminals_block ::= TERMINALS_KEY {terminal_symbol}/:$no_action:/    terminal_symbol ::= SYMBOL/:$offset process_terminal, /* $rule_number */://.$locationstatic void process_terminal(void){    assign_symbol_no(SYM1.name, OMEGA);    return;}./                      | '|'/:$offset process_terminal, /* $rule_number */:/                      | produces/:$offset process_terminal, /* $rule_number */:/                      | DEFINE_KEY         -- No Good !!!/:$offset bad_terminal, /* $rule_number */://.$locationstatic void bad_terminal(void){    sprintf(msg_line,            "Keyword  has been misplaced in Terminal section."            "  Line %d, column %d",            SYM1.start_line, SYM1.start_column);    PRNTERR(msg_line);    exit(12);}./                      | TERMINALS_KEY      -- No Good !!!/:$offset bad_terminal, /* $rule_number */:/                      | BLOCK           -- No good !!!/:$offset $action://.$locationstatic void act$rule_number(void){    sprintf(msg_line,            "Misplaced block found in TERMINALS section."            "  Line %d, column %d",            SYM1.start_line, SYM1.start_column);    PRNTERR(msg_line);    exit(12);}./    alias_block ::= ALIAS_KEY {alias_definition}/:$no_action:/   alias_definition ::= alias_lhs produces alias_rhs/:$offset $action://.$locationstatic void act$rule_number(void){    register int image;    char tok_string[SYMBOL_SIZE + 1];    switch(SYM3.kind)    {        case EMPTY_SYMBOL_TK:            image = empty;            break;        case SYMBOL_TK:            assign_symbol_no(SYM3.name, OMEGA);            image = symbol_image(SYM3.name);            break;        case ERROR_SYMBOL_TK:            if (error_image > num_terminals)            {                restore_symbol(tok_string, kerror);                sprintf(msg_line,                        "Illegal aliasing to %s prior to its "                        "definition.  Line %d, column %d",                        tok_string,                        SYM3.start_line, SYM3.start_column);                PRNTERR(msg_line);                exit(12);            }            image = error_image;            break;        case EOF_SYMBOL_TK:            if (eoft_image > num_terminals)            {                restore_symbol(tok_string, keoft);                sprintf(msg_line,                        "Illegal aliasing to %s prior to its "                        "definition. Line %d, column %d",                        tok_string,                        SYM3.start_line, SYM3.start_column);                PRNTERR(msg_line);                exit(12);            }            image = eoft_image;            break;        case EOL_SYMBOL_TK:            if (eolt_image == OMEGA)            {                sprintf(msg_line,                        "Illegal aliasing to EOL prior to its "                        "definition. Line %d, column %d",                        SYM3.start_line, SYM3.start_column);                PRNTERR(msg_line);                exit(12);            }            image = eolt_image;            break;        default: /* if SYM3.kind == symbol */            image = symbol_image(SYM3.name);            break;    }    switch(SYM1.kind)    {        case SYMBOL_TK:            if (symbol_image(SYM1.name) != OMEGA)            {                restore_symbol(tok_string, SYM1.name);                sprintf(msg_line,                        "Symbol %s was previously defined. "                        "Line %d, column %d", tok_string,                        SYM1.start_line, SYM1.start_column);                PRNTERR(msg_line);                exit(12);            }            assign_symbol_no(SYM1.name, image);            break;        case ERROR_SYMBOL_TK:            if (error_image > num_terminals || ! error_maps_bit)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -