mirror of
https://gitlab.com/camelot/kickc.git
synced 2025-02-20 00:29:10 +00:00
Separated lexer and parser in ANTLR parser.
This commit is contained in:
parent
91a7f0bb0d
commit
d9321907ea
@ -11,8 +11,8 @@ import dk.camelot64.kickc.model.types.SymbolType;
|
|||||||
import dk.camelot64.kickc.model.values.ConstantValue;
|
import dk.camelot64.kickc.model.values.ConstantValue;
|
||||||
import dk.camelot64.kickc.model.values.ScopeRef;
|
import dk.camelot64.kickc.model.values.ScopeRef;
|
||||||
import dk.camelot64.kickc.model.values.Value;
|
import dk.camelot64.kickc.model.values.Value;
|
||||||
import dk.camelot64.kickc.parser.KickCBaseVisitor;
|
|
||||||
import dk.camelot64.kickc.parser.KickCParser;
|
import dk.camelot64.kickc.parser.KickCParser;
|
||||||
|
import dk.camelot64.kickc.parser.KickCParserBaseVisitor;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -138,7 +138,7 @@ public class AsmFragmentInstance {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class AsmSequenceGenerator extends KickCBaseVisitor {
|
private static class AsmSequenceGenerator extends KickCParserBaseVisitor {
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
private AsmProgram program;
|
private AsmProgram program;
|
||||||
|
@ -1,339 +0,0 @@
|
|||||||
// KickC grammar
|
|
||||||
grammar KickC;
|
|
||||||
|
|
||||||
@header {
|
|
||||||
}
|
|
||||||
|
|
||||||
@lexer::members {
|
|
||||||
CParser cParser;
|
|
||||||
|
|
||||||
public KickCLexer(CharStream input, CParser cParser) {
|
|
||||||
this(input);
|
|
||||||
this.cParser = cParser;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@parser::members {
|
|
||||||
CParser cParser;
|
|
||||||
|
|
||||||
public KickCParser(TokenStream input, CParser cParser) {
|
|
||||||
this(input);
|
|
||||||
this.cParser = cParser;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
file
|
|
||||||
: declSeq EOF
|
|
||||||
;
|
|
||||||
|
|
||||||
asmFile
|
|
||||||
: asmLines EOF
|
|
||||||
;
|
|
||||||
|
|
||||||
declSeq
|
|
||||||
: declOrImport*
|
|
||||||
;
|
|
||||||
|
|
||||||
declOrImport
|
|
||||||
: decl
|
|
||||||
| importDecl
|
|
||||||
;
|
|
||||||
|
|
||||||
importDecl
|
|
||||||
: IMPORT IMPORTFILE
|
|
||||||
;
|
|
||||||
|
|
||||||
decl
|
|
||||||
: declVariables ';'
|
|
||||||
| structDef ';'
|
|
||||||
| enumDef ';'
|
|
||||||
| declFunction
|
|
||||||
| declKasm
|
|
||||||
| globalDirective
|
|
||||||
| typeDef ';'
|
|
||||||
;
|
|
||||||
|
|
||||||
typeDef
|
|
||||||
: 'typedef' typeDecl NAME {cParser.addTypedef($NAME.text);}
|
|
||||||
;
|
|
||||||
|
|
||||||
declTypes
|
|
||||||
: directive* typeDecl directive*
|
|
||||||
;
|
|
||||||
|
|
||||||
declVariables
|
|
||||||
: declTypes declVariableList
|
|
||||||
;
|
|
||||||
|
|
||||||
declVariableList
|
|
||||||
: declVariableInit
|
|
||||||
| declVariableList ',' declVariableInit
|
|
||||||
;
|
|
||||||
|
|
||||||
declVariableInit
|
|
||||||
: NAME ('=' expr)? #declVariableInitExpr
|
|
||||||
| NAME '=' declKasm #declVariableInitKasm
|
|
||||||
;
|
|
||||||
|
|
||||||
declFunction
|
|
||||||
: declTypes NAME '(' parameterListDecl? ')' '{' stmtSeq? '}'
|
|
||||||
;
|
|
||||||
|
|
||||||
parameterListDecl
|
|
||||||
: parameterDecl (',' parameterDecl)* ;
|
|
||||||
|
|
||||||
parameterDecl
|
|
||||||
: declTypes NAME #parameterDeclType
|
|
||||||
| SIMPLETYPE #parameterDeclVoid
|
|
||||||
;
|
|
||||||
|
|
||||||
globalDirective
|
|
||||||
: ('#pragma' 'reserve'|'#reserve') '(' NUMBER ( ',' NUMBER )* ')' #globalDirectiveReserve
|
|
||||||
| ('#pragma' 'pc'|'#pc') '(' NUMBER ')' #globalDirectivePc
|
|
||||||
| ('#pragma' 'target'|'#target') '(' NAME ')' #globalDirectivePlatform
|
|
||||||
| ('#pragma' 'link') '(' STRING ')' #globalDirectiveLinkScript
|
|
||||||
| ('#pragma' 'code_seg') '(' NAME ')' #globalDirectiveCodeSeg
|
|
||||||
| ('#pragma' 'data_seg') '(' NAME ')' #globalDirectiveDataSeg
|
|
||||||
| ('#pragma' 'encoding'|'#encoding') '(' NAME')' #globalDirectiveEncoding
|
|
||||||
;
|
|
||||||
|
|
||||||
directive
|
|
||||||
: 'const' #directiveConst
|
|
||||||
| 'extern' #directiveExtern
|
|
||||||
| 'export' #directiveExport
|
|
||||||
| 'align' '(' NUMBER ')' #directiveAlign
|
|
||||||
| 'register' ( '(' NAME ')')? #directiveRegister
|
|
||||||
| 'inline' #directiveInline
|
|
||||||
| 'volatile' #directiveVolatile
|
|
||||||
| 'interrupt' ( '(' NAME ')' )? #directiveInterrupt
|
|
||||||
| 'reserve' '(' NUMBER ( ',' NUMBER )* ')' #directiveReserveZp
|
|
||||||
;
|
|
||||||
|
|
||||||
stmtSeq
|
|
||||||
: stmt+
|
|
||||||
;
|
|
||||||
|
|
||||||
stmt
|
|
||||||
: declVariables ';' #stmtDeclVar
|
|
||||||
| '{' stmtSeq? '}' #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
|
|
||||||
| 'return' commaExpr? ';' #stmtReturn
|
|
||||||
| 'break' ';' #stmtBreak
|
|
||||||
| 'continue' ';' #stmtContinue
|
|
||||||
| 'asm' asmDirectives? '{' asmLines '}' #stmtAsm
|
|
||||||
| declKasm #stmtDeclKasm
|
|
||||||
;
|
|
||||||
|
|
||||||
switchCases:
|
|
||||||
switchCase+ ( 'default:' stmtSeq? )?
|
|
||||||
;
|
|
||||||
|
|
||||||
switchCase:
|
|
||||||
'case' expr ':' stmtSeq?
|
|
||||||
;
|
|
||||||
|
|
||||||
forLoop
|
|
||||||
: forClassicInit ';' commaExpr ';' commaExpr? #forClassic
|
|
||||||
| declTypes? NAME ':' expr ( '..' ) expr #forRange
|
|
||||||
;
|
|
||||||
|
|
||||||
forClassicInit
|
|
||||||
: declVariables? #forClassicInitDecl
|
|
||||||
| commaExpr #forClassicInitExpr
|
|
||||||
;
|
|
||||||
|
|
||||||
typeDecl
|
|
||||||
: '(' typeDecl ')' #typePar
|
|
||||||
| SIMPLETYPE #typeSimple
|
|
||||||
| ('signed'|'unsigned') SIMPLETYPE? #typeSignedSimple
|
|
||||||
| typeDecl '*' #typePtr
|
|
||||||
| typeDecl '[' (expr)? ']' #typeArray
|
|
||||||
| typeDecl '(' ')' #typeProcedure
|
|
||||||
| structDef #typeStructDef
|
|
||||||
| structRef #typeStructRef
|
|
||||||
| enumDef #typeEnumDef
|
|
||||||
| enumRef #typeEnumRef
|
|
||||||
| TYPEDEFNAME #typeNamedRef
|
|
||||||
;
|
|
||||||
|
|
||||||
structRef
|
|
||||||
: 'struct' NAME
|
|
||||||
;
|
|
||||||
|
|
||||||
structDef
|
|
||||||
: 'struct' NAME? '{' structMembers+ '}'
|
|
||||||
;
|
|
||||||
|
|
||||||
structMembers
|
|
||||||
: declVariables ';'
|
|
||||||
;
|
|
||||||
|
|
||||||
enumRef
|
|
||||||
: 'enum' NAME
|
|
||||||
;
|
|
||||||
|
|
||||||
enumDef
|
|
||||||
: 'enum' NAME? '{' enumMemberList '}'
|
|
||||||
;
|
|
||||||
|
|
||||||
enumMemberList
|
|
||||||
: enumMember
|
|
||||||
| enumMemberList ',' enumMember
|
|
||||||
;
|
|
||||||
|
|
||||||
enumMember
|
|
||||||
: NAME ( '=' expr )?
|
|
||||||
;
|
|
||||||
|
|
||||||
commaExpr
|
|
||||||
: expr #commaNone
|
|
||||||
| commaExpr ',' expr #commaSimple
|
|
||||||
;
|
|
||||||
|
|
||||||
expr
|
|
||||||
: '(' commaExpr ')' #exprPar
|
|
||||||
| expr '.' NAME #exprDot
|
|
||||||
| expr '->' NAME #exprArrow
|
|
||||||
| expr '(' parameterList? ')' #exprCall
|
|
||||||
| 'sizeof' '(' ( expr | typeDecl ) ')' #exprSizeOf
|
|
||||||
| 'typeid' '(' ( expr | typeDecl ) ')' #exprTypeId
|
|
||||||
| expr '[' commaExpr ']' #exprArray
|
|
||||||
| '(' typeDecl ')' expr #exprCast
|
|
||||||
| ('--' | '++' ) expr #exprPreMod
|
|
||||||
| expr ('--' | '++' ) #exprPostMod
|
|
||||||
| '*' expr #exprPtr
|
|
||||||
| ('+' | '-' | '!' | '&' | '~') expr #exprUnary
|
|
||||||
| expr ('>>' | '<<' ) expr #exprBinary
|
|
||||||
| expr ('*' | '/' | '%' ) expr #exprBinary
|
|
||||||
| expr ( '+' | '-') expr #exprBinary
|
|
||||||
| ('<' | '>') expr #exprUnary
|
|
||||||
| expr ( '==' | '!=' | '<' | '<=' | '>=' | '>' ) expr #exprBinary
|
|
||||||
| expr ( '&' ) expr #exprBinary
|
|
||||||
| expr ( '^' ) expr #exprBinary
|
|
||||||
| expr ( '|' ) expr #exprBinary
|
|
||||||
| expr ( '&&' ) expr #exprBinary
|
|
||||||
| expr ( '||' ) expr #exprBinary
|
|
||||||
| expr '?' expr ':' expr #exprTernary
|
|
||||||
| <assoc=right> expr '=' expr #exprAssignment
|
|
||||||
| <assoc=right> expr ('+=' | '-=' | '*=' | '/=' | '%=' | '<<=' | '>>=' | '&=' | '|=' | '^=' ) expr #exprAssignmentCompound
|
|
||||||
| '{' expr (',' expr )* '}' #initList
|
|
||||||
| NAME #exprId
|
|
||||||
| NUMBER #exprNumber
|
|
||||||
| STRING+ #exprString
|
|
||||||
| CHAR #exprChar
|
|
||||||
| BOOLEAN #exprBool
|
|
||||||
;
|
|
||||||
|
|
||||||
parameterList
|
|
||||||
: expr (',' expr)*
|
|
||||||
;
|
|
||||||
|
|
||||||
declKasm
|
|
||||||
: 'kickasm' asmDirectives? KICKASM
|
|
||||||
;
|
|
||||||
|
|
||||||
asmDirectives
|
|
||||||
: '(' asmDirective ( ',' asmDirective )* ')'
|
|
||||||
;
|
|
||||||
|
|
||||||
asmDirective
|
|
||||||
: 'resource' STRING #asmDirectiveResource
|
|
||||||
| 'uses' NAME #asmDirectiveUses
|
|
||||||
| 'clobbers' STRING #asmDirectiveClobber
|
|
||||||
| 'bytes' expr #asmDirectiveBytes
|
|
||||||
| 'cycles' expr #asmDirectiveCycles
|
|
||||||
| 'pc' ( 'inline' | expr ) #asmDirectiveAddress
|
|
||||||
;
|
|
||||||
|
|
||||||
asmLines
|
|
||||||
: {cParser.setModeAsm(true);} asmLine* {cParser.setModeAsm(false);}
|
|
||||||
;
|
|
||||||
|
|
||||||
asmLine
|
|
||||||
: asmLabel
|
|
||||||
| asmInstruction
|
|
||||||
| asmBytes
|
|
||||||
;
|
|
||||||
|
|
||||||
asmLabel
|
|
||||||
: NAME ':' #asmLabelName
|
|
||||||
| '!' NAME? ':' #asmLabelMulti
|
|
||||||
;
|
|
||||||
|
|
||||||
asmInstruction
|
|
||||||
: MNEMONIC (asmParamMode)?
|
|
||||||
;
|
|
||||||
|
|
||||||
asmBytes
|
|
||||||
: '.byte' asmExpr ( ',' asmExpr)*
|
|
||||||
;
|
|
||||||
|
|
||||||
asmParamMode
|
|
||||||
: asmExpr #asmModeAbs
|
|
||||||
| '#' asmExpr #asmModeImm
|
|
||||||
| asmExpr ',' NAME #asmModeAbsXY
|
|
||||||
| '(' asmExpr ')' ',' NAME #asmModeIndIdxXY
|
|
||||||
| '(' asmExpr ',' NAME ')' #asmModeIdxIndXY
|
|
||||||
| '(' asmExpr ')' #asmModeInd
|
|
||||||
;
|
|
||||||
|
|
||||||
asmExpr
|
|
||||||
: '[' asmExpr ']' #asmExprPar
|
|
||||||
| asmExpr ( '.' ) asmExpr #asmExprBinary
|
|
||||||
| asmExpr ( '<<' | '>>' ) asmExpr #asmExprBinary
|
|
||||||
| ('+' | '-' | '<' | '>' ) asmExpr #asmExprUnary
|
|
||||||
| asmExpr ('*' | '/' ) asmExpr #asmExprBinary
|
|
||||||
| asmExpr ( '+' | '-' ) asmExpr #asmExprBinary
|
|
||||||
| NAME #asmExprLabel
|
|
||||||
| ASMREL #asmExprLabelRel
|
|
||||||
| '{' NAME '}' #asmExprReplace
|
|
||||||
| NUMBER #asmExprInt
|
|
||||||
| CHAR #asmExprChar
|
|
||||||
;
|
|
||||||
|
|
||||||
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'
|
|
||||||
;
|
|
||||||
|
|
||||||
|
|
||||||
IMPORT: 'import' { cParser.setModeImport(true); } ;
|
|
||||||
IMPORTFILE: '"' ('\\"' | ~'"')* '"' { cParser.isModeImport() }? { cParser.setModeImport(false); cParser.loadCFile(getText()); } ;
|
|
||||||
|
|
||||||
SIMPLETYPE: 'byte' | 'word' | 'dword' | 'bool' | 'char' | 'short' | 'int' | 'long' | 'void' ;
|
|
||||||
STRING : '"' ('\\"' | ~'"')* '"' [z]?([ps][mu]?)?[z]? { !cParser.isModeImport() }? ;
|
|
||||||
CHAR : '\'' ('\\'['"rfn] | ~'\'' ) '\'';
|
|
||||||
BOOLEAN : 'true' | 'false';
|
|
||||||
NUMBER : NUMFLOAT | NUMINT ;
|
|
||||||
NUMFLOAT : BINFLOAT | DECFLOAT | HEXFLOAT;
|
|
||||||
BINFLOAT : ('%' | '0b' | '0B' ) (BINDIGIT)* '.' BINDIGIT+;
|
|
||||||
DECFLOAT : (DECDIGIT)* '.' DECDIGIT+;
|
|
||||||
HEXFLOAT : ('$' | '0x' | '0X' ) (HEXDIGIT)* '.' HEXDIGIT+;
|
|
||||||
NUMINT : (DECINTEGER | HEXINTEGER | BININTEGER ) ([us][bcwisdl] | 'l')? ;
|
|
||||||
BININTEGER : '0' [bB] BINDIGIT+ | '%' BINDIGIT+ ;
|
|
||||||
DECINTEGER : DECDIGIT+ ;
|
|
||||||
HEXINTEGER : ( '$' | '0x' | '0X' ) HEXDIGIT+ ;
|
|
||||||
fragment BINDIGIT : [0-1];
|
|
||||||
fragment DECDIGIT : [0-9];
|
|
||||||
fragment HEXDIGIT : [0-9a-fA-F];
|
|
||||||
NAME : NAME_START NAME_CHAR* {!cParser.isTypedef(getText())}?;
|
|
||||||
TYPEDEFNAME : NAME_START NAME_CHAR* {cParser.isTypedef(getText())}?;
|
|
||||||
fragment NAME_START : [a-zA-Z_];
|
|
||||||
fragment NAME_CHAR : [a-zA-Z0-9_];
|
|
||||||
ASMREL: '!' NAME_CHAR* [+-]+ {cParser.isModeAsm()}? ;
|
|
||||||
KICKASM: '{{' .*? '}}';
|
|
||||||
|
|
||||||
// Add white space to the hidden channel 1
|
|
||||||
WS : [ \t\r\n\u00a0]+ -> channel(1);
|
|
||||||
// Add comments to the hidden channel 2
|
|
||||||
COMMENT_LINE : '//' ~[\r\n]* -> channel(2);
|
|
||||||
COMMENT_BLOCK : '/*' .*? '*/' -> channel(2);
|
|
@ -1,210 +0,0 @@
|
|||||||
T__0=1
|
|
||||||
T__1=2
|
|
||||||
T__2=3
|
|
||||||
T__3=4
|
|
||||||
T__4=5
|
|
||||||
T__5=6
|
|
||||||
T__6=7
|
|
||||||
T__7=8
|
|
||||||
T__8=9
|
|
||||||
T__9=10
|
|
||||||
T__10=11
|
|
||||||
T__11=12
|
|
||||||
T__12=13
|
|
||||||
T__13=14
|
|
||||||
T__14=15
|
|
||||||
T__15=16
|
|
||||||
T__16=17
|
|
||||||
T__17=18
|
|
||||||
T__18=19
|
|
||||||
T__19=20
|
|
||||||
T__20=21
|
|
||||||
T__21=22
|
|
||||||
T__22=23
|
|
||||||
T__23=24
|
|
||||||
T__24=25
|
|
||||||
T__25=26
|
|
||||||
T__26=27
|
|
||||||
T__27=28
|
|
||||||
T__28=29
|
|
||||||
T__29=30
|
|
||||||
T__30=31
|
|
||||||
T__31=32
|
|
||||||
T__32=33
|
|
||||||
T__33=34
|
|
||||||
T__34=35
|
|
||||||
T__35=36
|
|
||||||
T__36=37
|
|
||||||
T__37=38
|
|
||||||
T__38=39
|
|
||||||
T__39=40
|
|
||||||
T__40=41
|
|
||||||
T__41=42
|
|
||||||
T__42=43
|
|
||||||
T__43=44
|
|
||||||
T__44=45
|
|
||||||
T__45=46
|
|
||||||
T__46=47
|
|
||||||
T__47=48
|
|
||||||
T__48=49
|
|
||||||
T__49=50
|
|
||||||
T__50=51
|
|
||||||
T__51=52
|
|
||||||
T__52=53
|
|
||||||
T__53=54
|
|
||||||
T__54=55
|
|
||||||
T__55=56
|
|
||||||
T__56=57
|
|
||||||
T__57=58
|
|
||||||
T__58=59
|
|
||||||
T__59=60
|
|
||||||
T__60=61
|
|
||||||
T__61=62
|
|
||||||
T__62=63
|
|
||||||
T__63=64
|
|
||||||
T__64=65
|
|
||||||
T__65=66
|
|
||||||
T__66=67
|
|
||||||
T__67=68
|
|
||||||
T__68=69
|
|
||||||
T__69=70
|
|
||||||
T__70=71
|
|
||||||
T__71=72
|
|
||||||
T__72=73
|
|
||||||
T__73=74
|
|
||||||
T__74=75
|
|
||||||
T__75=76
|
|
||||||
T__76=77
|
|
||||||
T__77=78
|
|
||||||
T__78=79
|
|
||||||
T__79=80
|
|
||||||
T__80=81
|
|
||||||
T__81=82
|
|
||||||
T__82=83
|
|
||||||
T__83=84
|
|
||||||
T__84=85
|
|
||||||
T__85=86
|
|
||||||
T__86=87
|
|
||||||
T__87=88
|
|
||||||
T__88=89
|
|
||||||
T__89=90
|
|
||||||
T__90=91
|
|
||||||
T__91=92
|
|
||||||
T__92=93
|
|
||||||
MNEMONIC=94
|
|
||||||
IMPORT=95
|
|
||||||
IMPORTFILE=96
|
|
||||||
SIMPLETYPE=97
|
|
||||||
STRING=98
|
|
||||||
CHAR=99
|
|
||||||
BOOLEAN=100
|
|
||||||
NUMBER=101
|
|
||||||
NUMFLOAT=102
|
|
||||||
BINFLOAT=103
|
|
||||||
DECFLOAT=104
|
|
||||||
HEXFLOAT=105
|
|
||||||
NUMINT=106
|
|
||||||
BININTEGER=107
|
|
||||||
DECINTEGER=108
|
|
||||||
HEXINTEGER=109
|
|
||||||
NAME=110
|
|
||||||
TYPEDEFNAME=111
|
|
||||||
ASMREL=112
|
|
||||||
KICKASM=113
|
|
||||||
WS=114
|
|
||||||
COMMENT_LINE=115
|
|
||||||
COMMENT_BLOCK=116
|
|
||||||
';'=1
|
|
||||||
'typedef'=2
|
|
||||||
','=3
|
|
||||||
'='=4
|
|
||||||
'('=5
|
|
||||||
')'=6
|
|
||||||
'{'=7
|
|
||||||
'}'=8
|
|
||||||
'#pragma'=9
|
|
||||||
'reserve'=10
|
|
||||||
'#reserve'=11
|
|
||||||
'pc'=12
|
|
||||||
'#pc'=13
|
|
||||||
'target'=14
|
|
||||||
'#target'=15
|
|
||||||
'link'=16
|
|
||||||
'code_seg'=17
|
|
||||||
'data_seg'=18
|
|
||||||
'encoding'=19
|
|
||||||
'#encoding'=20
|
|
||||||
'const'=21
|
|
||||||
'extern'=22
|
|
||||||
'export'=23
|
|
||||||
'align'=24
|
|
||||||
'register'=25
|
|
||||||
'inline'=26
|
|
||||||
'volatile'=27
|
|
||||||
'interrupt'=28
|
|
||||||
'if'=29
|
|
||||||
'else'=30
|
|
||||||
'while'=31
|
|
||||||
'do'=32
|
|
||||||
'for'=33
|
|
||||||
'switch'=34
|
|
||||||
'return'=35
|
|
||||||
'break'=36
|
|
||||||
'continue'=37
|
|
||||||
'asm'=38
|
|
||||||
'default:'=39
|
|
||||||
'case'=40
|
|
||||||
':'=41
|
|
||||||
'..'=42
|
|
||||||
'signed'=43
|
|
||||||
'unsigned'=44
|
|
||||||
'*'=45
|
|
||||||
'['=46
|
|
||||||
']'=47
|
|
||||||
'struct'=48
|
|
||||||
'enum'=49
|
|
||||||
'.'=50
|
|
||||||
'->'=51
|
|
||||||
'sizeof'=52
|
|
||||||
'typeid'=53
|
|
||||||
'--'=54
|
|
||||||
'++'=55
|
|
||||||
'+'=56
|
|
||||||
'-'=57
|
|
||||||
'!'=58
|
|
||||||
'&'=59
|
|
||||||
'~'=60
|
|
||||||
'>>'=61
|
|
||||||
'<<'=62
|
|
||||||
'/'=63
|
|
||||||
'%'=64
|
|
||||||
'<'=65
|
|
||||||
'>'=66
|
|
||||||
'=='=67
|
|
||||||
'!='=68
|
|
||||||
'<='=69
|
|
||||||
'>='=70
|
|
||||||
'^'=71
|
|
||||||
'|'=72
|
|
||||||
'&&'=73
|
|
||||||
'||'=74
|
|
||||||
'?'=75
|
|
||||||
'+='=76
|
|
||||||
'-='=77
|
|
||||||
'*='=78
|
|
||||||
'/='=79
|
|
||||||
'%='=80
|
|
||||||
'<<='=81
|
|
||||||
'>>='=82
|
|
||||||
'&='=83
|
|
||||||
'|='=84
|
|
||||||
'^='=85
|
|
||||||
'kickasm'=86
|
|
||||||
'resource'=87
|
|
||||||
'uses'=88
|
|
||||||
'clobbers'=89
|
|
||||||
'bytes'=90
|
|
||||||
'cycles'=91
|
|
||||||
'.byte'=92
|
|
||||||
'#'=93
|
|
||||||
'import'=95
|
|
132
src/main/java/dk/camelot64/kickc/parser/KickCLexer.g4
Normal file
132
src/main/java/dk/camelot64/kickc/parser/KickCLexer.g4
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
// KickC grammar
|
||||||
|
lexer grammar KickCLexer;
|
||||||
|
|
||||||
|
tokens { TYPEDEFNAME }
|
||||||
|
|
||||||
|
@header {
|
||||||
|
}
|
||||||
|
|
||||||
|
@lexer::members {
|
||||||
|
CParser cParser;
|
||||||
|
|
||||||
|
public KickCLexer(CharStream input, CParser cParser) {
|
||||||
|
this(input);
|
||||||
|
this.cParser = cParser;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CURLY_BEGIN: '{' ;
|
||||||
|
CURLY_END: '}' ;
|
||||||
|
BRACKET_BEGIN : '[' ;
|
||||||
|
BRACKET_END : ']' ;
|
||||||
|
PAR_BEGIN: '(' ;
|
||||||
|
PAR_END: ')' ;
|
||||||
|
SEMICOLON: ';' ;
|
||||||
|
COLON: ':';
|
||||||
|
COMMA: ',' ;
|
||||||
|
RANGE : '..' ;
|
||||||
|
QUESTION : '?' ;
|
||||||
|
DOT : '.' ;
|
||||||
|
ARROW : '->' ;
|
||||||
|
PLUS: '+';
|
||||||
|
MINUS: '-';
|
||||||
|
ASTERISK : '*' ;
|
||||||
|
DIVIDE : '/' ;
|
||||||
|
MODULO : '%' ;
|
||||||
|
INC : '++' ;
|
||||||
|
DEC : '--' ;
|
||||||
|
AND : '&' ;
|
||||||
|
BIT_NOT : '~' ;
|
||||||
|
BIT_XOR : '^' ;
|
||||||
|
BIT_OR : '|' ;
|
||||||
|
SHIFT_LEFT : '<<' ;
|
||||||
|
SHIFT_RIGHT : '>>' ;
|
||||||
|
EQUAL: '==' ;
|
||||||
|
NOT_EQUAL: '!=' ;
|
||||||
|
LESS_THAN: '<';
|
||||||
|
LESS_THAN_EQUAL: '<=';
|
||||||
|
GREATER_THAN_EQUAL: '>=';
|
||||||
|
GREATER_THAN : '>' ;
|
||||||
|
LOGIC_AND : '&&' ;
|
||||||
|
LOGIC_OR : '||' ;
|
||||||
|
ASSIGN: '=' ;
|
||||||
|
ASSIGN_COMPOUND : '+=' | '-=' | '*=' | '/=' | '%=' | '<<=' | '>>=' | '&=' | '|=' | '^=' ;
|
||||||
|
ASM_IMM : '#' ;
|
||||||
|
|
||||||
|
TYPEDEF: 'typedef' ;
|
||||||
|
PRAGMA: '#pragma' ;
|
||||||
|
RESERVE:'reserve' ;
|
||||||
|
PC:'pc';
|
||||||
|
TARGET:'target';
|
||||||
|
LINK:'link';
|
||||||
|
CODESEG:'code_seg';
|
||||||
|
DATASEG:'data_seg';
|
||||||
|
ENCODING:'encoding';
|
||||||
|
CONST: 'const' ;
|
||||||
|
EXTERN: 'extern' ;
|
||||||
|
EXPORT: 'export' ;
|
||||||
|
ALIGN: 'align' ;
|
||||||
|
REGISTER: 'register' ;
|
||||||
|
INLINE: 'inline' ;
|
||||||
|
VOLATILE: 'volatile' ;
|
||||||
|
INTERRUPT: 'interrupt' ;
|
||||||
|
IF: 'if' ;
|
||||||
|
ELSE: 'else' ;
|
||||||
|
WHILE: 'while' ;
|
||||||
|
DO: 'do' ;
|
||||||
|
FOR: 'for' ;
|
||||||
|
SWITCH: 'switch' ;
|
||||||
|
RETURN: 'return' ;
|
||||||
|
BREAK: 'break' ;
|
||||||
|
CONTINUE: 'continue' ;
|
||||||
|
ASM: 'asm' ;
|
||||||
|
DEFAULT : 'default' ;
|
||||||
|
CASE : 'case' ;
|
||||||
|
STRUCT : 'struct' ;
|
||||||
|
ENUM : 'enum' ;
|
||||||
|
SIZEOF : 'sizeof' ;
|
||||||
|
TYPEID : 'typeid' ;
|
||||||
|
KICKASM : 'kickasm' ;
|
||||||
|
RESOURCE : 'resource' ;
|
||||||
|
USES : 'uses' ;
|
||||||
|
CLOBBERS : 'clobbers' ;
|
||||||
|
BYTES : 'bytes' ;
|
||||||
|
CYCLES : 'cycles' ;
|
||||||
|
LOGIC_NOT : '!' ;
|
||||||
|
ASM_BYTE : '.byte' ;
|
||||||
|
SIGNED : 'signed' ;
|
||||||
|
UNSIGNED : 'unsigned' ;
|
||||||
|
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'
|
||||||
|
;
|
||||||
|
IMPORT: 'import' { cParser.setModeImport(true); } ;
|
||||||
|
SIMPLETYPE: 'byte' | 'word' | 'dword' | 'bool' | 'char' | 'short' | 'int' | 'long' | 'void' ;
|
||||||
|
STRING : '"' ('\\"' | ~'"')* '"' [z]?([ps][mu]?)?[z]? { if(cParser.isModeImport()) { cParser.setModeImport(false); cParser.loadCFile(getText()); } } ;
|
||||||
|
CHAR : '\'' ('\\'['"rfn] | ~'\'' ) '\'';
|
||||||
|
BOOLEAN : 'true' | 'false';
|
||||||
|
NUMBER : NUMFLOAT | NUMINT ;
|
||||||
|
NUMFLOAT : BINFLOAT | DECFLOAT | HEXFLOAT;
|
||||||
|
BINFLOAT : ('%' | '0b' | '0B' ) (BINDIGIT)* '.' BINDIGIT+;
|
||||||
|
DECFLOAT : (DECDIGIT)* '.' DECDIGIT+;
|
||||||
|
HEXFLOAT : ('$' | '0x' | '0X' ) (HEXDIGIT)* '.' HEXDIGIT+;
|
||||||
|
NUMINT : (DECINTEGER | HEXINTEGER | BININTEGER ) ([us][bcwisdl] | 'l')? ;
|
||||||
|
BININTEGER : '0' [bB] BINDIGIT+ | '%' BINDIGIT+ ;
|
||||||
|
DECINTEGER : DECDIGIT+ ;
|
||||||
|
HEXINTEGER : ( '$' | '0x' | '0X' ) HEXDIGIT+ ;
|
||||||
|
fragment BINDIGIT : [0-1];
|
||||||
|
fragment DECDIGIT : [0-9];
|
||||||
|
fragment HEXDIGIT : [0-9a-fA-F];
|
||||||
|
NAME : NAME_START NAME_CHAR* {if(cParser.isTypedef(getText())) setType(TYPEDEFNAME); };
|
||||||
|
fragment NAME_START : [a-zA-Z_];
|
||||||
|
fragment NAME_CHAR : [a-zA-Z0-9_];
|
||||||
|
ASMREL: '!' NAME_CHAR* [+-]+ {cParser.isModeAsm()}? ;
|
||||||
|
KICKASM_BODY: '{{' .*? '}}';
|
||||||
|
|
||||||
|
// Add white space to the hidden channel 1
|
||||||
|
WS : [ \t\r\n\u00a0]+ -> channel(1);
|
||||||
|
// Add comments to the hidden channel 2
|
||||||
|
COMMENT_LINE : '//' ~[\r\n]* -> channel(2);
|
||||||
|
COMMENT_BLOCK : '/*' .*? '*/' -> channel(2);
|
File diff suppressed because it is too large
Load Diff
@ -1,210 +1,182 @@
|
|||||||
T__0=1
|
TYPEDEFNAME=1
|
||||||
T__1=2
|
CURLY_BEGIN=2
|
||||||
T__2=3
|
CURLY_END=3
|
||||||
T__3=4
|
BRACKET_BEGIN=4
|
||||||
T__4=5
|
BRACKET_END=5
|
||||||
T__5=6
|
PAR_BEGIN=6
|
||||||
T__6=7
|
PAR_END=7
|
||||||
T__7=8
|
SEMICOLON=8
|
||||||
T__8=9
|
COLON=9
|
||||||
T__9=10
|
COMMA=10
|
||||||
T__10=11
|
RANGE=11
|
||||||
T__11=12
|
QUESTION=12
|
||||||
T__12=13
|
DOT=13
|
||||||
T__13=14
|
ARROW=14
|
||||||
T__14=15
|
PLUS=15
|
||||||
T__15=16
|
MINUS=16
|
||||||
T__16=17
|
ASTERISK=17
|
||||||
T__17=18
|
DIVIDE=18
|
||||||
T__18=19
|
MODULO=19
|
||||||
T__19=20
|
INC=20
|
||||||
T__20=21
|
DEC=21
|
||||||
T__21=22
|
AND=22
|
||||||
T__22=23
|
BIT_NOT=23
|
||||||
T__23=24
|
BIT_XOR=24
|
||||||
T__24=25
|
BIT_OR=25
|
||||||
T__25=26
|
SHIFT_LEFT=26
|
||||||
T__26=27
|
SHIFT_RIGHT=27
|
||||||
T__27=28
|
EQUAL=28
|
||||||
T__28=29
|
NOT_EQUAL=29
|
||||||
T__29=30
|
LESS_THAN=30
|
||||||
T__30=31
|
LESS_THAN_EQUAL=31
|
||||||
T__31=32
|
GREATER_THAN_EQUAL=32
|
||||||
T__32=33
|
GREATER_THAN=33
|
||||||
T__33=34
|
LOGIC_AND=34
|
||||||
T__34=35
|
LOGIC_OR=35
|
||||||
T__35=36
|
ASSIGN=36
|
||||||
T__36=37
|
ASSIGN_COMPOUND=37
|
||||||
T__37=38
|
ASM_IMM=38
|
||||||
T__38=39
|
TYPEDEF=39
|
||||||
T__39=40
|
PRAGMA=40
|
||||||
T__40=41
|
RESERVE=41
|
||||||
T__41=42
|
PC=42
|
||||||
T__42=43
|
TARGET=43
|
||||||
T__43=44
|
LINK=44
|
||||||
T__44=45
|
CODESEG=45
|
||||||
T__45=46
|
DATASEG=46
|
||||||
T__46=47
|
ENCODING=47
|
||||||
T__47=48
|
CONST=48
|
||||||
T__48=49
|
EXTERN=49
|
||||||
T__49=50
|
EXPORT=50
|
||||||
T__50=51
|
ALIGN=51
|
||||||
T__51=52
|
REGISTER=52
|
||||||
T__52=53
|
INLINE=53
|
||||||
T__53=54
|
VOLATILE=54
|
||||||
T__54=55
|
INTERRUPT=55
|
||||||
T__55=56
|
IF=56
|
||||||
T__56=57
|
ELSE=57
|
||||||
T__57=58
|
WHILE=58
|
||||||
T__58=59
|
DO=59
|
||||||
T__59=60
|
FOR=60
|
||||||
T__60=61
|
SWITCH=61
|
||||||
T__61=62
|
RETURN=62
|
||||||
T__62=63
|
BREAK=63
|
||||||
T__63=64
|
CONTINUE=64
|
||||||
T__64=65
|
ASM=65
|
||||||
T__65=66
|
DEFAULT=66
|
||||||
T__66=67
|
CASE=67
|
||||||
T__67=68
|
STRUCT=68
|
||||||
T__68=69
|
ENUM=69
|
||||||
T__69=70
|
SIZEOF=70
|
||||||
T__70=71
|
TYPEID=71
|
||||||
T__71=72
|
KICKASM=72
|
||||||
T__72=73
|
RESOURCE=73
|
||||||
T__73=74
|
USES=74
|
||||||
T__74=75
|
CLOBBERS=75
|
||||||
T__75=76
|
BYTES=76
|
||||||
T__76=77
|
CYCLES=77
|
||||||
T__77=78
|
LOGIC_NOT=78
|
||||||
T__78=79
|
ASM_BYTE=79
|
||||||
T__79=80
|
SIGNED=80
|
||||||
T__80=81
|
UNSIGNED=81
|
||||||
T__81=82
|
MNEMONIC=82
|
||||||
T__82=83
|
IMPORT=83
|
||||||
T__83=84
|
SIMPLETYPE=84
|
||||||
T__84=85
|
STRING=85
|
||||||
T__85=86
|
CHAR=86
|
||||||
T__86=87
|
BOOLEAN=87
|
||||||
T__87=88
|
NUMBER=88
|
||||||
T__88=89
|
NUMFLOAT=89
|
||||||
T__89=90
|
BINFLOAT=90
|
||||||
T__90=91
|
DECFLOAT=91
|
||||||
T__91=92
|
HEXFLOAT=92
|
||||||
T__92=93
|
NUMINT=93
|
||||||
MNEMONIC=94
|
BININTEGER=94
|
||||||
IMPORT=95
|
DECINTEGER=95
|
||||||
IMPORTFILE=96
|
HEXINTEGER=96
|
||||||
SIMPLETYPE=97
|
NAME=97
|
||||||
STRING=98
|
ASMREL=98
|
||||||
CHAR=99
|
KICKASM_BODY=99
|
||||||
BOOLEAN=100
|
WS=100
|
||||||
NUMBER=101
|
COMMENT_LINE=101
|
||||||
NUMFLOAT=102
|
COMMENT_BLOCK=102
|
||||||
BINFLOAT=103
|
'{'=2
|
||||||
DECFLOAT=104
|
'}'=3
|
||||||
HEXFLOAT=105
|
'['=4
|
||||||
NUMINT=106
|
']'=5
|
||||||
BININTEGER=107
|
'('=6
|
||||||
DECINTEGER=108
|
')'=7
|
||||||
HEXINTEGER=109
|
';'=8
|
||||||
NAME=110
|
':'=9
|
||||||
TYPEDEFNAME=111
|
','=10
|
||||||
ASMREL=112
|
'..'=11
|
||||||
KICKASM=113
|
'?'=12
|
||||||
WS=114
|
'.'=13
|
||||||
COMMENT_LINE=115
|
'->'=14
|
||||||
COMMENT_BLOCK=116
|
'+'=15
|
||||||
';'=1
|
'-'=16
|
||||||
'typedef'=2
|
'*'=17
|
||||||
','=3
|
'/'=18
|
||||||
'='=4
|
'%'=19
|
||||||
'('=5
|
'++'=20
|
||||||
')'=6
|
'--'=21
|
||||||
'{'=7
|
'&'=22
|
||||||
'}'=8
|
'~'=23
|
||||||
'#pragma'=9
|
'^'=24
|
||||||
'reserve'=10
|
'|'=25
|
||||||
'#reserve'=11
|
'<<'=26
|
||||||
'pc'=12
|
'>>'=27
|
||||||
'#pc'=13
|
'=='=28
|
||||||
'target'=14
|
'!='=29
|
||||||
'#target'=15
|
'<'=30
|
||||||
'link'=16
|
'<='=31
|
||||||
'code_seg'=17
|
'>='=32
|
||||||
'data_seg'=18
|
'>'=33
|
||||||
'encoding'=19
|
'&&'=34
|
||||||
'#encoding'=20
|
'||'=35
|
||||||
'const'=21
|
'='=36
|
||||||
'extern'=22
|
'#'=38
|
||||||
'export'=23
|
'typedef'=39
|
||||||
'align'=24
|
'#pragma'=40
|
||||||
'register'=25
|
'reserve'=41
|
||||||
'inline'=26
|
'pc'=42
|
||||||
'volatile'=27
|
'target'=43
|
||||||
'interrupt'=28
|
'link'=44
|
||||||
'if'=29
|
'code_seg'=45
|
||||||
'else'=30
|
'data_seg'=46
|
||||||
'while'=31
|
'encoding'=47
|
||||||
'do'=32
|
'const'=48
|
||||||
'for'=33
|
'extern'=49
|
||||||
'switch'=34
|
'export'=50
|
||||||
'return'=35
|
'align'=51
|
||||||
'break'=36
|
'register'=52
|
||||||
'continue'=37
|
'inline'=53
|
||||||
'asm'=38
|
'volatile'=54
|
||||||
'default:'=39
|
'interrupt'=55
|
||||||
'case'=40
|
'if'=56
|
||||||
':'=41
|
'else'=57
|
||||||
'..'=42
|
'while'=58
|
||||||
'signed'=43
|
'do'=59
|
||||||
'unsigned'=44
|
'for'=60
|
||||||
'*'=45
|
'switch'=61
|
||||||
'['=46
|
'return'=62
|
||||||
']'=47
|
'break'=63
|
||||||
'struct'=48
|
'continue'=64
|
||||||
'enum'=49
|
'asm'=65
|
||||||
'.'=50
|
'default'=66
|
||||||
'->'=51
|
'case'=67
|
||||||
'sizeof'=52
|
'struct'=68
|
||||||
'typeid'=53
|
'enum'=69
|
||||||
'--'=54
|
'sizeof'=70
|
||||||
'++'=55
|
'typeid'=71
|
||||||
'+'=56
|
'kickasm'=72
|
||||||
'-'=57
|
'resource'=73
|
||||||
'!'=58
|
'uses'=74
|
||||||
'&'=59
|
'clobbers'=75
|
||||||
'~'=60
|
'bytes'=76
|
||||||
'>>'=61
|
'cycles'=77
|
||||||
'<<'=62
|
'!'=78
|
||||||
'/'=63
|
'.byte'=79
|
||||||
'%'=64
|
'signed'=80
|
||||||
'<'=65
|
'unsigned'=81
|
||||||
'>'=66
|
'import'=83
|
||||||
'=='=67
|
|
||||||
'!='=68
|
|
||||||
'<='=69
|
|
||||||
'>='=70
|
|
||||||
'^'=71
|
|
||||||
'|'=72
|
|
||||||
'&&'=73
|
|
||||||
'||'=74
|
|
||||||
'?'=75
|
|
||||||
'+='=76
|
|
||||||
'-='=77
|
|
||||||
'*='=78
|
|
||||||
'/='=79
|
|
||||||
'%='=80
|
|
||||||
'<<='=81
|
|
||||||
'>>='=82
|
|
||||||
'&='=83
|
|
||||||
'|='=84
|
|
||||||
'^='=85
|
|
||||||
'kickasm'=86
|
|
||||||
'resource'=87
|
|
||||||
'uses'=88
|
|
||||||
'clobbers'=89
|
|
||||||
'bytes'=90
|
|
||||||
'cycles'=91
|
|
||||||
'.byte'=92
|
|
||||||
'#'=93
|
|
||||||
'import'=95
|
|
||||||
|
293
src/main/java/dk/camelot64/kickc/parser/KickCParser.g4
Normal file
293
src/main/java/dk/camelot64/kickc/parser/KickCParser.g4
Normal file
@ -0,0 +1,293 @@
|
|||||||
|
// KickC grammar
|
||||||
|
parser grammar KickCParser;
|
||||||
|
|
||||||
|
options { tokenVocab=KickCLexer; }
|
||||||
|
|
||||||
|
@header {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@parser::members {
|
||||||
|
CParser cParser;
|
||||||
|
|
||||||
|
public KickCParser(TokenStream input, CParser cParser) {
|
||||||
|
this(input);
|
||||||
|
this.cParser = cParser;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
file
|
||||||
|
: declSeq EOF
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
|
asmFile
|
||||||
|
: asmLines EOF
|
||||||
|
;
|
||||||
|
|
||||||
|
declSeq
|
||||||
|
: declOrImport*
|
||||||
|
;
|
||||||
|
|
||||||
|
declOrImport
|
||||||
|
: decl
|
||||||
|
| importDecl
|
||||||
|
;
|
||||||
|
|
||||||
|
importDecl
|
||||||
|
: IMPORT STRING
|
||||||
|
;
|
||||||
|
|
||||||
|
decl
|
||||||
|
: declVariables SEMICOLON
|
||||||
|
| structDef SEMICOLON
|
||||||
|
| enumDef SEMICOLON
|
||||||
|
| declFunction
|
||||||
|
| declKasm
|
||||||
|
| globalDirective
|
||||||
|
| typeDef SEMICOLON
|
||||||
|
;
|
||||||
|
|
||||||
|
typeDef
|
||||||
|
: TYPEDEF typeDecl NAME {cParser.addTypedef($NAME.text);}
|
||||||
|
;
|
||||||
|
|
||||||
|
declTypes
|
||||||
|
: directive* typeDecl directive*
|
||||||
|
;
|
||||||
|
|
||||||
|
declVariables
|
||||||
|
: declTypes declVariableList
|
||||||
|
;
|
||||||
|
|
||||||
|
declVariableList
|
||||||
|
: declVariableInit
|
||||||
|
| declVariableList COMMA declVariableInit
|
||||||
|
;
|
||||||
|
|
||||||
|
declVariableInit
|
||||||
|
: NAME (ASSIGN expr)? #declVariableInitExpr
|
||||||
|
| NAME ASSIGN declKasm #declVariableInitKasm
|
||||||
|
;
|
||||||
|
|
||||||
|
declFunction
|
||||||
|
: declTypes NAME PAR_BEGIN parameterListDecl? PAR_END CURLY_BEGIN stmtSeq? CURLY_END
|
||||||
|
;
|
||||||
|
|
||||||
|
parameterListDecl
|
||||||
|
: parameterDecl (COMMA parameterDecl)* ;
|
||||||
|
|
||||||
|
parameterDecl
|
||||||
|
: declTypes NAME #parameterDeclType
|
||||||
|
| SIMPLETYPE #parameterDeclVoid
|
||||||
|
;
|
||||||
|
|
||||||
|
globalDirective
|
||||||
|
: (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 PAR_BEGIN NUMBER PAR_END #directiveAlign
|
||||||
|
| REGISTER ( PAR_BEGIN NAME PAR_END)? #directiveRegister
|
||||||
|
| INLINE #directiveInline
|
||||||
|
| VOLATILE #directiveVolatile
|
||||||
|
| INTERRUPT ( PAR_BEGIN NAME PAR_END )? #directiveInterrupt
|
||||||
|
| RESERVE PAR_BEGIN NUMBER ( COMMA NUMBER )* PAR_END #directiveReserveZp
|
||||||
|
;
|
||||||
|
|
||||||
|
stmtSeq
|
||||||
|
: stmt+
|
||||||
|
;
|
||||||
|
|
||||||
|
stmt
|
||||||
|
: declVariables SEMICOLON #stmtDeclVar
|
||||||
|
| CURLY_BEGIN stmtSeq? CURLY_END #stmtBlock
|
||||||
|
| commaExpr SEMICOLON #stmtExpr
|
||||||
|
| 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 SEMICOLON #stmtDoWhile
|
||||||
|
| directive* FOR PAR_BEGIN forLoop PAR_END stmt #stmtFor
|
||||||
|
| SWITCH PAR_BEGIN commaExpr PAR_END CURLY_BEGIN switchCases CURLY_END #stmtSwitch
|
||||||
|
| RETURN commaExpr? SEMICOLON #stmtReturn
|
||||||
|
| BREAK SEMICOLON #stmtBreak
|
||||||
|
| CONTINUE SEMICOLON #stmtContinue
|
||||||
|
| ASM asmDirectives? CURLY_BEGIN asmLines CURLY_END #stmtAsm
|
||||||
|
| declKasm #stmtDeclKasm
|
||||||
|
;
|
||||||
|
|
||||||
|
switchCases:
|
||||||
|
switchCase+ ( DEFAULT COLON stmtSeq? )?
|
||||||
|
;
|
||||||
|
|
||||||
|
switchCase:
|
||||||
|
CASE expr COLON stmtSeq?
|
||||||
|
;
|
||||||
|
|
||||||
|
forLoop
|
||||||
|
: forClassicInit SEMICOLON commaExpr SEMICOLON commaExpr? #forClassic
|
||||||
|
| declTypes? NAME COLON expr RANGE expr #forRange
|
||||||
|
;
|
||||||
|
|
||||||
|
forClassicInit
|
||||||
|
: declVariables? #forClassicInitDecl
|
||||||
|
| commaExpr #forClassicInitExpr
|
||||||
|
;
|
||||||
|
|
||||||
|
typeDecl
|
||||||
|
: PAR_BEGIN typeDecl PAR_END #typePar
|
||||||
|
| SIMPLETYPE #typeSimple
|
||||||
|
| (SIGNED|UNSIGNED) SIMPLETYPE? #typeSignedSimple
|
||||||
|
| typeDecl ASTERISK #typePtr
|
||||||
|
| typeDecl BRACKET_BEGIN (expr)? BRACKET_END #typeArray
|
||||||
|
| typeDecl PAR_BEGIN PAR_END #typeProcedure
|
||||||
|
| structDef #typeStructDef
|
||||||
|
| structRef #typeStructRef
|
||||||
|
| enumDef #typeEnumDef
|
||||||
|
| enumRef #typeEnumRef
|
||||||
|
| TYPEDEFNAME #typeNamedRef
|
||||||
|
;
|
||||||
|
|
||||||
|
structRef
|
||||||
|
: STRUCT NAME
|
||||||
|
;
|
||||||
|
|
||||||
|
structDef
|
||||||
|
: STRUCT NAME? CURLY_BEGIN structMembers+ CURLY_END
|
||||||
|
;
|
||||||
|
|
||||||
|
structMembers
|
||||||
|
: declVariables SEMICOLON
|
||||||
|
;
|
||||||
|
|
||||||
|
enumRef
|
||||||
|
: ENUM NAME
|
||||||
|
;
|
||||||
|
|
||||||
|
enumDef
|
||||||
|
: ENUM NAME? CURLY_BEGIN enumMemberList CURLY_END
|
||||||
|
;
|
||||||
|
|
||||||
|
enumMemberList
|
||||||
|
: enumMember
|
||||||
|
| enumMemberList COMMA enumMember
|
||||||
|
;
|
||||||
|
|
||||||
|
enumMember
|
||||||
|
: NAME ( ASSIGN expr )?
|
||||||
|
;
|
||||||
|
|
||||||
|
commaExpr
|
||||||
|
: expr #commaNone
|
||||||
|
| commaExpr COMMA expr #commaSimple
|
||||||
|
;
|
||||||
|
|
||||||
|
expr
|
||||||
|
: PAR_BEGIN commaExpr PAR_END #exprPar
|
||||||
|
| expr DOT NAME #exprDot
|
||||||
|
| expr ARROW NAME #exprArrow
|
||||||
|
| 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
|
||||||
|
| (DEC | INC ) expr #exprPreMod
|
||||||
|
| expr (DEC | INC ) #exprPostMod
|
||||||
|
| ASTERISK expr #exprPtr
|
||||||
|
| (PLUS | MINUS | LOGIC_NOT | AND | BIT_NOT) expr #exprUnary
|
||||||
|
| expr (SHIFT_RIGHT | SHIFT_LEFT ) expr #exprBinary
|
||||||
|
| expr (ASTERISK | DIVIDE | MODULO ) expr #exprBinary
|
||||||
|
| expr ( PLUS | MINUS) expr #exprBinary
|
||||||
|
| (LESS_THAN | GREATER_THAN) expr #exprUnary
|
||||||
|
| expr ( EQUAL | NOT_EQUAL | LESS_THAN | LESS_THAN_EQUAL | GREATER_THAN_EQUAL | GREATER_THAN ) expr #exprBinary
|
||||||
|
| expr ( AND ) expr #exprBinary
|
||||||
|
| expr ( BIT_XOR ) expr #exprBinary
|
||||||
|
| expr ( BIT_OR ) expr #exprBinary
|
||||||
|
| expr ( LOGIC_AND ) expr #exprBinary
|
||||||
|
| expr ( LOGIC_OR ) expr #exprBinary
|
||||||
|
| expr QUESTION expr COLON expr #exprTernary
|
||||||
|
| <assoc=right> expr ASSIGN expr #exprAssignment
|
||||||
|
| <assoc=right> expr ASSIGN_COMPOUND expr #exprAssignmentCompound
|
||||||
|
| CURLY_BEGIN expr (COMMA expr )* CURLY_END #initList
|
||||||
|
| NAME #exprId
|
||||||
|
| NUMBER #exprNumber
|
||||||
|
| STRING+ #exprString
|
||||||
|
| CHAR #exprChar
|
||||||
|
| BOOLEAN #exprBool
|
||||||
|
;
|
||||||
|
|
||||||
|
parameterList
|
||||||
|
: expr (COMMA expr)*
|
||||||
|
;
|
||||||
|
|
||||||
|
declKasm
|
||||||
|
: KICKASM asmDirectives? KICKASM_BODY
|
||||||
|
;
|
||||||
|
|
||||||
|
asmDirectives
|
||||||
|
: PAR_BEGIN asmDirective ( COMMA asmDirective )* PAR_END
|
||||||
|
;
|
||||||
|
|
||||||
|
asmDirective
|
||||||
|
: RESOURCE STRING #asmDirectiveResource
|
||||||
|
| USES NAME #asmDirectiveUses
|
||||||
|
| CLOBBERS STRING #asmDirectiveClobber
|
||||||
|
| BYTES expr #asmDirectiveBytes
|
||||||
|
| CYCLES expr #asmDirectiveCycles
|
||||||
|
| PC ( INLINE | expr ) #asmDirectiveAddress
|
||||||
|
;
|
||||||
|
|
||||||
|
asmLines
|
||||||
|
: {cParser.setModeAsm(true);} asmLine* {cParser.setModeAsm(false);}
|
||||||
|
;
|
||||||
|
|
||||||
|
asmLine
|
||||||
|
: asmLabel
|
||||||
|
| asmInstruction
|
||||||
|
| asmBytes
|
||||||
|
;
|
||||||
|
|
||||||
|
asmLabel
|
||||||
|
: NAME COLON #asmLabelName
|
||||||
|
| LOGIC_NOT NAME? COLON #asmLabelMulti
|
||||||
|
;
|
||||||
|
|
||||||
|
asmInstruction
|
||||||
|
: MNEMONIC (asmParamMode)?
|
||||||
|
;
|
||||||
|
|
||||||
|
asmBytes
|
||||||
|
: ASM_BYTE asmExpr ( COMMA asmExpr)*
|
||||||
|
;
|
||||||
|
|
||||||
|
asmParamMode
|
||||||
|
: asmExpr #asmModeAbs
|
||||||
|
| ASM_IMM asmExpr #asmModeImm
|
||||||
|
| asmExpr COMMA NAME #asmModeAbsXY
|
||||||
|
| PAR_BEGIN asmExpr PAR_END COMMA NAME #asmModeIndIdxXY
|
||||||
|
| PAR_BEGIN asmExpr COMMA NAME PAR_END #asmModeIdxIndXY
|
||||||
|
| PAR_BEGIN asmExpr PAR_END #asmModeInd
|
||||||
|
;
|
||||||
|
|
||||||
|
asmExpr
|
||||||
|
: BRACKET_BEGIN asmExpr BRACKET_END #asmExprPar
|
||||||
|
| asmExpr ( DOT ) asmExpr #asmExprBinary
|
||||||
|
| asmExpr ( SHIFT_LEFT | SHIFT_RIGHT ) asmExpr #asmExprBinary
|
||||||
|
| (PLUS | MINUS | LESS_THAN | GREATER_THAN ) asmExpr #asmExprUnary
|
||||||
|
| asmExpr (ASTERISK | DIVIDE ) asmExpr #asmExprBinary
|
||||||
|
| asmExpr ( PLUS | MINUS ) asmExpr #asmExprBinary
|
||||||
|
| NAME #asmExprLabel
|
||||||
|
| ASMREL #asmExprLabelRel
|
||||||
|
| CURLY_BEGIN NAME CURLY_END #asmExprReplace
|
||||||
|
| NUMBER #asmExprInt
|
||||||
|
| CHAR #asmExprChar
|
||||||
|
;
|
File diff suppressed because it is too large
Load Diff
182
src/main/java/dk/camelot64/kickc/parser/KickCParser.tokens
Normal file
182
src/main/java/dk/camelot64/kickc/parser/KickCParser.tokens
Normal file
@ -0,0 +1,182 @@
|
|||||||
|
TYPEDEFNAME=1
|
||||||
|
CURLY_BEGIN=2
|
||||||
|
CURLY_END=3
|
||||||
|
BRACKET_BEGIN=4
|
||||||
|
BRACKET_END=5
|
||||||
|
PAR_BEGIN=6
|
||||||
|
PAR_END=7
|
||||||
|
SEMICOLON=8
|
||||||
|
COLON=9
|
||||||
|
COMMA=10
|
||||||
|
RANGE=11
|
||||||
|
QUESTION=12
|
||||||
|
DOT=13
|
||||||
|
ARROW=14
|
||||||
|
PLUS=15
|
||||||
|
MINUS=16
|
||||||
|
ASTERISK=17
|
||||||
|
DIVIDE=18
|
||||||
|
MODULO=19
|
||||||
|
INC=20
|
||||||
|
DEC=21
|
||||||
|
AND=22
|
||||||
|
BIT_NOT=23
|
||||||
|
BIT_XOR=24
|
||||||
|
BIT_OR=25
|
||||||
|
SHIFT_LEFT=26
|
||||||
|
SHIFT_RIGHT=27
|
||||||
|
EQUAL=28
|
||||||
|
NOT_EQUAL=29
|
||||||
|
LESS_THAN=30
|
||||||
|
LESS_THAN_EQUAL=31
|
||||||
|
GREATER_THAN_EQUAL=32
|
||||||
|
GREATER_THAN=33
|
||||||
|
LOGIC_AND=34
|
||||||
|
LOGIC_OR=35
|
||||||
|
ASSIGN=36
|
||||||
|
ASSIGN_COMPOUND=37
|
||||||
|
ASM_IMM=38
|
||||||
|
TYPEDEF=39
|
||||||
|
PRAGMA=40
|
||||||
|
RESERVE=41
|
||||||
|
PC=42
|
||||||
|
TARGET=43
|
||||||
|
LINK=44
|
||||||
|
CODESEG=45
|
||||||
|
DATASEG=46
|
||||||
|
ENCODING=47
|
||||||
|
CONST=48
|
||||||
|
EXTERN=49
|
||||||
|
EXPORT=50
|
||||||
|
ALIGN=51
|
||||||
|
REGISTER=52
|
||||||
|
INLINE=53
|
||||||
|
VOLATILE=54
|
||||||
|
INTERRUPT=55
|
||||||
|
IF=56
|
||||||
|
ELSE=57
|
||||||
|
WHILE=58
|
||||||
|
DO=59
|
||||||
|
FOR=60
|
||||||
|
SWITCH=61
|
||||||
|
RETURN=62
|
||||||
|
BREAK=63
|
||||||
|
CONTINUE=64
|
||||||
|
ASM=65
|
||||||
|
DEFAULT=66
|
||||||
|
CASE=67
|
||||||
|
STRUCT=68
|
||||||
|
ENUM=69
|
||||||
|
SIZEOF=70
|
||||||
|
TYPEID=71
|
||||||
|
KICKASM=72
|
||||||
|
RESOURCE=73
|
||||||
|
USES=74
|
||||||
|
CLOBBERS=75
|
||||||
|
BYTES=76
|
||||||
|
CYCLES=77
|
||||||
|
LOGIC_NOT=78
|
||||||
|
ASM_BYTE=79
|
||||||
|
SIGNED=80
|
||||||
|
UNSIGNED=81
|
||||||
|
MNEMONIC=82
|
||||||
|
IMPORT=83
|
||||||
|
SIMPLETYPE=84
|
||||||
|
STRING=85
|
||||||
|
CHAR=86
|
||||||
|
BOOLEAN=87
|
||||||
|
NUMBER=88
|
||||||
|
NUMFLOAT=89
|
||||||
|
BINFLOAT=90
|
||||||
|
DECFLOAT=91
|
||||||
|
HEXFLOAT=92
|
||||||
|
NUMINT=93
|
||||||
|
BININTEGER=94
|
||||||
|
DECINTEGER=95
|
||||||
|
HEXINTEGER=96
|
||||||
|
NAME=97
|
||||||
|
ASMREL=98
|
||||||
|
KICKASM_BODY=99
|
||||||
|
WS=100
|
||||||
|
COMMENT_LINE=101
|
||||||
|
COMMENT_BLOCK=102
|
||||||
|
'{'=2
|
||||||
|
'}'=3
|
||||||
|
'['=4
|
||||||
|
']'=5
|
||||||
|
'('=6
|
||||||
|
')'=7
|
||||||
|
';'=8
|
||||||
|
':'=9
|
||||||
|
','=10
|
||||||
|
'..'=11
|
||||||
|
'?'=12
|
||||||
|
'.'=13
|
||||||
|
'->'=14
|
||||||
|
'+'=15
|
||||||
|
'-'=16
|
||||||
|
'*'=17
|
||||||
|
'/'=18
|
||||||
|
'%'=19
|
||||||
|
'++'=20
|
||||||
|
'--'=21
|
||||||
|
'&'=22
|
||||||
|
'~'=23
|
||||||
|
'^'=24
|
||||||
|
'|'=25
|
||||||
|
'<<'=26
|
||||||
|
'>>'=27
|
||||||
|
'=='=28
|
||||||
|
'!='=29
|
||||||
|
'<'=30
|
||||||
|
'<='=31
|
||||||
|
'>='=32
|
||||||
|
'>'=33
|
||||||
|
'&&'=34
|
||||||
|
'||'=35
|
||||||
|
'='=36
|
||||||
|
'#'=38
|
||||||
|
'typedef'=39
|
||||||
|
'#pragma'=40
|
||||||
|
'reserve'=41
|
||||||
|
'pc'=42
|
||||||
|
'target'=43
|
||||||
|
'link'=44
|
||||||
|
'code_seg'=45
|
||||||
|
'data_seg'=46
|
||||||
|
'encoding'=47
|
||||||
|
'const'=48
|
||||||
|
'extern'=49
|
||||||
|
'export'=50
|
||||||
|
'align'=51
|
||||||
|
'register'=52
|
||||||
|
'inline'=53
|
||||||
|
'volatile'=54
|
||||||
|
'interrupt'=55
|
||||||
|
'if'=56
|
||||||
|
'else'=57
|
||||||
|
'while'=58
|
||||||
|
'do'=59
|
||||||
|
'for'=60
|
||||||
|
'switch'=61
|
||||||
|
'return'=62
|
||||||
|
'break'=63
|
||||||
|
'continue'=64
|
||||||
|
'asm'=65
|
||||||
|
'default'=66
|
||||||
|
'case'=67
|
||||||
|
'struct'=68
|
||||||
|
'enum'=69
|
||||||
|
'sizeof'=70
|
||||||
|
'typeid'=71
|
||||||
|
'kickasm'=72
|
||||||
|
'resource'=73
|
||||||
|
'uses'=74
|
||||||
|
'clobbers'=75
|
||||||
|
'bytes'=76
|
||||||
|
'cycles'=77
|
||||||
|
'!'=78
|
||||||
|
'.byte'=79
|
||||||
|
'signed'=80
|
||||||
|
'unsigned'=81
|
||||||
|
'import'=83
|
@ -1,4 +1,4 @@
|
|||||||
// Generated from /Users/jespergravgaard/c64/kickc/src/main/java/dk/camelot64/kickc/parser/KickC.g4 by ANTLR 4.7
|
// Generated from /Users/jespergravgaard/c64/kickc/src/main/java/dk/camelot64/kickc/parser/KickCParser.g4 by ANTLR 4.7
|
||||||
package dk.camelot64.kickc.parser;
|
package dk.camelot64.kickc.parser;
|
||||||
|
|
||||||
|
|
||||||
@ -8,11 +8,11 @@ import org.antlr.v4.runtime.tree.ErrorNode;
|
|||||||
import org.antlr.v4.runtime.tree.TerminalNode;
|
import org.antlr.v4.runtime.tree.TerminalNode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class provides an empty implementation of {@link KickCListener},
|
* This class provides an empty implementation of {@link KickCParserListener},
|
||||||
* which can be extended to create a listener which only needs to handle a subset
|
* which can be extended to create a listener which only needs to handle a subset
|
||||||
* of the available methods.
|
* of the available methods.
|
||||||
*/
|
*/
|
||||||
public class KickCBaseListener implements KickCListener {
|
public class KickCParserBaseListener implements KickCParserListener {
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
@ -1,18 +1,18 @@
|
|||||||
// Generated from /Users/jespergravgaard/c64/kickc/src/main/java/dk/camelot64/kickc/parser/KickC.g4 by ANTLR 4.7
|
// Generated from /Users/jespergravgaard/c64/kickc/src/main/java/dk/camelot64/kickc/parser/KickCParser.g4 by ANTLR 4.7
|
||||||
package dk.camelot64.kickc.parser;
|
package dk.camelot64.kickc.parser;
|
||||||
|
|
||||||
|
|
||||||
import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor;
|
import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class provides an empty implementation of {@link KickCVisitor},
|
* This class provides an empty implementation of {@link KickCParserVisitor},
|
||||||
* which can be extended to create a visitor which only needs to handle a subset
|
* which can be extended to create a visitor which only needs to handle a subset
|
||||||
* of the available methods.
|
* of the available methods.
|
||||||
*
|
*
|
||||||
* @param <T> The return type of the visit operation. Use {@link Void} for
|
* @param <T> The return type of the visit operation. Use {@link Void} for
|
||||||
* operations with no return type.
|
* operations with no return type.
|
||||||
*/
|
*/
|
||||||
public class KickCBaseVisitor<T> extends AbstractParseTreeVisitor<T> implements KickCVisitor<T> {
|
public class KickCParserBaseVisitor<T> extends AbstractParseTreeVisitor<T> implements KickCParserVisitor<T> {
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
@ -1,4 +1,4 @@
|
|||||||
// Generated from /Users/jespergravgaard/c64/kickc/src/main/java/dk/camelot64/kickc/parser/KickC.g4 by ANTLR 4.7
|
// Generated from /Users/jespergravgaard/c64/kickc/src/main/java/dk/camelot64/kickc/parser/KickCParser.g4 by ANTLR 4.7
|
||||||
package dk.camelot64.kickc.parser;
|
package dk.camelot64.kickc.parser;
|
||||||
|
|
||||||
|
|
||||||
@ -8,7 +8,7 @@ import org.antlr.v4.runtime.tree.ParseTreeListener;
|
|||||||
* This interface defines a complete listener for a parse tree produced by
|
* This interface defines a complete listener for a parse tree produced by
|
||||||
* {@link KickCParser}.
|
* {@link KickCParser}.
|
||||||
*/
|
*/
|
||||||
public interface KickCListener extends ParseTreeListener {
|
public interface KickCParserListener extends ParseTreeListener {
|
||||||
/**
|
/**
|
||||||
* Enter a parse tree produced by {@link KickCParser#file}.
|
* Enter a parse tree produced by {@link KickCParser#file}.
|
||||||
* @param ctx the parse tree
|
* @param ctx the parse tree
|
@ -1,4 +1,4 @@
|
|||||||
// Generated from /Users/jespergravgaard/c64/kickc/src/main/java/dk/camelot64/kickc/parser/KickC.g4 by ANTLR 4.7
|
// Generated from /Users/jespergravgaard/c64/kickc/src/main/java/dk/camelot64/kickc/parser/KickCParser.g4 by ANTLR 4.7
|
||||||
package dk.camelot64.kickc.parser;
|
package dk.camelot64.kickc.parser;
|
||||||
|
|
||||||
|
|
||||||
@ -11,7 +11,7 @@ import org.antlr.v4.runtime.tree.ParseTreeVisitor;
|
|||||||
* @param <T> The return type of the visit operation. Use {@link Void} for
|
* @param <T> The return type of the visit operation. Use {@link Void} for
|
||||||
* operations with no return type.
|
* operations with no return type.
|
||||||
*/
|
*/
|
||||||
public interface KickCVisitor<T> extends ParseTreeVisitor<T> {
|
public interface KickCParserVisitor<T> extends ParseTreeVisitor<T> {
|
||||||
/**
|
/**
|
||||||
* Visit a parse tree produced by {@link KickCParser#file}.
|
* Visit a parse tree produced by {@link KickCParser#file}.
|
||||||
* @param ctx the parse tree
|
* @param ctx the parse tree
|
@ -1,6 +1,6 @@
|
|||||||
package dk.camelot64.kickc.passes;
|
package dk.camelot64.kickc.passes;
|
||||||
|
|
||||||
import dk.camelot64.kickc.parser.CParser;
|
import dk.camelot64.kickc.parser.*;
|
||||||
import dk.camelot64.kickc.NumberParser;
|
import dk.camelot64.kickc.NumberParser;
|
||||||
import dk.camelot64.kickc.SourceLoader;
|
import dk.camelot64.kickc.SourceLoader;
|
||||||
import dk.camelot64.kickc.asm.AsmClobber;
|
import dk.camelot64.kickc.asm.AsmClobber;
|
||||||
@ -10,8 +10,6 @@ import dk.camelot64.kickc.model.statements.*;
|
|||||||
import dk.camelot64.kickc.model.symbols.*;
|
import dk.camelot64.kickc.model.symbols.*;
|
||||||
import dk.camelot64.kickc.model.types.*;
|
import dk.camelot64.kickc.model.types.*;
|
||||||
import dk.camelot64.kickc.model.values.*;
|
import dk.camelot64.kickc.model.values.*;
|
||||||
import dk.camelot64.kickc.parser.KickCBaseVisitor;
|
|
||||||
import dk.camelot64.kickc.parser.KickCParser;
|
|
||||||
import org.antlr.v4.runtime.*;
|
import org.antlr.v4.runtime.*;
|
||||||
import org.antlr.v4.runtime.misc.Interval;
|
import org.antlr.v4.runtime.misc.Interval;
|
||||||
import org.antlr.v4.runtime.tree.ParseTree;
|
import org.antlr.v4.runtime.tree.ParseTree;
|
||||||
@ -26,7 +24,7 @@ import java.util.regex.Pattern;
|
|||||||
/**
|
/**
|
||||||
* Generates program SSA form by visiting the ANTLR4 parse tree
|
* Generates program SSA form by visiting the ANTLR4 parse tree
|
||||||
*/
|
*/
|
||||||
public class Pass0GenerateStatementSequence extends KickCBaseVisitor<Object> {
|
public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Object> {
|
||||||
|
|
||||||
/** The C parser keeping track of C-files and lexers */
|
/** The C parser keeping track of C-files and lexers */
|
||||||
private CParser cParser;
|
private CParser cParser;
|
||||||
@ -79,7 +77,7 @@ public class Pass0GenerateStatementSequence extends KickCBaseVisitor<Object> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visitImportDecl(KickCParser.ImportDeclContext ctx) {
|
public Object visitImportDecl(KickCParser.ImportDeclContext ctx) {
|
||||||
String importName = ctx.IMPORTFILE().getText();
|
String importName = ctx.STRING().getText();
|
||||||
String importFileName = importName.substring(1, importName.length() - 1);
|
String importFileName = importName.substring(1, importName.length() - 1);
|
||||||
if(program.getLog().isVerboseParse()) {
|
if(program.getLog().isVerboseParse()) {
|
||||||
program.getLog().append("Importing " + importFileName);
|
program.getLog().append("Importing " + importFileName);
|
||||||
@ -244,7 +242,7 @@ public class Pass0GenerateStatementSequence extends KickCBaseVisitor<Object> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visitDeclKasm(KickCParser.DeclKasmContext ctx) {
|
public Object visitDeclKasm(KickCParser.DeclKasmContext ctx) {
|
||||||
String kasm = ctx.KICKASM().getText();
|
String kasm = ctx.KICKASM_BODY().getText();
|
||||||
Pattern p = Pattern.compile("\\{\\{[\\s]*(.*)[\\s]*\\}\\}", Pattern.DOTALL);
|
Pattern p = Pattern.compile("\\{\\{[\\s]*(.*)[\\s]*\\}\\}", Pattern.DOTALL);
|
||||||
Matcher m = p.matcher(kasm);
|
Matcher m = p.matcher(kasm);
|
||||||
if(m.find()) {
|
if(m.find()) {
|
||||||
@ -1251,7 +1249,7 @@ public class Pass0GenerateStatementSequence extends KickCBaseVisitor<Object> {
|
|||||||
*/
|
*/
|
||||||
private Map<String, SymbolRef> getAsmReferencedSymbolVariables(KickCParser.StmtAsmContext ctx, List<String> definedLabels) {
|
private Map<String, SymbolRef> getAsmReferencedSymbolVariables(KickCParser.StmtAsmContext ctx, List<String> definedLabels) {
|
||||||
Map<String, SymbolRef> referenced = new LinkedHashMap<>();
|
Map<String, SymbolRef> referenced = new LinkedHashMap<>();
|
||||||
KickCBaseVisitor<Void> findReferenced = new KickCBaseVisitor<Void>() {
|
KickCParserBaseVisitor<Void> findReferenced = new KickCParserBaseVisitor<Void>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Void visitAsmExprBinary(KickCParser.AsmExprBinaryContext ctx) {
|
public Void visitAsmExprBinary(KickCParser.AsmExprBinaryContext ctx) {
|
||||||
@ -1293,7 +1291,7 @@ public class Pass0GenerateStatementSequence extends KickCBaseVisitor<Object> {
|
|||||||
*/
|
*/
|
||||||
private List<String> getAsmDefinedLabels(KickCParser.StmtAsmContext ctx) {
|
private List<String> getAsmDefinedLabels(KickCParser.StmtAsmContext ctx) {
|
||||||
List<String> definedLabels = new ArrayList<>();
|
List<String> definedLabels = new ArrayList<>();
|
||||||
KickCBaseVisitor<Void> findDefinedLabels = new KickCBaseVisitor<Void>() {
|
KickCParserBaseVisitor<Void> findDefinedLabels = new KickCParserBaseVisitor<Void>() {
|
||||||
@Override
|
@Override
|
||||||
public Void visitAsmLabelName(KickCParser.AsmLabelNameContext ctx) {
|
public Void visitAsmLabelName(KickCParser.AsmLabelNameContext ctx) {
|
||||||
String label = ctx.NAME().getText();
|
String label = ctx.NAME().getText();
|
||||||
@ -2050,7 +2048,7 @@ public class Pass0GenerateStatementSequence extends KickCBaseVisitor<Object> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static class PrePostModifierHandler extends KickCBaseVisitor<Void> {
|
private static class PrePostModifierHandler extends KickCParserBaseVisitor<Void> {
|
||||||
|
|
||||||
private List<PrePostModifier> postMods;
|
private List<PrePostModifier> postMods;
|
||||||
private List<PrePostModifier> preMods;
|
private List<PrePostModifier> preMods;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user