From b24f61a465d21af404ed647a977160042017e601 Mon Sep 17 00:00:00 2001 From: Ryo Nihei Date: Sat, 5 Nov 2022 14:21:13 +0900 Subject: Remove alias system Remove unimportant features to tidy up the specification. --- README.md | 39 ++++++++++++--------------------------- 1 file changed, 12 insertions(+), 27 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index 9997232..568190f 100644 --- a/README.md +++ b/README.md @@ -40,14 +40,14 @@ expr | func_call | int | id - | '(' expr ')' #ast expr + | l_paren expr r_paren #ast expr ; func_call - : id '(' args ')' #ast id args - | id '(' ')' #ast id + : id l_paren args r_paren #ast id args + | id l_paren r_paren #ast id ; args - : args ',' expr #ast args... expr + : args comma expr #ast args... expr | expr ; @@ -65,6 +65,12 @@ mul : '*'; div : '/'; +l_paren + : '('; +r_paren + : ')'; +comma + : ','; ``` Save the above grammar to a file in UTF-8. In this explanation, the file name is `expr.vartan`. @@ -216,11 +222,7 @@ func printSyntaxError(w io.Writer, synErr *SyntaxError, gram Grammar) { msg = fmt.Sprintf("'%v' ()", string(tok.Lexeme())) default: if term := gram.Terminal(tok.TerminalID()); term != "" { - if alias := gram.TerminalAlias(tok.TerminalID()); alias != "" { - msg = fmt.Sprintf("'%v' (%v)", string(tok.Lexeme()), alias) - } else { - msg = fmt.Sprintf("'%v' (%v)", string(tok.Lexeme()), term) - } + msg = fmt.Sprintf("'%v' (%v)", string(tok.Lexeme()), term) } else { msg = fmt.Sprintf("'%v'", string(tok.Lexeme())) } @@ -263,7 +265,7 @@ expr ```sh $ echo -n 'foo+99?' | go run . -1:7: unexpected token: '?' (): expected: , +, -, *, / +1:7: unexpected token: '?' (): expected: , add, sub, mul, div exit status 1 ``` @@ -435,23 +437,6 @@ See [Error recovery](#error-recovery) section for more details on the `#recover` ### Directives for terminal symbols -#### `#alias ` - -An `#alias` directive aliases for a terminal symbol. You can use the alias in error messages, for example. - -example: - -``` -#name example; - -s - : id - ; - -id #alias 'identifier' - : "[A-Za-z_][0-9A-Za-z_]*"; -``` - #### `#mode {}`, `#push `, and `#pop` A terminal symbol with a `#mode` directive is recognized only on a specified mode (`mode-name`). The mode is lexer state, which a `#push` directive and a `#pop` directive can switch. -- cgit v1.2.3