Skip to content

Commit dbd3f2a

Browse files
committed
Allow omitting parenthesis on string functions.
This also makes the parser 2 bytes smaller.
1 parent c18a646 commit dbd3f2a

4 files changed

Lines changed: 17 additions & 17 deletions

File tree

manual.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -681,12 +681,13 @@ for example you can write `R.(10)`
681681
instead of `RAND(10)`.
682682

683683
You can also omit parentheses on
684-
functions that take one numerical value
685-
as argument, for example, `RAND 10`.
684+
functions that take only one argument,
685+
for example, `RAND 10`.
686+
686687
Note: This is not possible when the
687-
argument is a string (as with `ADR`),
688-
or the function accepts a variable number
689-
of arguments (as with `USR`).
688+
function accepts a variable number of
689+
arguments (as with `USR`), or with the
690+
`ADR` function.
690691

691692
Some functions don't take parameters,
692693
and you must provide a set of

src/syntax/basic.syn

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,9 @@ INT_FUNCTIONS: integer variable or function
182182
"USR(" EXPR emit TOK_USR_ADDR USR_EXPR_MORE ")" emit TOK_USR_CALL
183183
"ADR(" ADR_EXPR ")"
184184
"&" ADR_EXPR
185-
"Len" STR_PAR_EXPR emit TOK_PEEK # First byte of string is the length
186-
"Val" STR_PAR_EXPR emit TOK_VAL
187-
"ASc" STR_PAR_EXPR emit { TOK_PUSH_1, TOK_ADD, TOK_PEEK } # TODO: does not check for empty strings.
185+
"Len" STR_EXPR emit TOK_PEEK # First byte of string is the length
186+
"Val" STR_EXPR emit TOK_VAL
187+
"ASc" STR_EXPR emit { TOK_PUSH_1, TOK_ADD, TOK_PEEK } # TODO: does not check for empty strings.
188188

189189
# Used to handle PADDLE/STICK/PTRIG/STRIG
190190
RD_PORT:
@@ -193,9 +193,6 @@ RD_PORT:
193193
PAR_EXPR: left parenthesis
194194
"(" EXPR ")"
195195

196-
STR_PAR_EXPR: left parenthesis
197-
"(" STR_EXPR ")"
198-
199196
# Parses a continuation of an INT to BOOLean expression
200197
OR_AND_BOOL:
201198
OR_EXPR_RIGHT
@@ -265,8 +262,10 @@ COMP_EXPR_MORE:
265262

266263
# String expressions: base plus optional index
267264
STR_EXPR: string expression
265+
"(" STR_EXPR ")"
268266
STRING_FUNCTIONS OPT_STR_INDEX
269267

268+
270269
OPT_STR_INDEX:
271270
"[" emit TOK_PUSH EXPR C_EXPR "]" emit TOK_STR_IDX OPT_STR_INDEX
272271
"[" emit TOK_PUSH EXPR "]" emit { TOK_PUSH_BYTE, 255, TOK_STR_IDX } OPT_STR_INDEX
@@ -530,7 +529,7 @@ STATEMENT: statement
530529
"INC" VAR_WORD_LVALUE_SADDR emit TOK_INC
531530
"DEc" VAR_WORD_LVALUE_SADDR emit TOK_DEC
532531
"PRoc" E_LABEL_CREATE emit { TOK_JUMP } E_LABEL_DEF emit LT_PROC_2 E_PUSH_LT OPT_PROC_VAR
533-
"ENDProc" E_POP_PROC_2 emit TOK_RET E_POP_PROC_DATA
532+
"ENdproc" E_POP_PROC_2 emit TOK_RET E_POP_PROC_DATA
534533
EXEC_CALL E_LABEL_CREATE OPT_EXEC_PARAM emit { TOK_CALL } E_DO_EXEC
535534
"DAta" DATA_VAR DATA_END
536535
"END" emit TOK_END

src/syntax/float.syn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ FP_FUNCS:
8080
"SQr" FP_T_EXPR emit TOK_FP_SQRT
8181
"SIn" FP_T_EXPR emit TOK_FP_SIN
8282
"COs" FP_T_EXPR emit TOK_FP_COS
83-
"Val" STR_PAR_EXPR emit TOK_FP_VAL
83+
"Val" STR_EXPR emit TOK_FP_VAL
8484
"RNd()" emit TOK_FP_RND
8585
"%" PAR_EXPR emit TOK_FP_LOAD
8686

testsuite/tests/abbrev.bas

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ RA. ' RAD
129129
? LO.10 ' LOG10
130130
? SQ.4 ' SQR
131131
? COS0 ' COS
132-
? 0.0 + V.("0.1") ' VAL FP
132+
? 0.0 + V."0.1" ' VAL FP
133133
? RN.>=0.0 ' RND
134134

135135

@@ -154,9 +154,9 @@ P.$284,3
154154
' ? USR() ' USR (can't abbreviate)
155155
? ADR(R1)-ADR(R) ' ADR (can't abbreviate)
156156
? &R1-&R ' ADR
157-
? L.("123") ' LEN
158-
? V.("123") ' VAL
159-
? AS.("123") ' ASC
157+
? L."123" ' LEN
158+
? V."123" ' VAL
159+
? AS."123" ' ASC
160160

161161
? "OPER"
162162
? 1A.1;0A.1;0A.0 ' AND

0 commit comments

Comments
 (0)