parser

Написать ответ на текущее сообщение

 

 
   команды управления поиском

Parser3 Grammar

Александр Петросян (PAF) 03.11.2005 13:33 / 03.11.2005 13:37

подумалось, что кому-то может быть интересна грамматика, описанная формальным языком.
(исходный файл: compile.y)


all: one_big_piece
| methods

methods: method
| methods method

one_big_piece: maybe_codes

method: control_method
| code_method

control_method: '@' STRING '\n' maybe_control_strings

maybe_control_strings: empty
| control_strings

control_strings: control_string
| control_strings control_string

control_string: maybe_string '\n'

maybe_string: empty
| STRING

code_method: '@' STRING bracketed_maybe_strings maybe_bracketed_strings maybe_comment '\n' maybe_codes

maybe_bracketed_strings: empty
| bracketed_maybe_strings

bracketed_maybe_strings: '[' maybe_strings ']'

maybe_strings: empty
| strings

strings: STRING
| strings ';' STRING

maybe_comment: empty
| STRING

maybe_codes: empty
| codes

codes: code
| codes code

code: write_string
| action

action: get
| put
| call

get: get_value

get_value: '$' get_name_value

get_name_value: name_without_curly_rdive EON
| name_in_curly_rdive

name_in_curly_rdive: '{' name_without_curly_rdive '}'

name_without_curly_rdive: name_without_curly_rdive_read
| name_without_curly_rdive_class

name_without_curly_rdive_read: name_without_curly_rdive_code

name_without_curly_rdive_class: class_prefix name_without_curly_rdive_code

name_without_curly_rdive_code: name_advance2
| name_path name_advance2

put: '$' name_expr_wdive construct

name_expr_wdive: name_expr_wdive_root
| name_expr_wdive_write
| name_expr_wdive_class

name_expr_wdive_root: name_expr_dive_code

name_expr_wdive_write: '.' name_expr_dive_code

name_expr_wdive_class: class_prefix name_expr_dive_code

construct: construct_square
| construct_round
| construct_curly

construct_square: '[' any_constructor_code_value ']'

construct_round: '(' expr_value ')'

construct_curly: '{' maybe_codes '}'

any_constructor_code_value: void_value
| STRING
| constructor_code_value

constructor_code_value: constructor_code

constructor_code: codes__excluding_sole_str_literal

codes__excluding_sole_str_literal: action
| code codes

call: call_value

call_value: '^' call_name store_params EON

call_name: name_without_curly_rdive

store_params: store_param
| store_params store_param

store_param: store_square_param
| store_round_param
| store_curly_param

store_square_param: '[' store_code_param_parts ']'

store_round_param: '(' store_expr_param_parts ')'

store_curly_param: '{' store_curly_param_parts '}'

store_code_param_parts: store_code_param_part
| store_code_param_parts ';' store_code_param_part

store_expr_param_parts: store_expr_param_part
| store_expr_param_parts ';' store_expr_param_part

store_curly_param_parts: store_curly_param_part
| store_curly_param_parts ';' store_curly_param_part

store_code_param_part: code_param_value

store_expr_param_part: expr_value

store_curly_param_part: maybe_codes

code_param_value: void_value
| STRING
| constructor_code_value

name_expr_dive_code: name_expr_value
| name_path name_expr_value

name_path: name_step
| name_path name_step

name_step: name_advance1 '.'

name_advance1: name_expr_value

name_advance2: name_expr_value
| STRING BOGUS

name_expr_value: STRING
| name_expr_subvar_value
| name_expr_with_subvar_value
| name_square_code_value

name_expr_subvar_value: '$' subvar_ref_name_rdive

name_expr_with_subvar_value: STRING subvar_get_writes

name_square_code_value: '[' codes ']'

subvar_ref_name_rdive: STRING

subvar_get_writes: subvar__get_write
| subvar_get_writes subvar__get_write

subvar__get_write: '$' subvar_ref_name_rdive

class_prefix: class_static_prefix
| class_constructor_prefix

class_static_prefix: STRING ':'

class_constructor_prefix: class_static_prefix ':'

expr_value: expr

expr: double_or_STRING
| get_value
| call_value
| '"' string_inside_quotes_value '"'
| ''' string_inside_quotes_value '''
| '(' expr ')'
| '-' expr
| '+' expr
| '~' expr
| '!' expr
| "def" expr
| "in" expr
| "-f" expr
| "-d" expr
| expr '-' expr
| expr '+' expr
| expr '*' expr
| expr '/' expr
| expr '%' expr
| expr '\\' expr
| expr "<<" expr
| expr ">>" expr
| expr '&' expr
| expr '|' expr
| expr "!|" expr
| expr "&&" expr
| expr "||" expr
| expr "!||" expr
| expr '<' expr
| expr '>' expr
| expr "<=" expr
| expr ">=" expr
| expr "==" expr
| expr "!=" expr
| expr "lt" expr
| expr "gt" expr
| expr "le" expr
| expr "ge" expr
| expr "eq" expr
| expr "ne" expr
| expr "is" expr

double_or_STRING: STRING

string_inside_quotes_value: maybe_codes

write_string: STRING

void_value: /* empty */

empty: /* empty */