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

[Swift] invalid swift generated for Dynamically-Scoped Attributes #4476

Open
EXC-BAD-ACCESS opened this issue Nov 25, 2023 · 0 comments
Open

Comments

@EXC-BAD-ACCESS
Copy link

when using the (slightly altered for swift) grammar from the doc

grammar DynScope;
 
prog: block ;
 
block
    /* List of symbols defined within this block */
    locals [
    symbols: [String]
    ]
    : '{' decl* stat+ '}'
    // print out all symbols found in block
    // $block::symbols evaluates to a List as defined in scope
    {print("symbols=\($symbols)");}
    ;
 
/** Match a declaration and add identifier name to list of symbols */
decl: 'int' ID {$block::symbols.append($ID.text);} ';' ;
 
/** Match an assignment then test list of symbols to verify
 * that it contains the variable on the left side of the assignment.
 * Method contains() is List.contains() because $block::symbols
 * is a List.
 */
stat: ID '=' INT ';'
    {
    if ( !$block::symbols.contains($ID.text) ) {
    print("undefined variable: "+$ID.text);
    }
    }
    | block
    ;
 
ID : [a-z]+ ;
INT : [0-9]+ ;
WS : [ \t\r\n]+ -> skip ;

the generated code is:
(BlockContext)getInvokingContext(1)).symbols.append((_localctx.castdown(DeclContext.self)._ID != nil ? _localctx.castdown(DeclContext.self)._ID!.getText()! : ""));
which uses an invalid c-style cast.

it should generate something like:
(getInvokingContext(1) as! BlockContext).symbols.append((_localctx.castdown(DeclContext.self)._ID != nil ? _localctx.castdown(DeclContext.self)._ID!.getText()! : ""));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant