文法

下は、フォーマルな文法です。
stmtsは、stmt 行の集合です。 stmtは、3種類のfor ステートメントまたは、function_stmtまたは、 COMMENTまたは print_stmtからなります。
赤字は、予約語です。大文字は、レキサ(字句切り出し器)からの識別子を表しています。

また、下記は、構文上の文法です。構文上は許されても、意味解析上は許されないところもあります。それらは、出来る限り指摘するようにしましたが、十分ではないと思います。一番確実なのは、既にサンプルで使っている記述をそのまま流用することです。


stmts:
stmt
| stmts stmt


stmt:
for_stmt
| for_inc_stmt
| for_inc_stmt2
| function_stmt
| COMMENT
| print_stmt



stmts_if:
stmt_if
| stmts_if stmt_if


stmt_if:
stmt
| if_stmt
| pushback_stmt


elsif_stmts:
elsif_stmt
| elsif_stmts elsif_stmt

elsif_stmt:
elsif ( operation ) { stmts_if }
| elsif ( operation ) { }
| elsif ( and_or_operation ) { stmts_if }
| elsif ( and_or_operation ) { }

if_op:
if ( operation ) { stmts_if }
| if ( operation ) { }
| if ( and_or_operation ) { stmts_if }
| if ( and_or_operation ) { }



if_stmt:
if_op
| if_op else { stmts_if }
| if_op else { }
| if_op elsif_stmts
| if_op elsif_stmts else { stmts_if }
| if_op elsif_stmts else { }



optype:
==
| !=
| >
| <
| >=
| <=

optypei:
optype
| in


primary_left:
UID
| UID + UID
| UID + NUM
| UID - NUM
| UID [ UID ]
| UID [ UID ] + UID
| UID [ UID ] + NUM
| UID [ UID ] - NUM
| UID [ UID + NUM ]
| UID [ UID - NUM ]
| UID [ UID + NUM ] + UID
| UID [ UID - NUM ] + UID
| UID [ UID + NUM ] + NUM
| UID [ UID - NUM ] + NUM
| UID [ UID + NUM ] - NUM
| UID [ UID - NUM ] - NUM



| UID . size ( )
| UID . size ( ) + NUM
| UID . size ( ) - NUM



primary_right:
NUM
| - NUM
| primary_left

operation:
primary_left optypei primary_right

and_or_operation:
operation && operation
| operation || operation
| and_or_operation && operation
| and_or_operation || operation

decl:
vector uid_list ;
| vector uid_list ; COMMENT

decls:
decl
| decls decl

uid_list:
UID
| uid_list , UID

for_inc_stmt2:
for ( UID = NUM to UID . size ( )- NUM ) { stmts_if }
| decls for ( UID = NUM to UID . size ( ) - NUM ) { stmts_if }

for_inc_stmt:
for( UID = NUM to NUM ) { stmts_if }
| for( UID = - NUM to NUM ) { stmts_if }
| for ( UID = - NUM to- NUM ) { stmts_if }
| decls for ( UID = NUM to NUM ) { stmts_if }
| decls for ( UID = - NUM to NUM ) { stmts_if }
| decls for ( UID = - NUM to - NUM ) { stmts_if }

for_stmt:
for ( UID in UID ) { stmts_if }
| decls for ( UID in UID ) { stmts_if }





print_item:
STRING
| UID
| UID . size ( )




print_list:
print_item
| print_list , print_item






print_stmt:
print ( print_list ) ;






function_stmt:
ufunction ;
| UID : ufunction ;
| UID : COMMENT ufunction ;
| NUM : COMMENT ufunction ;
| NUM : ufunction ;



pushback_stmt:
UID . pushback ( ufunction ) ;
| UID . pushback ( U_shift ) ;
| UID . pushback ( ! U_shift ) ;
| UID . pushfront ( ufunction ) ;
| UID . pushfront ( U_shift ) ;
| UID . pushfront ( ! U_shift ) ;
| UID . pushfront ( ) ;
| UID . popback ( ) ;
| UID . clear ( );

ufunction:
FUNCID ( uexpr_list )

uexpr_list:
uexpr
| uexpr_list , uexpr

uexpr:
ufunction
| U_shift
| NUM
| UID


ushift_sub:
[ UID ]
| [ UID + NUM ]
| [ UID - NUM ]
| [ UID + UID ]
| [ UID - UID ]
| [ UID [ UID ] ]
| [ UID [ UID ] + NUM ]
| [ UID [ UID ] - NUM ]
| [ UID [ UID + NUM ] ]
| [ UID [ UID + NUM ] + NUM ]
| [ UID [ UID + NUM ] - NUM ]
| [ UID [ UID - NUM ] ]
| [ UID [ UID - NUM ] + NUM ]
| [ UID [ UID - NUM ] - NUM ]



U_shift:
UID ushift_sub ushift_sub ushift_sub

[Index] [Home]