mirror of
https://gitlab.com/camelot/kickc.git
synced 2024-12-30 15:31:17 +00:00
Added modes to lexer.
This commit is contained in:
parent
cb7469baf3
commit
87268abc2a
@ -276,11 +276,13 @@ public class AsmFormat {
|
||||
.replace(':', '_')
|
||||
.replace("#", "_")
|
||||
.replace("$", "_");
|
||||
//param = ""+((Registers.RegisterZp) register).getZp();
|
||||
return param;
|
||||
} else {
|
||||
String param = asmName.replace('@', 'b').replace(':', '_').replace("#", "_").replace("$", "_");
|
||||
//param = ""+((Registers.RegisterZp) register).getZp();
|
||||
String param = asmName
|
||||
.replace('@', 'b')
|
||||
.replace(':', '_')
|
||||
.replace("#", "_")
|
||||
.replace("$", "_");
|
||||
return param;
|
||||
}
|
||||
}
|
||||
|
@ -160,15 +160,15 @@ public class AsmFragmentInstance {
|
||||
|
||||
@Override
|
||||
public Object visitAsmLabelName(KickCParser.AsmLabelNameContext ctx) {
|
||||
program.addLine(new AsmLabel(ctx.NAME().getText()));
|
||||
program.addLine(new AsmLabel(ctx.ASM_NAME().getText()));
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object visitAsmLabelMulti(KickCParser.AsmLabelMultiContext ctx) {
|
||||
String label = "!";
|
||||
if(ctx.NAME()!=null) {
|
||||
label = label + ctx.NAME().getText();
|
||||
if(ctx.ASM_NAME()!=null) {
|
||||
label = label + ctx.ASM_NAME().getText();
|
||||
}
|
||||
program.addLine(new AsmLabel(label));
|
||||
return null;
|
||||
@ -306,7 +306,7 @@ public class AsmFragmentInstance {
|
||||
|
||||
@Override
|
||||
public AsmParameter visitAsmExprInt(KickCParser.AsmExprIntContext ctx) {
|
||||
Number number = NumberParser.parseLiteral(ctx.NUMBER().getText());
|
||||
Number number = NumberParser.parseLiteral(ctx.ASM_NUMBER().getText());
|
||||
boolean isZp = SymbolType.BYTE.contains(number.longValue()) || SymbolType.SBYTE.contains(number.longValue());
|
||||
String param = AsmFormat.getAsmNumber(number);
|
||||
return new AsmParameter(param, isZp);
|
||||
@ -319,7 +319,7 @@ public class AsmFragmentInstance {
|
||||
|
||||
@Override
|
||||
public AsmParameter visitAsmExprLabel(KickCParser.AsmExprLabelContext ctx) {
|
||||
String param = ctx.NAME().getSymbol().getText();
|
||||
String param = ctx.ASM_NAME().getSymbol().getText();
|
||||
return new AsmParameter(param, false);
|
||||
}
|
||||
|
||||
@ -331,7 +331,7 @@ public class AsmFragmentInstance {
|
||||
|
||||
@Override
|
||||
public AsmParameter visitAsmExprReplace(KickCParser.AsmExprReplaceContext ctx) {
|
||||
String replaceName = ctx.NAME().getSymbol().getText();
|
||||
String replaceName = ctx.ASM_NAME().getSymbol().getText();
|
||||
return bindings.getBoundValue(replaceName);
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ public class AsmParser {
|
||||
CodePointCharStream fragmentCharStream = CharStreams.fromString(body);
|
||||
CParser cParser = new CParser(null);
|
||||
KickCLexer kickCLexer = new KickCLexer(fragmentCharStream, cParser);
|
||||
kickCLexer.pushMode(KickCLexer.ASM_MODE);
|
||||
KickCParser kickCParser = new KickCParser(new CommonTokenStream(kickCLexer), cParser);
|
||||
kickCParser.addErrorListener(new BaseErrorListener() {
|
||||
@Override
|
||||
|
@ -41,9 +41,6 @@ public class CParser {
|
||||
/** Names of typedefs. Used by lexer to know the difference between normal value IDENTIFIERS and TYPEIDENTIFIERS */
|
||||
private List<String> typedefs;
|
||||
|
||||
/** True whenever the lexer/parser is parsing ASM. Enables/disables a lexer rules that might interfere.*/
|
||||
private boolean modeAsm;
|
||||
|
||||
/** True whenever the lexer is expecting an import filename as the next token. */
|
||||
private boolean modeImport;
|
||||
|
||||
@ -90,14 +87,6 @@ public class CParser {
|
||||
return typedefs.contains(identifier);
|
||||
}
|
||||
|
||||
public boolean isModeAsm() {
|
||||
return modeAsm;
|
||||
}
|
||||
|
||||
public void setModeAsm(boolean asm) {
|
||||
modeAsm = asm;
|
||||
}
|
||||
|
||||
public boolean isModeImport() {
|
||||
return modeImport;
|
||||
}
|
||||
|
@ -9,6 +9,9 @@ tokens { TYPEDEFNAME }
|
||||
@lexer::members {
|
||||
CParser cParser;
|
||||
|
||||
boolean asmEnter = false;
|
||||
int asmCurlyCount = 0;
|
||||
|
||||
public KickCLexer(CharStream input, CParser cParser) {
|
||||
this(input);
|
||||
this.cParser = cParser;
|
||||
@ -16,7 +19,7 @@ tokens { TYPEDEFNAME }
|
||||
}
|
||||
|
||||
// Special characters
|
||||
CURLY_BEGIN: '{' ;
|
||||
CURLY_BEGIN: '{' { if(asmEnter) { pushMode(ASM_MODE); asmEnter=false; } } ;
|
||||
CURLY_END: '}' ;
|
||||
BRACKET_BEGIN : '[' ;
|
||||
BRACKET_END : ']' ;
|
||||
@ -81,7 +84,7 @@ SWITCH: 'switch' ;
|
||||
RETURN: 'return' ;
|
||||
BREAK: 'break' ;
|
||||
CONTINUE: 'continue' ;
|
||||
ASM: 'asm' ;
|
||||
ASM: 'asm' { asmEnter=true; };
|
||||
DEFAULT : 'default' ;
|
||||
CASE : 'case' ;
|
||||
STRUCT : 'struct' ;
|
||||
@ -99,15 +102,7 @@ SIGNEDNESS : 'signed' | 'unsigned' ;
|
||||
SIMPLETYPE: 'byte' | 'word' | 'dword' | 'bool' | 'char' | 'short' | 'int' | 'long' | 'void' ;
|
||||
BOOLEAN : 'true' | 'false';
|
||||
KICKASM_BODY: '{{' .*? '}}';
|
||||
ASM_IMM : '#' ;
|
||||
ASM_BYTE : '.byte' ;
|
||||
ASM_MNEMONIC:
|
||||
'brk' | 'ora' | 'kil' | 'slo' | 'nop' | 'asl' | 'php' | 'anc' | 'bpl' | 'clc' | 'jsr' | 'and' | 'rla' | 'bit' | 'rol' | 'pla' | 'plp' | 'bmi' | 'sec' |
|
||||
'rti' | 'eor' | 'sre' | 'lsr' | 'pha' | 'alr' | 'jmp' | 'bvc' | 'cli' | 'rts' | 'adc' | 'rra' | 'bvs' | 'sei' | 'sax' | 'sty' | 'sta' | 'stx' | 'dey' |
|
||||
'txa' | 'xaa' | 'bcc' | 'ahx' | 'tya' | 'txs' | 'tas' | 'shy' | 'shx' | 'ldy' | 'lda' | 'ldx' | 'lax' | 'tay' | 'tax' | 'bcs' | 'clv' | 'tsx' | 'las' |
|
||||
'cpy' | 'cmp' | 'cpx' | 'dcp' | 'dec' | 'inc' | 'axs' | 'bne' | 'cld' | 'sbc' | 'isc' | 'inx' | 'beq' | 'sed' | 'dex' | 'iny' | 'ror'
|
||||
;
|
||||
ASM_REL: '!' NAME_CHAR* [+-]+ {cParser.isModeAsm()}? ;
|
||||
|
||||
|
||||
// Strings and chars - with special handling of imports
|
||||
STRING : '"' ('\\"' | ~'"')* '"' [z]?([ps][mu]?)?[z]? { if(cParser.isModeImport()) { cParser.setModeImport(false); cParser.loadCFile(getText()); } } ;
|
||||
@ -137,3 +132,62 @@ WS : [ \t\r\n\u00a0]+ -> channel(1);
|
||||
// Comments on hidden channel 2
|
||||
COMMENT_LINE : '//' ~[\r\n]* -> channel(2);
|
||||
COMMENT_BLOCK : '/*' .*? '*/' -> channel(2);
|
||||
|
||||
|
||||
// MODE FOR INLINE ASSEMBLER
|
||||
|
||||
mode ASM_MODE;
|
||||
ASM_BYTE : '.byte' ;
|
||||
ASM_MNEMONIC:
|
||||
'brk' | 'ora' | 'kil' | 'slo' | 'nop' | 'asl' | 'php' | 'anc' | 'bpl' | 'clc' | 'jsr' | 'and' | 'rla' | 'bit' | 'rol' | 'pla' | 'plp' | 'bmi' | 'sec' |
|
||||
'rti' | 'eor' | 'sre' | 'lsr' | 'pha' | 'alr' | 'jmp' | 'bvc' | 'cli' | 'rts' | 'adc' | 'rra' | 'bvs' | 'sei' | 'sax' | 'sty' | 'sta' | 'stx' | 'dey' |
|
||||
'txa' | 'xaa' | 'bcc' | 'ahx' | 'tya' | 'txs' | 'tas' | 'shy' | 'shx' | 'ldy' | 'lda' | 'ldx' | 'lax' | 'tay' | 'tax' | 'bcs' | 'clv' | 'tsx' | 'las' |
|
||||
'cpy' | 'cmp' | 'cpx' | 'dcp' | 'dec' | 'inc' | 'axs' | 'bne' | 'cld' | 'sbc' | 'isc' | 'inx' | 'beq' | 'sed' | 'dex' | 'iny' | 'ror'
|
||||
;
|
||||
ASM_REL: '!' ASM_NAME_CHAR* [+-]+ ;
|
||||
ASM_IMM : '#' ;
|
||||
ASM_COLON : ':';
|
||||
ASM_EXCL : '!';
|
||||
ASM_COMMA : ',' ;
|
||||
ASM_PAR_BEGIN : '(' ;
|
||||
ASM_PAR_END : ')' ;
|
||||
ASM_BRACKET_BEGIN: '[' ;
|
||||
ASM_BRACKET_END: ']' ;
|
||||
ASM_DOT : '.' ;
|
||||
ASM_SHIFT_LEFT : '<<' ;
|
||||
ASM_SHIFT_RIGHT : '>>' ;
|
||||
ASM_PLUS : '+' ;
|
||||
ASM_MINUS : '-' ;
|
||||
ASM_LESS_THAN : '<' ;
|
||||
ASM_GREATER_THAN : '>' ;
|
||||
ASM_MULTIPLY : '*' ;
|
||||
ASM_DIVIDE : '/' ;
|
||||
ASM_CURLY_BEGIN : '{' { asmCurlyCount++; };
|
||||
ASM_CURLY_END : '}' { asmCurlyCount--; if(asmCurlyCount<0) { popMode(); } };
|
||||
|
||||
// Numbers
|
||||
ASM_NUMBER : ASM_NUMFLOAT | ASM_NUMINT ;
|
||||
ASM_NUMFLOAT : ASM_BINFLOAT | ASM_DECFLOAT | ASM_HEXFLOAT;
|
||||
ASM_BINFLOAT : '%' (ASM_BINDIGIT)* '.' ASM_BINDIGIT+;
|
||||
ASM_DECFLOAT : (ASM_DECDIGIT)* '.' ASM_DECDIGIT+;
|
||||
ASM_HEXFLOAT : '$' (ASM_HEXDIGIT)* '.' ASM_HEXDIGIT+;
|
||||
ASM_NUMINT : (ASM_DECINTEGER | ASM_HEXINTEGER | ASM_BININTEGER ) ;
|
||||
ASM_BININTEGER : '%' ASM_BINDIGIT+ ;
|
||||
ASM_DECINTEGER : ASM_DECDIGIT+ ;
|
||||
ASM_HEXINTEGER : '$' ASM_HEXDIGIT+ ;
|
||||
fragment ASM_BINDIGIT : [0-1];
|
||||
fragment ASM_DECDIGIT : [0-9];
|
||||
fragment ASM_HEXDIGIT : [0-9a-fA-F];
|
||||
|
||||
ASM_CHAR : '\'' ('\\'['"rfn] | ~'\'' ) '\'';
|
||||
|
||||
//Names
|
||||
ASM_NAME : ASM_NAME_START ASM_NAME_CHAR* ;
|
||||
fragment ASM_NAME_START : [a-zA-Z_];
|
||||
fragment ASM_NAME_CHAR : [a-zA-Z0-9_];
|
||||
|
||||
// White space on hidden channel 1
|
||||
ASM_WS : [ \t\r\n\u00a0]+ -> channel(1);
|
||||
// Comments on hidden channel 2
|
||||
ASM_COMMENT_LINE : '//' ~[\r\n]* -> channel(2);
|
||||
ASM_COMMENT_BLOCK : '/*' .*? '*/' -> channel(2);
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -80,42 +80,61 @@ SIGNEDNESS=79
|
||||
SIMPLETYPE=80
|
||||
BOOLEAN=81
|
||||
KICKASM_BODY=82
|
||||
ASM_IMM=83
|
||||
ASM_BYTE=84
|
||||
ASM_MNEMONIC=85
|
||||
ASM_REL=86
|
||||
STRING=87
|
||||
CHAR=88
|
||||
NUMBER=89
|
||||
NUMFLOAT=90
|
||||
BINFLOAT=91
|
||||
DECFLOAT=92
|
||||
HEXFLOAT=93
|
||||
NUMINT=94
|
||||
BININTEGER=95
|
||||
DECINTEGER=96
|
||||
HEXINTEGER=97
|
||||
NAME=98
|
||||
WS=99
|
||||
COMMENT_LINE=100
|
||||
COMMENT_BLOCK=101
|
||||
'{'=2
|
||||
'}'=3
|
||||
'['=4
|
||||
']'=5
|
||||
'('=6
|
||||
')'=7
|
||||
STRING=83
|
||||
CHAR=84
|
||||
NUMBER=85
|
||||
NUMFLOAT=86
|
||||
BINFLOAT=87
|
||||
DECFLOAT=88
|
||||
HEXFLOAT=89
|
||||
NUMINT=90
|
||||
BININTEGER=91
|
||||
DECINTEGER=92
|
||||
HEXINTEGER=93
|
||||
NAME=94
|
||||
WS=95
|
||||
COMMENT_LINE=96
|
||||
COMMENT_BLOCK=97
|
||||
ASM_BYTE=98
|
||||
ASM_MNEMONIC=99
|
||||
ASM_REL=100
|
||||
ASM_IMM=101
|
||||
ASM_COLON=102
|
||||
ASM_EXCL=103
|
||||
ASM_COMMA=104
|
||||
ASM_PAR_BEGIN=105
|
||||
ASM_PAR_END=106
|
||||
ASM_BRACKET_BEGIN=107
|
||||
ASM_BRACKET_END=108
|
||||
ASM_DOT=109
|
||||
ASM_SHIFT_LEFT=110
|
||||
ASM_SHIFT_RIGHT=111
|
||||
ASM_PLUS=112
|
||||
ASM_MINUS=113
|
||||
ASM_LESS_THAN=114
|
||||
ASM_GREATER_THAN=115
|
||||
ASM_MULTIPLY=116
|
||||
ASM_DIVIDE=117
|
||||
ASM_CURLY_BEGIN=118
|
||||
ASM_CURLY_END=119
|
||||
ASM_NUMBER=120
|
||||
ASM_NUMFLOAT=121
|
||||
ASM_BINFLOAT=122
|
||||
ASM_DECFLOAT=123
|
||||
ASM_HEXFLOAT=124
|
||||
ASM_NUMINT=125
|
||||
ASM_BININTEGER=126
|
||||
ASM_DECINTEGER=127
|
||||
ASM_HEXINTEGER=128
|
||||
ASM_CHAR=129
|
||||
ASM_NAME=130
|
||||
ASM_WS=131
|
||||
ASM_COMMENT_LINE=132
|
||||
ASM_COMMENT_BLOCK=133
|
||||
';'=8
|
||||
':'=9
|
||||
','=10
|
||||
'..'=11
|
||||
'?'=12
|
||||
'.'=13
|
||||
'->'=14
|
||||
'+'=15
|
||||
'-'=16
|
||||
'*'=17
|
||||
'/'=18
|
||||
'%'=19
|
||||
'++'=20
|
||||
'--'=21
|
||||
@ -123,14 +142,10 @@ COMMENT_BLOCK=101
|
||||
'~'=23
|
||||
'^'=24
|
||||
'|'=25
|
||||
'<<'=26
|
||||
'>>'=27
|
||||
'=='=28
|
||||
'!='=29
|
||||
'<'=30
|
||||
'<='=31
|
||||
'>='=32
|
||||
'>'=33
|
||||
'&&'=34
|
||||
'||'=35
|
||||
'='=36
|
||||
@ -174,6 +189,5 @@ COMMENT_BLOCK=101
|
||||
'clobbers'=75
|
||||
'bytes'=76
|
||||
'cycles'=77
|
||||
'!'=78
|
||||
'#'=83
|
||||
'.byte'=84
|
||||
'.byte'=98
|
||||
'#'=101
|
||||
|
@ -21,7 +21,6 @@ file
|
||||
: declSeq EOF
|
||||
;
|
||||
|
||||
|
||||
asmFile
|
||||
: asmLines EOF
|
||||
;
|
||||
@ -63,7 +62,7 @@ declVariables
|
||||
|
||||
declVariableList
|
||||
: declVariableInit
|
||||
| declVariableList ',' declVariableInit
|
||||
| declVariableList COMMA declVariableInit
|
||||
;
|
||||
|
||||
declVariableInit
|
||||
@ -72,11 +71,11 @@ declVariableInit
|
||||
;
|
||||
|
||||
declFunction
|
||||
: declTypes NAME '(' parameterListDecl? ')' '{' stmtSeq? '}'
|
||||
: declTypes NAME PAR_BEGIN parameterListDecl? PAR_END CURLY_BEGIN stmtSeq? CURLY_END
|
||||
;
|
||||
|
||||
parameterListDecl
|
||||
: parameterDecl (',' parameterDecl)* ;
|
||||
: parameterDecl (COMMA parameterDecl)* ;
|
||||
|
||||
parameterDecl
|
||||
: declTypes NAME #parameterDeclType
|
||||
@ -84,25 +83,25 @@ parameterDecl
|
||||
;
|
||||
|
||||
globalDirective
|
||||
: (PRAGMA RESERVE) '(' NUMBER ( ',' NUMBER )* ')' #globalDirectiveReserve
|
||||
| (PRAGMA PC) '(' NUMBER ')' #globalDirectivePc
|
||||
| (PRAGMA TARGET) '(' NAME ')' #globalDirectivePlatform
|
||||
| (PRAGMA LINK) '(' STRING ')' #globalDirectiveLinkScript
|
||||
| (PRAGMA CODESEG) '(' NAME ')' #globalDirectiveCodeSeg
|
||||
| (PRAGMA DATASEG) '(' NAME ')' #globalDirectiveDataSeg
|
||||
| (PRAGMA ENCODING) '(' NAME ')' #globalDirectiveEncoding
|
||||
: (PRAGMA RESERVE) PAR_BEGIN NUMBER ( COMMA NUMBER )* PAR_END #globalDirectiveReserve
|
||||
| (PRAGMA PC) PAR_BEGIN NUMBER PAR_END #globalDirectivePc
|
||||
| (PRAGMA TARGET) PAR_BEGIN NAME PAR_END #globalDirectivePlatform
|
||||
| (PRAGMA LINK) PAR_BEGIN STRING PAR_END #globalDirectiveLinkScript
|
||||
| (PRAGMA CODESEG) PAR_BEGIN NAME PAR_END #globalDirectiveCodeSeg
|
||||
| (PRAGMA DATASEG) PAR_BEGIN NAME PAR_END #globalDirectiveDataSeg
|
||||
| (PRAGMA ENCODING) PAR_BEGIN NAME PAR_END #globalDirectiveEncoding
|
||||
;
|
||||
|
||||
directive
|
||||
: CONST #directiveConst
|
||||
| EXTERN #directiveExtern
|
||||
| EXPORT #directiveExport
|
||||
| ALIGN '(' NUMBER ')' #directiveAlign
|
||||
| REGISTER ( '(' NAME ')')? #directiveRegister
|
||||
| ALIGN PAR_BEGIN NUMBER PAR_END #directiveAlign
|
||||
| REGISTER ( PAR_BEGIN NAME PAR_END)? #directiveRegister
|
||||
| INLINE #directiveInline
|
||||
| VOLATILE #directiveVolatile
|
||||
| INTERRUPT ( '(' NAME ')' )? #directiveInterrupt
|
||||
| RESERVE '(' NUMBER ( ',' NUMBER )* ')' #directiveReserveZp
|
||||
| INTERRUPT ( PAR_BEGIN NAME PAR_END )? #directiveInterrupt
|
||||
| RESERVE PAR_BEGIN NUMBER ( COMMA NUMBER )* PAR_END #directiveReserveZp
|
||||
;
|
||||
|
||||
stmtSeq
|
||||
@ -111,31 +110,31 @@ stmtSeq
|
||||
|
||||
stmt
|
||||
: declVariables ';' #stmtDeclVar
|
||||
| '{' stmtSeq? '}' #stmtBlock
|
||||
| CURLY_BEGIN stmtSeq? CURLY_END #stmtBlock
|
||||
| commaExpr ';' #stmtExpr
|
||||
| IF '(' commaExpr ')' stmt ( ELSE stmt )? #stmtIfElse
|
||||
| directive* WHILE '(' commaExpr ')' stmt #stmtWhile
|
||||
| directive* DO stmt WHILE '(' commaExpr ')' ';' #stmtDoWhile
|
||||
| directive* FOR '(' forLoop ')' stmt #stmtFor
|
||||
| SWITCH '(' commaExpr ')' '{' switchCases '}' #stmtSwitch
|
||||
| IF PAR_BEGIN commaExpr PAR_END stmt ( ELSE stmt )? #stmtIfElse
|
||||
| directive* WHILE PAR_BEGIN commaExpr PAR_END stmt #stmtWhile
|
||||
| directive* DO stmt WHILE PAR_BEGIN commaExpr PAR_END ';' #stmtDoWhile
|
||||
| directive* FOR PAR_BEGIN forLoop PAR_END stmt #stmtFor
|
||||
| SWITCH PAR_BEGIN commaExpr PAR_END CURLY_BEGIN switchCases CURLY_END #stmtSwitch
|
||||
| RETURN commaExpr? ';' #stmtReturn
|
||||
| BREAK ';' #stmtBreak
|
||||
| CONTINUE ';' #stmtContinue
|
||||
| ASM asmDirectives? '{' asmLines '}' #stmtAsm
|
||||
| ASM asmDirectives? CURLY_BEGIN asmLines ASM_CURLY_END #stmtAsm
|
||||
| declKasm #stmtDeclKasm
|
||||
;
|
||||
|
||||
switchCases:
|
||||
switchCase+ ( DEFAULT ':' stmtSeq? )?
|
||||
switchCase+ ( DEFAULT COLON stmtSeq? )?
|
||||
;
|
||||
|
||||
switchCase:
|
||||
CASE expr ':' stmtSeq?
|
||||
CASE expr COLON stmtSeq?
|
||||
;
|
||||
|
||||
forLoop
|
||||
: forClassicInit ';' commaExpr ';' commaExpr? #forClassic
|
||||
| declTypes? NAME ':' expr '..' expr #forRange
|
||||
| declTypes? NAME COLON expr '..' expr #forRange
|
||||
;
|
||||
|
||||
forClassicInit
|
||||
@ -144,12 +143,12 @@ forClassicInit
|
||||
;
|
||||
|
||||
typeDecl
|
||||
: '(' typeDecl ')' #typePar
|
||||
: PAR_BEGIN typeDecl PAR_END #typePar
|
||||
| SIMPLETYPE #typeSimple
|
||||
| SIGNEDNESS SIMPLETYPE? #typeSignedSimple
|
||||
| typeDecl ASTERISK #typePtr
|
||||
| typeDecl '[' (expr)? ']' #typeArray
|
||||
| typeDecl '(' ')' #typeProcedure
|
||||
| typeDecl BRACKET_BEGIN (expr)? BRACKET_END #typeArray
|
||||
| typeDecl PAR_BEGIN PAR_END #typeProcedure
|
||||
| structDef #typeStructDef
|
||||
| structRef #typeStructRef
|
||||
| enumDef #typeEnumDef
|
||||
@ -162,7 +161,7 @@ structRef
|
||||
;
|
||||
|
||||
structDef
|
||||
: STRUCT NAME? '{' structMembers+ '}'
|
||||
: STRUCT NAME? CURLY_BEGIN structMembers+ CURLY_END
|
||||
;
|
||||
|
||||
structMembers
|
||||
@ -174,12 +173,12 @@ enumRef
|
||||
;
|
||||
|
||||
enumDef
|
||||
: ENUM NAME? '{' enumMemberList '}'
|
||||
: ENUM NAME? CURLY_BEGIN enumMemberList CURLY_END
|
||||
;
|
||||
|
||||
enumMemberList
|
||||
: enumMember
|
||||
| enumMemberList ',' enumMember
|
||||
| enumMemberList COMMA enumMember
|
||||
;
|
||||
|
||||
enumMember
|
||||
@ -188,36 +187,36 @@ enumMember
|
||||
|
||||
commaExpr
|
||||
: expr #commaNone
|
||||
| commaExpr ',' expr #commaSimple
|
||||
| commaExpr COMMA expr #commaSimple
|
||||
;
|
||||
|
||||
expr
|
||||
: '(' commaExpr ')' #exprPar
|
||||
| expr '.' NAME #exprDot
|
||||
: PAR_BEGIN commaExpr PAR_END #exprPar
|
||||
| expr DOT NAME #exprDot
|
||||
| expr '->' NAME #exprArrow
|
||||
| expr '(' parameterList? ')' #exprCall
|
||||
| SIZEOF '(' ( expr | typeDecl ) ')' #exprSizeOf
|
||||
| TYPEID '(' ( expr | typeDecl ) ')' #exprTypeId
|
||||
| expr '[' commaExpr ']' #exprArray
|
||||
| '(' typeDecl ')' expr #exprCast
|
||||
| expr PAR_BEGIN parameterList? PAR_END #exprCall
|
||||
| SIZEOF PAR_BEGIN ( expr | typeDecl ) PAR_END #exprSizeOf
|
||||
| TYPEID PAR_BEGIN ( expr | typeDecl ) PAR_END #exprTypeId
|
||||
| expr BRACKET_BEGIN commaExpr BRACKET_END #exprArray
|
||||
| PAR_BEGIN typeDecl PAR_END expr #exprCast
|
||||
| ('--' | '++' ) expr #exprPreMod
|
||||
| expr ('--' | '++' ) #exprPostMod
|
||||
| '*' expr #exprPtr
|
||||
| ('+' | '-' | '!' | '&'| '~' ) expr #exprUnary
|
||||
| expr ('<<' | '>>' ) expr #exprBinary
|
||||
| expr ('*' | '/' | '%' ) expr #exprBinary
|
||||
| expr ( '+' | '-' ) expr #exprBinary
|
||||
| ('<' | '>') expr #exprUnary
|
||||
| expr ( '==' | '!=' | '<' | '<=' | '>=' | '>' ) expr #exprBinary
|
||||
| ASTERISK expr #exprPtr
|
||||
| (PLUS | MINUS | LOGIC_NOT | '&'| '~' ) expr #exprUnary
|
||||
| expr (SHIFT_LEFT | SHIFT_RIGHT ) expr #exprBinary
|
||||
| expr (ASTERISK | DIVIDE | '%' ) expr #exprBinary
|
||||
| expr ( PLUS | MINUS ) expr #exprBinary
|
||||
| (LESS_THAN | GREATER_THAN) expr #exprUnary
|
||||
| expr ( '==' | '!=' | LESS_THAN | '<=' | '>=' | GREATER_THAN ) expr #exprBinary
|
||||
| expr ( '&' ) expr #exprBinary
|
||||
| expr ( '^' ) expr #exprBinary
|
||||
| expr ( '|' ) expr #exprBinary
|
||||
| expr ( '&&' ) expr #exprBinary
|
||||
| expr ( '||' ) expr #exprBinary
|
||||
| expr '?' expr ':' expr #exprTernary
|
||||
| expr '?' expr COLON expr #exprTernary
|
||||
| <assoc=right> expr '=' expr #exprAssignment
|
||||
| <assoc=right> expr ASSIGN_COMPOUND expr #exprAssignmentCompound
|
||||
| '{' expr (',' expr )* '}' #initList
|
||||
| CURLY_BEGIN expr (COMMA expr )* CURLY_END #initList
|
||||
| NAME #exprId
|
||||
| NUMBER #exprNumber
|
||||
| STRING+ #exprString
|
||||
@ -226,7 +225,7 @@ expr
|
||||
;
|
||||
|
||||
parameterList
|
||||
: expr (',' expr)*
|
||||
: expr (COMMA expr)*
|
||||
;
|
||||
|
||||
declKasm
|
||||
@ -234,7 +233,7 @@ declKasm
|
||||
;
|
||||
|
||||
asmDirectives
|
||||
: '(' asmDirective ( ',' asmDirective )* ')'
|
||||
: PAR_BEGIN asmDirective ( COMMA asmDirective )* PAR_END
|
||||
;
|
||||
|
||||
asmDirective
|
||||
@ -247,7 +246,7 @@ asmDirective
|
||||
;
|
||||
|
||||
asmLines
|
||||
: {cParser.setModeAsm(true);} asmLine* {cParser.setModeAsm(false);}
|
||||
: asmLine*
|
||||
;
|
||||
|
||||
asmLine
|
||||
@ -257,8 +256,8 @@ asmLine
|
||||
;
|
||||
|
||||
asmLabel
|
||||
: NAME ':' #asmLabelName
|
||||
| '!' NAME? ':' #asmLabelMulti
|
||||
: ASM_NAME ASM_COLON #asmLabelName
|
||||
| ASM_EXCL ASM_NAME? ASM_COLON #asmLabelMulti
|
||||
;
|
||||
|
||||
asmInstruction
|
||||
@ -266,28 +265,28 @@ asmInstruction
|
||||
;
|
||||
|
||||
asmBytes
|
||||
: ASM_BYTE asmExpr ( ',' asmExpr)*
|
||||
: ASM_BYTE asmExpr ( ASM_COMMA asmExpr)*
|
||||
;
|
||||
|
||||
asmParamMode
|
||||
: asmExpr #asmModeAbs
|
||||
| '#' asmExpr #asmModeImm
|
||||
| asmExpr ',' NAME #asmModeAbsXY
|
||||
| '(' asmExpr ')' ',' NAME #asmModeIndIdxXY
|
||||
| '(' asmExpr ',' NAME ')' #asmModeIdxIndXY
|
||||
| '(' asmExpr ')' #asmModeInd
|
||||
| ASM_IMM asmExpr #asmModeImm
|
||||
| asmExpr ASM_COMMA ASM_NAME #asmModeAbsXY
|
||||
| ASM_PAR_BEGIN asmExpr ASM_PAR_END ASM_COMMA ASM_NAME #asmModeIndIdxXY
|
||||
| ASM_PAR_BEGIN asmExpr ASM_COMMA ASM_NAME ASM_PAR_END #asmModeIdxIndXY
|
||||
| ASM_PAR_BEGIN asmExpr ASM_PAR_END #asmModeInd
|
||||
;
|
||||
|
||||
asmExpr
|
||||
: '[' asmExpr ']' #asmExprPar
|
||||
| asmExpr ( '.' ) asmExpr #asmExprBinary
|
||||
| asmExpr ( '<<'| '>>' ) asmExpr #asmExprBinary
|
||||
| ('+' | '-'| '<' | '>' ) asmExpr #asmExprUnary
|
||||
| asmExpr ('*' | '/' ) asmExpr #asmExprBinary
|
||||
| asmExpr ( '+' | '-' ) asmExpr #asmExprBinary
|
||||
| NAME #asmExprLabel
|
||||
: ASM_BRACKET_BEGIN asmExpr ASM_BRACKET_END #asmExprPar
|
||||
| asmExpr ( ASM_DOT ) asmExpr #asmExprBinary
|
||||
| asmExpr ( ASM_SHIFT_LEFT| ASM_SHIFT_RIGHT ) asmExpr #asmExprBinary
|
||||
| (ASM_PLUS | ASM_MINUS| ASM_LESS_THAN | ASM_GREATER_THAN ) asmExpr #asmExprUnary
|
||||
| asmExpr (ASM_MULTIPLY | ASM_DIVIDE ) asmExpr #asmExprBinary
|
||||
| asmExpr ( ASM_PLUS | ASM_MINUS ) asmExpr #asmExprBinary
|
||||
| ASM_NAME #asmExprLabel
|
||||
| ASM_REL #asmExprLabelRel
|
||||
| '{' NAME '}' #asmExprReplace
|
||||
| NUMBER #asmExprInt
|
||||
| CHAR #asmExprChar
|
||||
| ASM_CURLY_BEGIN ASM_NAME ASM_CURLY_END #asmExprReplace
|
||||
| ASM_NUMBER #asmExprInt
|
||||
| ASM_CHAR #asmExprChar
|
||||
;
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -80,42 +80,61 @@ SIGNEDNESS=79
|
||||
SIMPLETYPE=80
|
||||
BOOLEAN=81
|
||||
KICKASM_BODY=82
|
||||
ASM_IMM=83
|
||||
ASM_BYTE=84
|
||||
ASM_MNEMONIC=85
|
||||
ASM_REL=86
|
||||
STRING=87
|
||||
CHAR=88
|
||||
NUMBER=89
|
||||
NUMFLOAT=90
|
||||
BINFLOAT=91
|
||||
DECFLOAT=92
|
||||
HEXFLOAT=93
|
||||
NUMINT=94
|
||||
BININTEGER=95
|
||||
DECINTEGER=96
|
||||
HEXINTEGER=97
|
||||
NAME=98
|
||||
WS=99
|
||||
COMMENT_LINE=100
|
||||
COMMENT_BLOCK=101
|
||||
'{'=2
|
||||
'}'=3
|
||||
'['=4
|
||||
']'=5
|
||||
'('=6
|
||||
')'=7
|
||||
STRING=83
|
||||
CHAR=84
|
||||
NUMBER=85
|
||||
NUMFLOAT=86
|
||||
BINFLOAT=87
|
||||
DECFLOAT=88
|
||||
HEXFLOAT=89
|
||||
NUMINT=90
|
||||
BININTEGER=91
|
||||
DECINTEGER=92
|
||||
HEXINTEGER=93
|
||||
NAME=94
|
||||
WS=95
|
||||
COMMENT_LINE=96
|
||||
COMMENT_BLOCK=97
|
||||
ASM_BYTE=98
|
||||
ASM_MNEMONIC=99
|
||||
ASM_REL=100
|
||||
ASM_IMM=101
|
||||
ASM_COLON=102
|
||||
ASM_EXCL=103
|
||||
ASM_COMMA=104
|
||||
ASM_PAR_BEGIN=105
|
||||
ASM_PAR_END=106
|
||||
ASM_BRACKET_BEGIN=107
|
||||
ASM_BRACKET_END=108
|
||||
ASM_DOT=109
|
||||
ASM_SHIFT_LEFT=110
|
||||
ASM_SHIFT_RIGHT=111
|
||||
ASM_PLUS=112
|
||||
ASM_MINUS=113
|
||||
ASM_LESS_THAN=114
|
||||
ASM_GREATER_THAN=115
|
||||
ASM_MULTIPLY=116
|
||||
ASM_DIVIDE=117
|
||||
ASM_CURLY_BEGIN=118
|
||||
ASM_CURLY_END=119
|
||||
ASM_NUMBER=120
|
||||
ASM_NUMFLOAT=121
|
||||
ASM_BINFLOAT=122
|
||||
ASM_DECFLOAT=123
|
||||
ASM_HEXFLOAT=124
|
||||
ASM_NUMINT=125
|
||||
ASM_BININTEGER=126
|
||||
ASM_DECINTEGER=127
|
||||
ASM_HEXINTEGER=128
|
||||
ASM_CHAR=129
|
||||
ASM_NAME=130
|
||||
ASM_WS=131
|
||||
ASM_COMMENT_LINE=132
|
||||
ASM_COMMENT_BLOCK=133
|
||||
';'=8
|
||||
':'=9
|
||||
','=10
|
||||
'..'=11
|
||||
'?'=12
|
||||
'.'=13
|
||||
'->'=14
|
||||
'+'=15
|
||||
'-'=16
|
||||
'*'=17
|
||||
'/'=18
|
||||
'%'=19
|
||||
'++'=20
|
||||
'--'=21
|
||||
@ -123,14 +142,10 @@ COMMENT_BLOCK=101
|
||||
'~'=23
|
||||
'^'=24
|
||||
'|'=25
|
||||
'<<'=26
|
||||
'>>'=27
|
||||
'=='=28
|
||||
'!='=29
|
||||
'<'=30
|
||||
'<='=31
|
||||
'>='=32
|
||||
'>'=33
|
||||
'&&'=34
|
||||
'||'=35
|
||||
'='=36
|
||||
@ -174,6 +189,5 @@ COMMENT_BLOCK=101
|
||||
'clobbers'=75
|
||||
'bytes'=76
|
||||
'cycles'=77
|
||||
'!'=78
|
||||
'#'=83
|
||||
'.byte'=84
|
||||
'.byte'=98
|
||||
'#'=101
|
||||
|
@ -1265,15 +1265,15 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
|
||||
|
||||
@Override
|
||||
public Void visitAsmExprLabel(KickCParser.AsmExprLabelContext ctxLabel) {
|
||||
String label = ctxLabel.NAME().toString();
|
||||
String label = ctxLabel.ASM_NAME().toString();
|
||||
if(!definedLabels.contains(label)) {
|
||||
// Look for the symbol
|
||||
Symbol symbol = getCurrentScope().getSymbol(ctxLabel.NAME().getText());
|
||||
Symbol symbol = getCurrentScope().getSymbol(ctxLabel.ASM_NAME().getText());
|
||||
if(symbol != null) {
|
||||
referenced.put(label, symbol.getRef());
|
||||
} else {
|
||||
// Either forward reference or a non-existing variable. Create a forward reference for later resolving.
|
||||
referenced.put(label, new ForwardVariableRef(ctxLabel.NAME().getText()));
|
||||
referenced.put(label, new ForwardVariableRef(ctxLabel.ASM_NAME().getText()));
|
||||
}
|
||||
}
|
||||
return super.visitAsmExprLabel(ctxLabel);
|
||||
@ -1294,7 +1294,7 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
|
||||
KickCParserBaseVisitor<Void> findDefinedLabels = new KickCParserBaseVisitor<Void>() {
|
||||
@Override
|
||||
public Void visitAsmLabelName(KickCParser.AsmLabelNameContext ctx) {
|
||||
String label = ctx.NAME().getText();
|
||||
String label = ctx.ASM_NAME().getText();
|
||||
definedLabels.add(label);
|
||||
return super.visitAsmLabelName(ctx);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user