added a lot to parser
git-svn-id: svn://anubis/jtlc/trunk@4 f5bc74b8-7b62-4e90-9214-7121d538519f
This commit is contained in:
parent
f8b1248c72
commit
57c9bbbbea
@ -80,8 +80,54 @@ int yywrap()
|
||||
|
||||
%%
|
||||
|
||||
program: INT_LITERAL
|
||||
;
|
||||
program_items: /* empty */
|
||||
| program_item program_items
|
||||
;
|
||||
|
||||
program_item: module_declaration
|
||||
| import
|
||||
| variable_declaration
|
||||
| function
|
||||
;
|
||||
|
||||
module_declaration: MODULE module_name SEMICOLON
|
||||
;
|
||||
|
||||
module_name: IDENTIFIER module_name_more
|
||||
;
|
||||
|
||||
module_name_more: /* empty */
|
||||
| DOT IDENTIFIER module_name_more
|
||||
;
|
||||
|
||||
import: IMPORT import_name SEMICOLON
|
||||
;
|
||||
|
||||
import_name: IDENTIFIER import_name_more
|
||||
;
|
||||
|
||||
import_name_more: /* empty */
|
||||
| DOT import_name_more_more
|
||||
;
|
||||
|
||||
import_name_more_more: IDENTIFIER import_name_more
|
||||
| STAR
|
||||
;
|
||||
|
||||
function: type IDENTIFIER LPAREN parameter_list RPAREN LCURLY function_items RCURLY
|
||||
;
|
||||
|
||||
function_items: /* empty */
|
||||
| statement function_items
|
||||
;
|
||||
|
||||
parameter_list: /* empty */
|
||||
| variable_spec parameter_list_more
|
||||
;
|
||||
|
||||
parameter_list_more: /* empty */
|
||||
| COMMA variable_spec parameter_list_more
|
||||
;
|
||||
|
||||
primitive_type: BYTE
|
||||
| UBYTE
|
||||
@ -106,17 +152,38 @@ struct_item: variable_declaration
|
||||
variable_declaration: variable_spec SEMICOLON;
|
||||
;
|
||||
|
||||
variable_spec: IDENTIFIER COLON type
|
||||
variable_spec: type IDENTIFIER
|
||||
;
|
||||
|
||||
ptr_type: type STAR
|
||||
;
|
||||
|
||||
array_type: type LBRACKET RBRACKET
|
||||
;
|
||||
|
||||
type: primitive_type
|
||||
| ptr_type
|
||||
| struct_type
|
||||
| array_type
|
||||
| IDENTIFIER
|
||||
;
|
||||
|
||||
statement: expression SEMICOLON
|
||||
| return_statement SEMICOLON
|
||||
;
|
||||
|
||||
return_statement: RETURN expression
|
||||
;
|
||||
|
||||
expression: assign_expr
|
||||
;
|
||||
|
||||
assign_expr: lvalue ASSIGN expression
|
||||
;
|
||||
|
||||
lvalue: IDENTIFIER
|
||||
;
|
||||
|
||||
%%
|
||||
|
||||
void parse(const char * fileName)
|
||||
|
Loading…
x
Reference in New Issue
Block a user