Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Macro arguments in the middle of expressions. #63

Closed
yenatch opened this issue Mar 14, 2015 · 3 comments
Closed

Macro arguments in the middle of expressions. #63

yenatch opened this issue Mar 14, 2015 · 3 comments
Labels
bug Unexpected behavior / crashes; to be fixed ASAP! rgbasm This affects RGBASM

Comments

@yenatch
Copy link
Contributor

yenatch commented Mar 14, 2015

A__ = -1

test_1: macro
    db \1_\1_\1
endm

test_2: macro
    db \1_\2_\3
endm

section "main", rom0

    test_1 A       ; -1
    test_2 A, B, C ; -1

Numbers are weirder:

test_3: macro
    db \11
endm

test_4: macro
    db -\1
endm

test_5: macro
    db 1\12
endm

test_6: macro
    db 1\1
endm

section "main", rom0

    test_3 1       ; 11
    test_4 1       ; -1
    test_5 -       ; -1
    test_5 1       ; syntax error
    test_6 1       ; syntax error
@AntonioND
Copy link
Member

AntonioND commented Apr 24, 2017

I'm taking a look at this, but I'll post my findings so far:

For numbers, the problem is that the lexer, as soon as it finds a number, it looks for the first non-valid character for a number, sends it to the parser and continues. That way, when you do 1\1 the parser sees 1 \1. However, when it's done the other way around, the lexer finds the first numeric value when the argument is replaced by the value of the argument. Only after finishing the argument it finds the other number, so it considers it a continuation.

For labels and EQUs, it works just fine, at least with the current version.

Also, it seems that EQUSes can't be used in the list of macro arguments, the lexer used for macro arguments is a lot simpler than the one used for any other part of the code and interprets them as simple strings of characters that are copied when used from inside the macro. Macro arguments only allow a few escape characters (including macro arguments) as seen in yylex_MACROARGS. This has to be documented.

EDIT: Explanation of that last part:

LIST EQUS "3, 4"

MyMacro : MACRO
    DB \1
ENDM

    MyMacro 1, 2 ; interpreted as two arguments
    MyMacro "1\, 2" ; interpreted as a string (the comma has to be escaped)
    MyMacro LIST ; \1 = LIST, it is expanded when parsing the insides of the macro

@AntonioND AntonioND added bug Unexpected behavior / crashes; to be fixed ASAP! rgbasm This affects RGBASM labels Apr 2, 2018
@ISSOtm
Copy link
Member

ISSOtm commented Nov 4, 2019

State of this right now: the first block complains that A_A_A and A_B_C are not defined, respectively, so that's good.

The second block returns 11 (expected), -1 (expected), -1 (expected), a syntax error (oops), and another syntax error (oops)

@ISSOtm
Copy link
Member

ISSOtm commented Oct 5, 2020

Fixed by #557.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unexpected behavior / crashes; to be fixed ASAP! rgbasm This affects RGBASM
Projects
None yet
Development

No branches or pull requests

3 participants