/ * Below is Yacc Grammer source for ANSI C * // * YACC - LALR (1) PARSER * /% token IDENTIFIER CONSTANT STRING_LITERAL SIZEOF% token PTR_OP INC_OP DEC_OP LEFT_OP RIGHT_OP LE_OP GE_OP EQ_OP NE_OP% token AND_OP OR_OP MUL_ASSIGN DIV_ASSIGN MOD_ASSIGN ADD_ASSIGN% token SUB_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN% token XOR_ASSIGN OR_ASSIGN TYPE_NAME% token TYPEDEF EXTERN STATIC AUTO REGISTER% token CHAR SHORT INT LONG SIGNED UNSIGNED FLOAT DOUBLE CONST VOLATILE VOID% token STRUCT UNION ENUM eLIPSIS RANGE% token CASE DEFAULT IF ELSE SWITCH WHILE DO FOR GOTO CONTINUE BREAK RETURN% start file %% primary_expr: identifier | CONSTANT | STRING_LITERAL | '(' expr ')'; postfix_expr: primary_expr | postfix_expr '[' expr ']' | postfix_expr '(' ')' | postfix_expr '(' argument_expr_list ') '| postfix_expr' 'identifier | postfix_expr PTR_OP identifier | postfix_expr INC_OP | postfix_expr DEC_OP; argument_expr_list: assignment_expr | argument_expr_list'., 'assignment_expr; unary_expr: postfix_expr | INC_OP unary_expr | DEC_OP unary_exp R | Unary_operator, (') (' Type_name ')'; Unary_Operator: '&' | '*' | ' ' | '-' | '~' | '!'; CAST_EXPR: UNARY_EXPR | '(' type_name ')' cast_expr; multiplicative_expr: cast_expr | multiplicative_expr '*' cast_expr | multiplicative_expr '/' cast_expr | multiplicative_expr '%' cast_expr; additive_expr: multiplicative_expr | additive_expr ' ' multiplicative_expr | additive_expr '-' multiplicative_expr; shift_expr: additive_expr | shift_expr LEFT_OP Additive_EXPR | Shift_expr Right_OP Additive_EXPR;
relational_expr: shift_expr | relational_expr '<' shift_expr | relational_expr '>' shift_expr | relational_expr LE_OP shift_expr | relational_expr GE_OP shift_expr; equality_expr: relational_expr | equality_expr EQ_OP relational_expr | equality_expr NE_OP relational_expr; and_expr: equality_expr | and_expr '&' equality_expr; exclusive_or_expr: and_expr | exclusive_or_expr '^' and_expr; inclusive_or_expr: exclusive_or_expr | inclusive_or_expr '|' exclusive_or_expr; logical_and_expr: inclusive_or_expr | logical_and_expr AND_OP inclusive_or_expr; logical_or_expr: logical_and_expr | logical_or_expr OR_OP logical_and_expr; conditional_expr: logical_or_expr | logical_or_expr logical_or_expr ':' conditional_expr; assignment_expr: conditional_expr | '?' unary_expr assignment_operator assignment_expr; assignment_operator: '=' | MUL_ASSIGN | DIV_ASSIGN | MOD_ASSIGN | ADD_ASSIGN | SUB_ASSIGN | LEFT_ASSIGN | RIGHT_ASSIGN | AND_ASSIGN | XOR_ASSIGN | OR_ASSIGN; expr: assignment_expr | expr ',' assignment_expr; constant_expr: conditio nal_expr; declaration: declaration_specifiers ';' | declaration_specifiers init_declarator_list ';'; declaration_specifiers: storage_class_specifier | storage_class_specifier declaration_specifiers | type_specifier | type_specifier declaration_specifiers; init_declarator_list: init_declarator | init_declarator_list ',' init_declarator; init_declarator: declarator | declarator '=' initializer; storage_class_specifier: TYPEDEF | Extern | static | auto | register; type_specifier: char | short | int | long | sign | unsigned | float | double | const | volatile | void | struct_or_union_specifier | ENUM_SPECIFIER | TYPE_NAME;
struct_or_union_specifier: struct_or_union identifier '{' struct_declaration_list '}' | struct_or_union '{' struct_declaration_list '}' | struct_or_union identifier; struct_or_union: STRUCT | UNION; struct_declaration_list: struct_declaration | struct_declaration_list struct_declaration; struct_declaration: type_specifier_list struct_declarator_list ';'; struct_declarator_list: struct_declarator | struct_declarator_list ',' struct_declarator; struct_declarator: declarator | ':' constant_expr | declarator ':' constant_expr; enum_specifier: ENUM '{' enumerator_list '}' | ENUM identifier '{' enumerator_list '}' | ENUM identifier; enumerator_list: enumerator | enumerator_list ' , 'enumerator; enumerator: identifier | identifier' = 'constant_expr; declarator: declarator2 | pointer declarator2; declarator2: identifier |' ( 'declarator') '| declarator2' [ ''] '| declarator2' [ 'constant_expr'] '| DECLARATOR2 '(') '| DECLARATOR2' ('parameter_type_list') '| DECLARATOR2' ('parameter_identifier_list') '; Pointe r: '*' | '*' type_specifier_list | '*' pointer | '*' type_specifier_list pointer; type_specifier_list: type_specifier | type_specifier_list type_specifier; parameter_identifier_list: identifier_list | identifier_list ',' ELIPSIS; identifier_list: identifier | identifier_list ',' identifier; parameter_type_list : parameter_list | parameter_list ',' Elipsis; parameter_list: parameter_declaration | parameter_list ',' parameter_Declaration;
parameter_declaration: type_specifier_list declarator | type_name; type_name: type_specifier_list | type_specifier_list abstract_declarator; abstract_declarator: pointer | abstract_declarator2 | pointer abstract_declarator2; abstract_declarator2: '(' abstract_declarator ')' | '[' ']' | '[' constant_expr ']' | abstract_declarator2 ' [ ''] '| abstract_declarator2' [ 'constant_expr'] '|' ( '') '|' ( 'parameter_type_list') '| abstract_declarator2' ( '') '| abstract_declarator2' ( 'parameter_type_list') '; initializer: assignment_expr | '{' initializer_list '}' | '{' initializer_list ',' '}'; initializer_list: initializer | initializer_list ',' initializer; statement: labeled_statement | compound_statement | expression_statement | selection_statement | iteration_statement | jump_statement; labeled_statement: identifier ':' statement | CASE constant_expr ':' statement | DEFAULT ':' statement; compound_statement: '{' '}' | '{' statement_list '}' | '{' declaration_list '}' | '{' declaration_list statement_list '} '; Declaration_list: declaration | declaration_list declaration; statement_list: statement | statement_list statement; expression_statement:'; '| expr'; '; selection_statement: IF' ( 'expr') 'statement | IF' ( 'expr') 'statement ELSE statement | Switch '(' expr ')' statement; iprosis_statement: while '(' expr ')' Statement | Do Statement While '(' expr ')' ';' | for '
(''; ''; ')' Statement | FOR '(' ';'; ')' Statement | for '(' ';'; ';' ')' Statement | for '(' ' ; 'expr'; 'expr') 'statement | for' ('expr'; ''; ')' Statement | FOR '(' expr ';' ';' expr ')' Statement | for '(' expr ';' expr ';' ')' Statement | For '(' expr ';' expr ';' expr ')' Statement; Jump_Statement: goto Identifier ';' | Continue ';' | Break ';' | Return ' ; '| RETURN expr'; '; file: external_definition | file external_definition; external_definition: function_definition | declaration; function_definition: declarator function_body | declaration_specifiers declarator function_body; function_body: compound_statement | declaration_list compound_statement; identifier: IDENTIFIER; %% # include
{Count ();} "Continue" {count (); return (continue);} "default" {count (); return (default);} "do" {count (); return (Do " "}" Double "{count (); return (double);} {count (); return (else);}" enum "{count (); return (enum);}" extern "{Count ();} "float" {count (); return (float);} "for" {count (); return (for);} "goto" {count (); return (goto); } "if" {count (); return (if);} "int" {count (); return (int);} "long" {count (); return (long);} "register" {count () Return (register);} "Return" {count (); return (return);} "short" {count (); return (short);} "signed" {count (); returnid;} "{count (); return (sizeof);} {count (); return (static);}} {count (); return (struct);}}" switch "{count (); return (Switch);} "typef" {count (); return (typef);} "union" {count (); return (union);} "unsigned" {count (); returnid;} "void" {count (); Return (Void);} "volatile" {count (); return (volatile);} "while" {count ();}} {l} ({l} | {d}) * {count (); recn (check_type ());} 0 [xx] {h} {is}? { Count (); return (constant);} 0 [xx] {h} {is}? {count (); return (constant);} 0 {d} {is}? {count (); return (constant) );} 0 {d} {is}? {Count (); return (constant);} {d} {d}} {count (); return (constant);} {D} {is}? {Count ();} '(//. | [^ //']) '{count (); return (constant);} {d} {e} {fs}? {count (); return (constant);} {D} * "."
{D} ({E})? {Fs}? {Count (); return (constant);} {D} "." {D} * ({E})? {Fs}? {Count () Return (constant);} / "(//. | {count (); return (string_literal);}" >> = "{count (); return (right_assign); } "<< =" {count (); return (left_assign);} " =" {count (); return (add_assign);} "- =" {count (); return (sub_assign);} "* = "{Count ();}" / = "{count (); return (div_assign);}"% = "{count (); return (mod_assign);}" & = "{count () Return (and_assign);} "^ =" {count (); return (xor_assign);} "| =" {count (); return (or_assign);} ">>" {count (); return (Right_OP) } "<<" {count (); return (left_op);} " " {count (); return (inc_OP);} "- {count (); return (dec_op);} -> "{Count (); Return (PTR_OP);}" && "{count (); return (and_op);}" || "{count (); return (or_op);}" <= "{count (); Return (le_op);} "> =" {count (); return (ge_op);} "==" {count (); return (eq_op);} "! =" {count (); return (ne_op); } ";" {Count (); return (';');} "{" {count (); return ( '{');} "}" {Count (); return ('}');} "," {count (); return (',');}: "{count (); Return (': ');} "=" {Count (); return (' = ');} "(" {count (); return (');} ") {count (); return (')') } "[" {Count (); return ('[');} "] {count (); return (']');}". "
{count (); return ('.');} "&" {count (); return ('&');} "!" {count (); return ('!');} "~" {count (); RETURN ('~');} "-" {count (); return ('-');} " " {count (); return (' ');} "*" {count () Return ('*');} "/" {count (); return ('/');} "%" {count (); return ('%');} "<" {count (); return ('<');} ">" {Count (); return ('>');} "^" {count (); return ('^');} "| {count (); return (' | ');} "?" {Count (); RETURN ('? ');} [/ T / v / n / f] {count ();}. {/ * Ignore bad characters * /} %% YYWRAP () {RETURN (1);} comment () {Char C, C1; loop: while ((c = INPUT ())! = '*' && c! = 0) PUTCHAR (C); if (((c1 = INPUT ())! = '/' && c! = 0) {UNPUT (C1); goto loop;} IF (c! = 0) PUTCHAR (C1);} int colorn = 0; void count () {INT i ; for (i = 0; yytext [i]! = '/ 0'; i ) IF (YYTEXT [i] == '/ n') column = 0; Else IF (YYTEXT [I] == '/ t' ) Column = 8 - (Column% 8); Else Column ; echo;} int check_type () {/ ** pseudo code --- this is what it Should Check ** if (YYTEXT == Type_name) * Return (Type_name ** return (Identifier); * // ** IT Actually Will Only Return Identifier * / Return (Identifier);} / Rogue / Monster / Else Echo "Will NOT OVER WRITE ./scan.l "fiif` Test! -s ./y.tab.h`thenecho "Writting. /y.tab.h"cat> ./y.tab.h << '/ rogue / monster /'