Mercurial > ~dholland > hg > ag > index.cgi
diff tests/agcl/oldagsrc/cf-old.syn @ 0:13d2b8934445
Import AnaGram (near-)release tree into Mercurial.
author | David A. Holland |
---|---|
date | Sat, 22 Dec 2007 17:52:45 -0500 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/agcl/oldagsrc/cf-old.syn Sat Dec 22 17:52:45 2007 -0500 @@ -0,0 +1,698 @@ +{/* + AnaGram Syntax Analyzer. + Copyright (c) Parsifal Software, 1993. + All Rights Reserved. + + Configuration file module +*/ +#include HEADERS + +#include DATA +#include ASSERT +#include CTYPE +#include STDLIB +#include STRING +#include ARRAYS +#include MYALLOC +#include CF +#include PARAMS +#include PF + +} +[ + auto resynch + context type = cint + grammar token = config file + ~declare pcb + diagnose errors +// enum constant name = "cf_%_token" + lines and columns + line numbers + ~allow macros + line numbers + error frame + nest comments + ~test range + token names + pointer input + default token type = int + near functions +] + +any digit = digit + hex letter +backslash = '\\' +blank char = ' ' + '\t' +carriage return = '\r' +digit = '0-9' +double quote = '"' +eof = 0 + 26 +eol chars = newline + carriage return +hex letter = 'a-f' + 'A-F' +letter = 'a-z' + 'A-Z' + '_' +newline = '\n' +nonoctal digit = any digit - octal digit +octal digit = '0-7' +simple string char = ~eof - (any digit + double quote + backslash + eol chars) +tab = '\t' +vertical space = '\f' + '\v' + +equals + -> '=', space? + +minus + -> '-', space? + +plus + -> '+', space? + +tilde + -> '~', space? +/* +left bracket + -> '[', space? + +right bracket + -> ']', blank?... +*/ +left parenthesis + -> '(', space? + +right parenthesis + -> ')', blank?... + + +config file + -> blank?..., [global parameter | end of line]/..., eof + +(void) global parameter + -> name =cf_gp4(1); + -> tilde, name =cf_gp4(0); + -> name, equals, data type =cf_gp2(); + -> name, equals, keyword string =cf_gp3(); + -> name, equals, number:n =cf_gp5(n); + -> "trial", blank..., "copy", blank..., "code", blank?..., equals, + trial copy code:n =trial_copy_code = n; + +(unsigned long) trial copy code + -> '0-9':d =d-'0'; + -> trial copy code:n, '0-9':d =10*n + d-'0'; + +(void) data type + -> name + -> name, abstract declarator =concat_string(); + +(void) abstract declarator + -> indirect data type + -> direct abstract declarator + -> indirect data type, direct abstract declarator =concat_string(); + + +(void) direct abstract declarator + -> {left parenthesis =scs('('),0;}, abstract declarator, + right parenthesis =concat_string(), acs(')'); +/* + -> brackets + -> direct abstract declarator, brackets =concat_string(); + +(void) brackets + -> left bracket, right bracket =sss("[]"); + -> left parenthesis, right parenthesis =sss("()"); +*/ + +(void) pointer + -> star + -> star, name =concat_string(); + +(void) star + -> '*', blank?... =sss(" *"); + +(void) indirect data type + -> pointer + -> indirect data type, pointer =concat_string(); + +(void) name string + -> letter:a =scs(a); + -> name string, letter + digit :a =acs(a); + -> name string, blank..., letter + digit :a =acs(' '), acs(a); + +name + -> name string, blank?... + +blank + -> blank char + -> c comment + +space + -> blank... + -> blank..., continuation + -> continuation + +continuation + -> comment, next line + -> next line + +next line + -> carriage return?, newline + -> carriage return?, newline, blank... + +white + -> blank + -> carriage return?, newline + -> comment, carriage return?, newline + +end of line + -> comment, carriage return?, newline + -> carriage return?, newline + -> end of line, white + -> end of line, vertical space //form feed + +comment + -> "//", ~eol chars & ~eof?... + +decimal number + -> '1-9':d =d - '0'; + -> decimal number:n, '0-9':d =10*n + d - '0'; + +octal number + -> '0' =0; + -> octal number:n, '0-7':d =8*n + d - '0'; + +hex number + -> "0x" =0; + -> "0X" =0; + -> hex number:n, '0-9':d =16*n + d - '0'; + -> hex number:n, 'A-F' + 'a-f':d =16*n + (d&7) + 9; + +simple number + -> decimal number + -> octal number + -> hex number + +number + -> sign:s, simple number:n, blank?... =s*n; + +sign + -> plus? =1; + -> minus =-1; + +keyword string + -> keyword string head, string, double quote, blank?... + +string + -> string A | string B | string C + +(void) keyword string head + -> double quote =ics(); + +string char + -> simple string char + -> escape sequence + +escape sequence + -> "\\a" ='\a'; + -> "\\b" ='\b'; + -> "\\f" ='\f'; + -> "\\n" ='\n'; + -> "\\r" ='\r'; + -> "\\t" ='\t'; + -> "\\v" ='\v'; + -> "\\\\" ='\\'; + -> "\\?" = '\?'; + -> "\\'" ='\''; + -> "\\\"" ='"'; + -> three octal:n =n==0?cf_error("Null character in string"),0 : n; + +one octal + -> backslash, '0-7':n =n&7; + +two octal + -> one octal:n, '0-7':d = n*8 + (d&7); + +three octal + -> two octal:n, '0-7':d = n*8 + (d&7); + +octal escape + -> {one octal | two octal}:n = + n==0?cf_error("Null character in string"),0 : n; + +hex escape + -> "\\x", hex number:n =n; + +(void) string A + -> string char:c =acs(c); + -> any digit:c =acs(c); + -> string, string char:c =acs(c); + -> string A, any digit:c =acs(c); + -> string B, nonoctal digit:c =acs(c); + +(void) string B + -> octal escape:n =acs(n); + -> string, octal escape:n =acs(n); + +(void) string C + -> hex escape:n =acs(n); + -> string, hex escape:n =acs(n); + +(void) c comment + -> c comment text, "*/" + +(void) c comment text + -> "/*" + -> c comment text, ~eof + +c comment, c comment text + -> c comment text, c comment = +{if (nest_comments) PCB.reduction_token = cf_c_comment_text_token;} + +[ + hidden { + left parenthesis, right parenthesis, + pointer, indirect data type, name string, + space, next line, sign, one octal, two octal, three octal, + string A, string B, string C, c comment text, escape sequence, + octal escape, hex escape, name string + } +] + +{ + +#define PARSE_STACK_OVERFLOW\ + {fprintf(stderr,"Parse stack overflow\n");myabort();} +#define SYNTAX_ERROR cf_syn_error() +#define GET_CONTEXT CONTEXT.x = PCB.column, CONTEXT.y = PCB.line + +#define N_PARAMS 80 + + +static cf_pcb_type cfcb; +#define PCB cfcb + +extern string_dict *param_dict; +extern unsigned char *input_base; +extern int precedence_level; +extern int int_token_type; + +void reset_stack(void); +void log_error(void); + +static void cf_gp2(void); +static void cf_gp3(void); +static void cf_gp4(int); +static void cf_gp5(int); + +void acs(int); +void scs(int); + +void init_params(void); + +unsigned char *read_file(char *); + +static char *config_file; + +static void cf_error(char *); + +static void cf_bad_param(int pn) { + char *dm; + if (pn) dm = "Inappropriate value"; + else dm = "No such parameter"; + cf_error(dm); + rcs(); + return; +} + +void xgp5(int, void bad(int), int); + +static void cf_gp5(int tv) { + xgp5(tv,cf_bad_param,0); +} + +void xgp4(int, void bad(int), int); + +static void cf_gp4(int tv) { + xgp4(tv,cf_bad_param,0); +} + +void xgp2(void bad(int), int); + +static void cf_gp2(void) { + xgp2(cf_bad_param,0); +} + +void xgp3(void bad(int), int); + +static void cf_gp3(void) { + xgp3(cf_bad_param,0); +} + +static int read_config_file(char *path) { + char* file_name = allocate(strlen(path)+20,char); + char *cp; + + strcpy(file_name, path); + cp = strrchr(file_name,PATH_DELIMITER); +/* + assert(cp != NULL); + strcpy(cp+1,"AnaGram.cfg"); +*/ + if (cp) cp++; + else cp = file_name; + strcpy(cp,"AnaGram.cfg"); + config_file = file_name; + cfcb.pointer = input_base = read_file(file_name); + return input_base != NULL; +} + +static void get_config(char *path) { + cfcb.pointer = input_base = read_file(path); + if (input_base != NULL) { + cf(); + free(input_base); + } + input_base = NULL; +} +int in_cur_dir(char *); + +void read_config(char *path) { + if (read_config_file(path)) { + cf(); + free(input_base); + free(config_file); + } + if (in_cur_dir(path)) return; + config_file = "AnaGram.cfg"; + get_config("anagram.cfg"); +} + +static void cf_error(char *msg) { + int eline = PCB.line, ecol = PCB.column; + + if (PCB.token_number == cf_eof_token) { + eline = ERROR_CONTEXT.y; + ecol = ERROR_CONTEXT.x; + } + ssprintf("%s, Line %d, Col %d: %s", config_file, + eline, ecol, msg); + log_error(); +} + +static void cf_syn_error(void) { + reset_stk(); + cf_error(PCB.error_message); +} + +param_number_map *map_param_number; + +static void init_param_val_proc(int *pn, char *name, int v) { + param_number_map *mpn; + + *pn = add_string_dict(name,param_dict); + check_size(map_param_number,*pn,*pn); + mpn = &map_param_number[*pn]; +/* mpn->value_name = 1; */ + mpn->value = v; +} + + +#define init_param_val(p,v) \ + init_param_val_proc(&p##_pn, #p,v) + +static param_number_map *id_param(int *pn, void *p, char *name) { + int k = add_string_dict(name,param_dict); + param_number_map *mpn; + + check_size(map_param_number, k,3*k/2); + *pn = k; + mpn = &map_param_number[k]; + mpn->param = p; + return mpn; +} + +#define init_param(p, global, implicit)\ + {param_number_map *mpn = id_param(&p##_pn,&p, #p);\ + mpn->global = 1;\ + mpn->implicit = 1;} + +#define init_param_co(p, global, implicit)\ + {param_number_map *mpn = id_param(&p##_pn,&p, #p);\ + mpn->global = mpn->config_only = 1;\ + mpn->implicit = 1;} + +/* +#define init_verb(p,param)\ + {param_number_map *mpn =\ + &map_param_number[p##_pn = add_string_dict(#p, param_dict)];\ + mpn->verb = 1;\ + mpn->value = param##_pn;} +*/ +/* +#define init_token_param(p,implicit)\ + {param_number_map *mpn =\ + &map_param_number[p##_pn = add_string_dict(#p, param_dict)];\ + mpn->token = 1;\ + mpn->implicit = 1;} +*/ + +#define init_dict_param(p,global,dict_name)\ + {param_number_map *mpn = id_param(&p##_pn,&p, #p);\ + mpn->global = 1;\ + mpn->dict = dict_name;\ + mpn->value_id = 1;} +/* +#define init_literal_param(p,global,first_value)\ + {param_number_map *mpn = id_param(&p##_pn,&p, #p);\ + mpn->value = first_value##_pn;\ + mpn->global = 1;\ + mpn->dict = param_dict;\ + mpn->literal = 1;} +*/ + +#define init_proc_param(p,global,proc_name)\ + {param_number_map *mpn = id_param(&p##_pn,&p, #p);\ + mpn->global = 1;\ + mpn->proc = proc_name;\ + mpn->proc_call = 1;} + +#define init_token_id_param(p,global)\ + {param_number_map *mpn = id_param(&p##_pn,&p, #p);\ + mpn->global = 1;\ + mpn->proc = name_token;\ + mpn->proc_call = 1;\ + mpn->token_id = 1;} + +#define dp(p)\ +static int p##_pn + +dp(on); +dp(off); + +extern int allow_macros; dp(allow_macros); + int auto_init = 1; dp(auto_init); + int auto_resynch = 0; dp(auto_resynch); +extern int backtrack; dp(backtrack); + int bottom_margin = 3; dp(bottom_margin); + int bright_background = 1; dp(bright_background); + + int case_sensitive = 1; dp(case_sensitive); + char *compile_command = ""; dp(compile_command); + char *context_type = NULL; dp(context_type); + char *coverage_file_name = "#.nrc"; dp(coverage_file_name); + + int declare_pcb = 1; dp(declare_pcb); +extern int default_input_type; dp(default_input_type); +extern int default_token_type; dp(default_token_type); +extern int default_reductions; dp(default_reductions); + int diagnose_errors = 1; dp(diagnose_errors); + +extern char *edit_command; dp(edit_command); + char *enum_constant_name = "$_%_token"; dp(enum_constant_name); + int error_frame = 0; dp(error_frame); + int error_trace = 0; dp(error_trace); + int escape_backslashes = 0; dp(escape_backslashes); + int event_driven = 0; dp(event_driven); + +extern int far_tables; dp(far_tables); + +extern int grammar_token; dp(grammar_token); +extern char *header_file_name; dp(header_file_name); + int input_values = 0; dp(input_values); + + int line_length = 80; dp(line_length); +extern int line_numbers; dp(line_numbers); + char *line_numbers_path = NULL; dp(line_numbers_path); +extern int lines_and_columns; dp(lines_and_columns); + + int main_program = 1; dp(main_program); + int max_conflicts = 50; dp(max_conflicts); + + int near_functions = 0; dp(near_functions); + int nest_comments = 0; dp(nest_comments); + + int old_style = 0; dp(old_style); + + int page_length = 66; dp(page_length); +extern char *parser_file_name; dp(parser_file_name); + char *parser_name = "#"; dp(parser_name); + int parser_stack_alignment; dp(parser_stack_alignment); + int parser_stack_size = 32; dp(parser_stack_size); + int pointer_input = 0; dp(pointer_input); + char *pointer_type = "unsigned char *"; dp(pointer_type); + char *print_file_name = "LPT1"; dp(print_file_name); + + int quick_reference = 1; dp(quick_reference); + + int reduction_choices =0; dp(reduction_choices); + int rule_coverage = 0; dp(rule_coverage); + + int tab_spacing = 8; dp(tab_spacing); + int test_file_binary = 0; dp(test_file_binary); + char *test_file_mask = "*.*"; dp(test_file_mask); +extern int test_range; dp(test_range); +extern int token_names; dp(token_names); + int top_margin = 3; dp(top_margin); +extern int traditional_engine; dp(traditional_engine); + +extern int video_mode; dp(video_mode); + + unsigned long trial_copy_code = 0; + + +/* char *note_file_name = "$.nf"; dp(note_file_name); */ + + char *input_type_name = "$_it_type"; /* dp(input_type_name); */ + + +char *control_block_type = "$_pcb_type"; +char *typedef_name = "$_token_type"; +char *value_stack_type = "$_vs_type"; + + +extern string_dict *cast_dict; +extern string_dict *proc_dict; + + +extern string_dict *tkn_dict; + +extern int error_token; dp(error_token); +/* extern int noise_token; dp(noise_token); */ +int eof_token = 0; dp(eof_token); + +extern int active_color; dp(active_color); +extern int active_bar_color; dp(active_bar_color); +extern int inactive_color; dp(inactive_color); +extern int inactive_bar_color; dp(inactive_bar_color); +extern int backdrop_color; dp(backdrop_color); +extern int backdrop_bar_color; dp(backdrop_bar_color); + + +int id_token(int); + +static int name_token(char *name){ + sss(name); + free(name); + ids(tkn_dict); + return id_token(fis()); +} + +void init_params(void) { + int n; + map_param_number = init_array(N_PARAMS,sizeof(param_number_map)); + + init_param_val(off, 0); + init_param_val(on, 1); + +/* + + N.B. The following list should be in alphabetical order. Make sure that + when you enter a new parameter, you enter it in the right place! + +*/ + init_param(allow_macros, global, implicit); + init_param(auto_init, global, implicit); + init_param(auto_resynch, global, implicit); + + init_param(backtrack, global, implicit); + init_param(bottom_margin, global, int_value); + init_param_co(bright_background, global, implicit); + + init_param(case_sensitive, global, implicit); + init_param(compile_command, global, string_value); + init_param(context_type, global, text_value); + init_param(coverage_file_name, global, string_value); + + init_param(declare_pcb, global,implicit); + init_dict_param(default_input_type, global, cast_dict); + init_param(default_reductions, global, implicit); + init_dict_param(default_token_type, global, cast_dict); + init_param(diagnose_errors, global, implicit); + + init_param(edit_command, global, string_value); + init_param(enum_constant_name, global, string_value); + init_token_id_param(eof_token, global); + init_param(error_frame, global, implicit); + init_token_id_param(error_token, global); + init_param(error_trace, global, implicit); + init_param(escape_backslashes, global, implicit); + init_param(event_driven, global, implicit); + + init_param(far_tables, global, implicit); + + init_token_id_param(grammar_token, global); + + init_param(header_file_name, global, string_value); + + init_param(input_values, global, implicit); + + init_param(line_length, global, int_value); + init_param(line_numbers, global, implicit); + init_param(line_numbers_path, global, string_value); + init_param(lines_and_columns, global, implicit); + + init_param(main_program, global, implicit); + init_param(max_conflicts, global, int_value); + + init_param(near_functions, global, implicit); + init_param(nest_comments, global, implicit); + + init_param(old_style, global, implicit); + + init_param(page_length, global, int_value); + init_param(parser_file_name, global, string_value); + init_param(parser_name, global, text_value); + init_dict_param(parser_stack_alignment, global, cast_dict); + init_param(parser_stack_size, global, int_value); + init_param(pointer_input, global, implicit); + init_param(pointer_type, global, text_value); + init_param(print_file_name, global, string_value); + + init_param(quick_reference, global, implicit); + + init_param(reduction_choices, global, implicit); + init_param(rule_coverage, global, implicit); + + init_param(tab_spacing, global, int_value); + init_param(test_file_binary, global, implicit); + init_param(test_file_mask, global, string_value); + init_param(test_range, global, implicit); + init_param(token_names, global, implicit); + init_param(top_margin, global, int_value); + init_param(traditional_engine, global, implicit); + init_param_co(video_mode, global, int_value); + + + + init_param_co(active_bar_color, global, color_value); + init_param_co(active_color, global, color_value); + init_param_co(backdrop_bar_color, global, color_value); + init_param_co(backdrop_color, global, color_value); + init_param_co(inactive_bar_color, global, color_value); + init_param_co(inactive_color, global, color_value); + + + n = param_dict->nsx; + assert(n < N_PARAMS); + map_param_number = set_array_size(map_param_number, n); +} +} + + +