No more newlines (use . DOT as delimiter).

This commit is contained in:
Stefano Sanfilippo 2014-11-23 20:45:44 +01:00
parent d86f72eec3
commit 95087c6e7e
2 changed files with 10 additions and 9 deletions

View File

@ -16,7 +16,6 @@ CHAR [a-zA-Z_]
%% %%
("\r\n"|"\n") { ("\r\n"|"\n") {
lineNumber += 1; lineNumber += 1;
return NEWLINE;
} }
"bituma"[^\n]* {} "bituma"[^\n]* {}
@ -146,6 +145,9 @@ CHAR [a-zA-Z_]
"O scherziamo?" { "O scherziamo?" {
return CASE_END; return CASE_END;
} }
"." {
return DOT;
}
[ \t\f\v] {} [ \t\f\v] {}

View File

@ -14,14 +14,13 @@ extern void emit(const char *, ...);
%token MAIN %token MAIN
%token RETURN %token RETURN
%token NEWLINE
%token ARTICLE TYPENAME STAR %token ARTICLE TYPENAME STAR
%token VARDECL ASSIGN %token VARDECL ASSIGN
%token PRINT INPUT %token PRINT INPUT
%token ASSERT_BEGIN ASSERT_END %token ASSERT_BEGIN ASSERT_END
%token LOOP_BEGIN LOOP_CONDITION %token LOOP_BEGIN LOOP_CONDITION
%token BRANCH_CONDITION BRANCH_BEGIN BRANCH_ELSE BRANCH_END CASE_END %token BRANCH_CONDITION BRANCH_BEGIN BRANCH_ELSE BRANCH_END CASE_END
%token COLON COMMA LCURL RCURL %token COLON COMMA LCURL RCURL DOT
%token FUNDECL PARAMS FUNCALL %token FUNDECL PARAMS FUNCALL
%token ABORT %token ABORT
%token ID NUMBER FLOAT %token ID NUMBER FLOAT
@ -50,7 +49,7 @@ fun_decls:
/* epsilon */ | fun_decls fun_decl /* epsilon */ | fun_decls fun_decl
; ;
fun_decl: fun_decl:
FUNDECL ID args LCURL statements RCURL NEWLINE FUNDECL ID args LCURL statements RCURL
; ;
args: args:
/* epsilon */ | PARAMS arglist /* epsilon */ | PARAMS arglist
@ -59,11 +58,10 @@ arglist:
ID | ID COMMA arglist ID | ID COMMA arglist
; ;
main: main:
MAIN NEWLINE statements MAIN statements
; ;
statements: statements:
NEWLINE | statements statement NEWLINE /* epsilon */ | statements statement DOT
;
statement: statement:
var_decl | assign_stmt | print_stmt | input_stmt | return_stmt | var_decl | assign_stmt | print_stmt | input_stmt | return_stmt |
loop_stmt | branch_stmt | fun_call | abort_stmt | assert_stmt | loop_stmt | branch_stmt | fun_call | abort_stmt | assert_stmt |
@ -106,13 +104,14 @@ branch_stmt:
; ;
branch_body: branch_body:
cases %prec LOWER_THAN_ELSE | cases %prec LOWER_THAN_ELSE |
cases BRANCH_ELSE COLON NEWLINE statements cases BRANCH_ELSE COLON statements
; ;
cases: cases:
case_stmt | case_stmt cases case_stmt | case_stmt cases
; ;
case_stmt: case_stmt:
expression COLON NEWLINE statements CASE_END expression COLON statements CASE_END
;
; ;
fun_call: fun_call:
FUNCALL ID args FUNCALL ID args