1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-06-03 07:29:37 +00:00

SSA form generation for expressions started

This commit is contained in:
jespergravgaard 2017-05-05 09:55:15 +02:00
parent 04d4f32ad9
commit 7a24cc0b62
28 changed files with 1279 additions and 160 deletions

View File

@ -44,7 +44,4 @@
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" project-jdk-name="1.7" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
<component name="SvnConfiguration" myUseAcceleration="nothing">
<configuration>$USER_HOME$/.subversion</configuration>
</component>
</project>

124
.idea/uiDesigner.xml Normal file
View File

@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>

View File

@ -1,21 +1,33 @@
// Define a grammar called Hello
// KickC grammar
grammar KickC;
expr :
NUMBER |
NAME |
'(' expr ')' |
('+' | '-') expr |
expr ( '*' | '/' ) expr |
expr ( '+' | '-' ) expr ;
expr
: '(' expr ')' #exprPar
| ('+' | '-' | 'not' | '!') expr #exprUnary
| expr ('*' | '/' ) expr #exprBinary
| expr ( '+' | '-') expr #exprBinary
| expr ( '=' | '==' | '!=' | '<>' | '<' | '<=' | '=<' | '>=' | '=>' | '>' ) expr #exprBinary
| expr ( 'and' | '&&' ) expr #exprBinary
| expr ( 'or' | '||' ) expr #exprBinary
| NAME #exprId
| NUMBER #exprNumber
| STRING #exprString
| BOOLEAN #exprBool
;
STRING : '"' ('\\"' | ~'"')* '"';
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 ;
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* ;
fragment NAME_START : [a-zA-Z_];
fragment NAME_CHAR : [a-zA-Z0-9_];
NUMBER : FLOAT | DECINTEGER | HEXINTEGER | BININTEGER ;
FLOAT : (DECDIGIT)* '.' DECDIGIT+;
DECINTEGER : DECDIGIT+ ;
fragment DECDIGIT : [0-9];
HEXINTEGER : '0' [xX] HEXDIGIT+ | '$' HEXDIGIT+ ;
fragment HEXDIGIT : [0-9a-fA-F];
BININTEGER : '0' [bB] BINDIGIT+ | '%' BINDIGIT+ ;
fragment BINDIGIT : [0-1];
WS : [ \t\r\n]+ -> skip ; // skip spaces, tabs, newlines

View File

@ -4,15 +4,54 @@ T__2=3
T__3=4
T__4=5
T__5=6
NAME=7
FLOAT=8
HEXINTEGER=9
DECINTEGER=10
BININTEGER=11
WS=12
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
STRING=23
BOOLEAN=24
NUMBER=25
NUMFLOAT=26
BINFLOAT=27
DECFLOAT=28
HEXFLOAT=29
NUMINT=30
BININTEGER=31
DECINTEGER=32
HEXINTEGER=33
NAME=34
WS=35
'('=1
')'=2
'+'=3
'-'=4
'*'=5
'/'=6
'not'=5
'!'=6
'*'=7
'/'=8
'='=9
'=='=10
'!='=11
'<>'=12
'<'=13
'<='=14
'=<'=15
'>='=16
'=>'=17
'>'=18
'and'=19
'&&'=20
'or'=21
'||'=22

View File

@ -16,13 +16,85 @@ public class KickCBaseListener implements KickCListener {
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterExpr(KickCParser.ExprContext ctx) { }
@Override public void enterExprBinary(KickCParser.ExprBinaryContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitExpr(KickCParser.ExprContext ctx) { }
@Override public void exitExprBinary(KickCParser.ExprBinaryContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterExprPar(KickCParser.ExprParContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitExprPar(KickCParser.ExprParContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterExprString(KickCParser.ExprStringContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitExprString(KickCParser.ExprStringContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterExprBool(KickCParser.ExprBoolContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitExprBool(KickCParser.ExprBoolContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterExprId(KickCParser.ExprIdContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitExprId(KickCParser.ExprIdContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterExprUnary(KickCParser.ExprUnaryContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitExprUnary(KickCParser.ExprUnaryContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterExprNumber(KickCParser.ExprNumberContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitExprNumber(KickCParser.ExprNumberContext ctx) { }
/**
* {@inheritDoc}

View File

@ -0,0 +1,63 @@
// Generated from /Users/jespergravgaard/c64/src/kickc/src/dk/camelot64/kickc/parser/KickC.g4 by ANTLR 4.7
package dk.camelot64.kickc.parser;
import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor;
/**
* This class provides an empty implementation of {@link KickCVisitor},
* which can be extended to create a visitor which only needs to handle a subset
* of the available methods.
*
* @param <T> The return type of the visit operation. Use {@link Void} for
* operations with no return type.
*/
public class KickCBaseVisitor<T> extends AbstractParseTreeVisitor<T> implements KickCVisitor<T> {
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitExprBinary(KickCParser.ExprBinaryContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitExprPar(KickCParser.ExprParContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitExprString(KickCParser.ExprStringContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitExprBool(KickCParser.ExprBoolContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitExprId(KickCParser.ExprIdContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitExprUnary(KickCParser.ExprUnaryContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitExprNumber(KickCParser.ExprNumberContext ctx) { return visitChildren(ctx); }
}

View File

@ -17,8 +17,11 @@ public class KickCLexer extends Lexer {
protected static final PredictionContextCache _sharedContextCache =
new PredictionContextCache();
public static final int
T__0=1, T__1=2, T__2=3, T__3=4, T__4=5, T__5=6, NAME=7, FLOAT=8, HEXINTEGER=9,
DECINTEGER=10, BININTEGER=11, WS=12;
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, STRING=23, BOOLEAN=24,
NUMBER=25, NUMFLOAT=26, BINFLOAT=27, DECFLOAT=28, HEXFLOAT=29, NUMINT=30,
BININTEGER=31, DECINTEGER=32, HEXINTEGER=33, NAME=34, WS=35;
public static String[] channelNames = {
"DEFAULT_TOKEN_CHANNEL", "HIDDEN"
};
@ -28,17 +31,24 @@ public class KickCLexer extends Lexer {
};
public static final String[] ruleNames = {
"T__0", "T__1", "T__2", "T__3", "T__4", "T__5", "NAME", "NAME_START",
"NAME_CHAR", "FLOAT", "HEXINTEGER", "HEXDIGIT", "DECINTEGER", "DECDIGIT",
"BININTEGER", "BINDIGIT", "WS"
"T__0", "T__1", "T__2", "T__3", "T__4", "T__5", "T__6", "T__7", "T__8",
"T__9", "T__10", "T__11", "T__12", "T__13", "T__14", "T__15", "T__16",
"T__17", "T__18", "T__19", "T__20", "T__21", "STRING", "BOOLEAN", "NUMBER",
"NUMFLOAT", "BINFLOAT", "DECFLOAT", "HEXFLOAT", "NUMINT", "BININTEGER",
"DECINTEGER", "HEXINTEGER", "BINDIGIT", "DECDIGIT", "HEXDIGIT", "NAME",
"NAME_START", "NAME_CHAR", "WS"
};
private static final String[] _LITERAL_NAMES = {
null, "'('", "')'", "'+'", "'-'", "'*'", "'/'"
null, "'('", "')'", "'+'", "'-'", "'not'", "'!'", "'*'", "'/'", "'='",
"'=='", "'!='", "'<>'", "'<'", "'<='", "'=<'", "'>='", "'=>'", "'>'",
"'and'", "'&&'", "'or'", "'||'"
};
private static final String[] _SYMBOLIC_NAMES = {
null, null, null, null, null, null, null, "NAME", "FLOAT", "HEXINTEGER",
"DECINTEGER", "BININTEGER", "WS"
null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null, null, "STRING",
"BOOLEAN", "NUMBER", "NUMFLOAT", "BINFLOAT", "DECFLOAT", "HEXFLOAT", "NUMINT",
"BININTEGER", "DECINTEGER", "HEXINTEGER", "NAME", "WS"
};
public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES);
@ -98,38 +108,103 @@ public class KickCLexer extends Lexer {
public ATN getATN() { return _ATN; }
public static final String _serializedATN =
"\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\2\16x\b\1\4\2\t\2\4"+
"\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4\b\t\b\4\t\t\t\4\n\t\n\4\13\t"+
"\13\4\f\t\f\4\r\t\r\4\16\t\16\4\17\t\17\4\20\t\20\4\21\t\21\4\22\t\22"+
"\3\2\3\2\3\3\3\3\3\4\3\4\3\5\3\5\3\6\3\6\3\7\3\7\3\b\3\b\7\b\64\n\b\f"+
"\b\16\b\67\13\b\3\t\3\t\3\n\3\n\3\13\7\13>\n\13\f\13\16\13A\13\13\3\13"+
"\3\13\6\13E\n\13\r\13\16\13F\3\f\3\f\3\f\6\fL\n\f\r\f\16\fM\3\f\3\f\6"+
"\fR\n\f\r\f\16\fS\5\fV\n\f\3\r\3\r\3\16\6\16[\n\16\r\16\16\16\\\3\17\3"+
"\17\3\20\3\20\3\20\6\20d\n\20\r\20\16\20e\3\20\3\20\6\20j\n\20\r\20\16"+
"\20k\5\20n\n\20\3\21\3\21\3\22\6\22s\n\22\r\22\16\22t\3\22\3\22\2\2\23"+
"\3\3\5\4\7\5\t\6\13\7\r\b\17\t\21\2\23\2\25\n\27\13\31\2\33\f\35\2\37"+
"\r!\2#\16\3\2\n\5\2C\\aac|\6\2\62;C\\aac|\4\2ZZzz\5\2\62;CHch\3\2\62;"+
"\4\2DDdd\3\2\62\63\5\2\13\f\17\17\"\"\2}\2\3\3\2\2\2\2\5\3\2\2\2\2\7\3"+
"\2\2\2\2\t\3\2\2\2\2\13\3\2\2\2\2\r\3\2\2\2\2\17\3\2\2\2\2\25\3\2\2\2"+
"\2\27\3\2\2\2\2\33\3\2\2\2\2\37\3\2\2\2\2#\3\2\2\2\3%\3\2\2\2\5\'\3\2"+
"\2\2\7)\3\2\2\2\t+\3\2\2\2\13-\3\2\2\2\r/\3\2\2\2\17\61\3\2\2\2\218\3"+
"\2\2\2\23:\3\2\2\2\25?\3\2\2\2\27U\3\2\2\2\31W\3\2\2\2\33Z\3\2\2\2\35"+
"^\3\2\2\2\37m\3\2\2\2!o\3\2\2\2#r\3\2\2\2%&\7*\2\2&\4\3\2\2\2\'(\7+\2"+
"\2(\6\3\2\2\2)*\7-\2\2*\b\3\2\2\2+,\7/\2\2,\n\3\2\2\2-.\7,\2\2.\f\3\2"+
"\2\2/\60\7\61\2\2\60\16\3\2\2\2\61\65\5\21\t\2\62\64\5\23\n\2\63\62\3"+
"\2\2\2\64\67\3\2\2\2\65\63\3\2\2\2\65\66\3\2\2\2\66\20\3\2\2\2\67\65\3"+
"\2\2\289\t\2\2\29\22\3\2\2\2:;\t\3\2\2;\24\3\2\2\2<>\5\35\17\2=<\3\2\2"+
"\2>A\3\2\2\2?=\3\2\2\2?@\3\2\2\2@B\3\2\2\2A?\3\2\2\2BD\7\60\2\2CE\5\35"+
"\17\2DC\3\2\2\2EF\3\2\2\2FD\3\2\2\2FG\3\2\2\2G\26\3\2\2\2HI\7\62\2\2I"+
"K\t\4\2\2JL\5\31\r\2KJ\3\2\2\2LM\3\2\2\2MK\3\2\2\2MN\3\2\2\2NV\3\2\2\2"+
"OQ\7&\2\2PR\5\31\r\2QP\3\2\2\2RS\3\2\2\2SQ\3\2\2\2ST\3\2\2\2TV\3\2\2\2"+
"UH\3\2\2\2UO\3\2\2\2V\30\3\2\2\2WX\t\5\2\2X\32\3\2\2\2Y[\5\35\17\2ZY\3"+
"\2\2\2[\\\3\2\2\2\\Z\3\2\2\2\\]\3\2\2\2]\34\3\2\2\2^_\t\6\2\2_\36\3\2"+
"\2\2`a\7\62\2\2ac\t\7\2\2bd\5!\21\2cb\3\2\2\2de\3\2\2\2ec\3\2\2\2ef\3"+
"\2\2\2fn\3\2\2\2gi\7\'\2\2hj\5!\21\2ih\3\2\2\2jk\3\2\2\2ki\3\2\2\2kl\3"+
"\2\2\2ln\3\2\2\2m`\3\2\2\2mg\3\2\2\2n \3\2\2\2op\t\b\2\2p\"\3\2\2\2qs"+
"\t\t\2\2rq\3\2\2\2st\3\2\2\2tr\3\2\2\2tu\3\2\2\2uv\3\2\2\2vw\b\22\2\2"+
"w$\3\2\2\2\16\2\65?FMSU\\ekmt\3\b\2\2";
"\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\2%\u011b\b\1\4\2\t"+
"\2\4\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4\b\t\b\4\t\t\t\4\n\t\n\4\13"+
"\t\13\4\f\t\f\4\r\t\r\4\16\t\16\4\17\t\17\4\20\t\20\4\21\t\21\4\22\t\22"+
"\4\23\t\23\4\24\t\24\4\25\t\25\4\26\t\26\4\27\t\27\4\30\t\30\4\31\t\31"+
"\4\32\t\32\4\33\t\33\4\34\t\34\4\35\t\35\4\36\t\36\4\37\t\37\4 \t \4!"+
"\t!\4\"\t\"\4#\t#\4$\t$\4%\t%\4&\t&\4\'\t\'\4(\t(\4)\t)\3\2\3\2\3\3\3"+
"\3\3\4\3\4\3\5\3\5\3\6\3\6\3\6\3\6\3\7\3\7\3\b\3\b\3\t\3\t\3\n\3\n\3\13"+
"\3\13\3\13\3\f\3\f\3\f\3\r\3\r\3\r\3\16\3\16\3\17\3\17\3\17\3\20\3\20"+
"\3\20\3\21\3\21\3\21\3\22\3\22\3\22\3\23\3\23\3\24\3\24\3\24\3\24\3\25"+
"\3\25\3\25\3\26\3\26\3\26\3\27\3\27\3\27\3\30\3\30\3\30\3\30\7\30\u0092"+
"\n\30\f\30\16\30\u0095\13\30\3\30\3\30\3\31\3\31\3\31\3\31\3\31\3\31\3"+
"\31\3\31\3\31\5\31\u00a2\n\31\3\32\3\32\5\32\u00a6\n\32\3\33\3\33\3\33"+
"\5\33\u00ab\n\33\3\34\3\34\3\34\3\34\3\34\5\34\u00b2\n\34\3\34\7\34\u00b5"+
"\n\34\f\34\16\34\u00b8\13\34\3\34\3\34\6\34\u00bc\n\34\r\34\16\34\u00bd"+
"\3\35\7\35\u00c1\n\35\f\35\16\35\u00c4\13\35\3\35\3\35\6\35\u00c8\n\35"+
"\r\35\16\35\u00c9\3\36\3\36\3\36\3\36\3\36\5\36\u00d1\n\36\3\36\7\36\u00d4"+
"\n\36\f\36\16\36\u00d7\13\36\3\36\3\36\6\36\u00db\n\36\r\36\16\36\u00dc"+
"\3\37\3\37\3\37\5\37\u00e2\n\37\3 \3 \3 \6 \u00e7\n \r \16 \u00e8\3 \3"+
" \6 \u00ed\n \r \16 \u00ee\5 \u00f1\n \3!\6!\u00f4\n!\r!\16!\u00f5\3\""+
"\3\"\3\"\3\"\3\"\5\"\u00fd\n\"\3\"\6\"\u0100\n\"\r\"\16\"\u0101\3#\3#"+
"\3$\3$\3%\3%\3&\3&\7&\u010c\n&\f&\16&\u010f\13&\3\'\3\'\3(\3(\3)\6)\u0116"+
"\n)\r)\16)\u0117\3)\3)\2\2*\3\3\5\4\7\5\t\6\13\7\r\b\17\t\21\n\23\13\25"+
"\f\27\r\31\16\33\17\35\20\37\21!\22#\23%\24\'\25)\26+\27-\30/\31\61\32"+
"\63\33\65\34\67\359\36;\37= ?!A\"C#E\2G\2I\2K$M\2O\2Q%\3\2\n\3\2$$\4\2"+
"DDdd\3\2\62\63\3\2\62;\5\2\62;CHch\5\2C\\aac|\6\2\62;C\\aac|\5\2\13\f"+
"\17\17\"\"\2\u0130\2\3\3\2\2\2\2\5\3\2\2\2\2\7\3\2\2\2\2\t\3\2\2\2\2\13"+
"\3\2\2\2\2\r\3\2\2\2\2\17\3\2\2\2\2\21\3\2\2\2\2\23\3\2\2\2\2\25\3\2\2"+
"\2\2\27\3\2\2\2\2\31\3\2\2\2\2\33\3\2\2\2\2\35\3\2\2\2\2\37\3\2\2\2\2"+
"!\3\2\2\2\2#\3\2\2\2\2%\3\2\2\2\2\'\3\2\2\2\2)\3\2\2\2\2+\3\2\2\2\2-\3"+
"\2\2\2\2/\3\2\2\2\2\61\3\2\2\2\2\63\3\2\2\2\2\65\3\2\2\2\2\67\3\2\2\2"+
"\29\3\2\2\2\2;\3\2\2\2\2=\3\2\2\2\2?\3\2\2\2\2A\3\2\2\2\2C\3\2\2\2\2K"+
"\3\2\2\2\2Q\3\2\2\2\3S\3\2\2\2\5U\3\2\2\2\7W\3\2\2\2\tY\3\2\2\2\13[\3"+
"\2\2\2\r_\3\2\2\2\17a\3\2\2\2\21c\3\2\2\2\23e\3\2\2\2\25g\3\2\2\2\27j"+
"\3\2\2\2\31m\3\2\2\2\33p\3\2\2\2\35r\3\2\2\2\37u\3\2\2\2!x\3\2\2\2#{\3"+
"\2\2\2%~\3\2\2\2\'\u0080\3\2\2\2)\u0084\3\2\2\2+\u0087\3\2\2\2-\u008a"+
"\3\2\2\2/\u008d\3\2\2\2\61\u00a1\3\2\2\2\63\u00a5\3\2\2\2\65\u00aa\3\2"+
"\2\2\67\u00b1\3\2\2\29\u00c2\3\2\2\2;\u00d0\3\2\2\2=\u00e1\3\2\2\2?\u00f0"+
"\3\2\2\2A\u00f3\3\2\2\2C\u00fc\3\2\2\2E\u0103\3\2\2\2G\u0105\3\2\2\2I"+
"\u0107\3\2\2\2K\u0109\3\2\2\2M\u0110\3\2\2\2O\u0112\3\2\2\2Q\u0115\3\2"+
"\2\2ST\7*\2\2T\4\3\2\2\2UV\7+\2\2V\6\3\2\2\2WX\7-\2\2X\b\3\2\2\2YZ\7/"+
"\2\2Z\n\3\2\2\2[\\\7p\2\2\\]\7q\2\2]^\7v\2\2^\f\3\2\2\2_`\7#\2\2`\16\3"+
"\2\2\2ab\7,\2\2b\20\3\2\2\2cd\7\61\2\2d\22\3\2\2\2ef\7?\2\2f\24\3\2\2"+
"\2gh\7?\2\2hi\7?\2\2i\26\3\2\2\2jk\7#\2\2kl\7?\2\2l\30\3\2\2\2mn\7>\2"+
"\2no\7@\2\2o\32\3\2\2\2pq\7>\2\2q\34\3\2\2\2rs\7>\2\2st\7?\2\2t\36\3\2"+
"\2\2uv\7?\2\2vw\7>\2\2w \3\2\2\2xy\7@\2\2yz\7?\2\2z\"\3\2\2\2{|\7?\2\2"+
"|}\7@\2\2}$\3\2\2\2~\177\7@\2\2\177&\3\2\2\2\u0080\u0081\7c\2\2\u0081"+
"\u0082\7p\2\2\u0082\u0083\7f\2\2\u0083(\3\2\2\2\u0084\u0085\7(\2\2\u0085"+
"\u0086\7(\2\2\u0086*\3\2\2\2\u0087\u0088\7q\2\2\u0088\u0089\7t\2\2\u0089"+
",\3\2\2\2\u008a\u008b\7~\2\2\u008b\u008c\7~\2\2\u008c.\3\2\2\2\u008d\u0093"+
"\7$\2\2\u008e\u008f\7^\2\2\u008f\u0092\7$\2\2\u0090\u0092\n\2\2\2\u0091"+
"\u008e\3\2\2\2\u0091\u0090\3\2\2\2\u0092\u0095\3\2\2\2\u0093\u0091\3\2"+
"\2\2\u0093\u0094\3\2\2\2\u0094\u0096\3\2\2\2\u0095\u0093\3\2\2\2\u0096"+
"\u0097\7$\2\2\u0097\60\3\2\2\2\u0098\u0099\7v\2\2\u0099\u009a\7t\2\2\u009a"+
"\u009b\7w\2\2\u009b\u00a2\7g\2\2\u009c\u009d\7h\2\2\u009d\u009e\7c\2\2"+
"\u009e\u009f\7n\2\2\u009f\u00a0\7u\2\2\u00a0\u00a2\7g\2\2\u00a1\u0098"+
"\3\2\2\2\u00a1\u009c\3\2\2\2\u00a2\62\3\2\2\2\u00a3\u00a6\5\65\33\2\u00a4"+
"\u00a6\5=\37\2\u00a5\u00a3\3\2\2\2\u00a5\u00a4\3\2\2\2\u00a6\64\3\2\2"+
"\2\u00a7\u00ab\5\67\34\2\u00a8\u00ab\59\35\2\u00a9\u00ab\5;\36\2\u00aa"+
"\u00a7\3\2\2\2\u00aa\u00a8\3\2\2\2\u00aa\u00a9\3\2\2\2\u00ab\66\3\2\2"+
"\2\u00ac\u00b2\7\'\2\2\u00ad\u00ae\7\62\2\2\u00ae\u00b2\7d\2\2\u00af\u00b0"+
"\7\62\2\2\u00b0\u00b2\7D\2\2\u00b1\u00ac\3\2\2\2\u00b1\u00ad\3\2\2\2\u00b1"+
"\u00af\3\2\2\2\u00b2\u00b6\3\2\2\2\u00b3\u00b5\5E#\2\u00b4\u00b3\3\2\2"+
"\2\u00b5\u00b8\3\2\2\2\u00b6\u00b4\3\2\2\2\u00b6\u00b7\3\2\2\2\u00b7\u00b9"+
"\3\2\2\2\u00b8\u00b6\3\2\2\2\u00b9\u00bb\7\60\2\2\u00ba\u00bc\5E#\2\u00bb"+
"\u00ba\3\2\2\2\u00bc\u00bd\3\2\2\2\u00bd\u00bb\3\2\2\2\u00bd\u00be\3\2"+
"\2\2\u00be8\3\2\2\2\u00bf\u00c1\5G$\2\u00c0\u00bf\3\2\2\2\u00c1\u00c4"+
"\3\2\2\2\u00c2\u00c0\3\2\2\2\u00c2\u00c3\3\2\2\2\u00c3\u00c5\3\2\2\2\u00c4"+
"\u00c2\3\2\2\2\u00c5\u00c7\7\60\2\2\u00c6\u00c8\5G$\2\u00c7\u00c6\3\2"+
"\2\2\u00c8\u00c9\3\2\2\2\u00c9\u00c7\3\2\2\2\u00c9\u00ca\3\2\2\2\u00ca"+
":\3\2\2\2\u00cb\u00d1\7&\2\2\u00cc\u00cd\7\62\2\2\u00cd\u00d1\7z\2\2\u00ce"+
"\u00cf\7\62\2\2\u00cf\u00d1\7Z\2\2\u00d0\u00cb\3\2\2\2\u00d0\u00cc\3\2"+
"\2\2\u00d0\u00ce\3\2\2\2\u00d1\u00d5\3\2\2\2\u00d2\u00d4\5I%\2\u00d3\u00d2"+
"\3\2\2\2\u00d4\u00d7\3\2\2\2\u00d5\u00d3\3\2\2\2\u00d5\u00d6\3\2\2\2\u00d6"+
"\u00d8\3\2\2\2\u00d7\u00d5\3\2\2\2\u00d8\u00da\7\60\2\2\u00d9\u00db\5"+
"I%\2\u00da\u00d9\3\2\2\2\u00db\u00dc\3\2\2\2\u00dc\u00da\3\2\2\2\u00dc"+
"\u00dd\3\2\2\2\u00dd<\3\2\2\2\u00de\u00e2\5A!\2\u00df\u00e2\5C\"\2\u00e0"+
"\u00e2\5? \2\u00e1\u00de\3\2\2\2\u00e1\u00df\3\2\2\2\u00e1\u00e0\3\2\2"+
"\2\u00e2>\3\2\2\2\u00e3\u00e4\7\62\2\2\u00e4\u00e6\t\3\2\2\u00e5\u00e7"+
"\5E#\2\u00e6\u00e5\3\2\2\2\u00e7\u00e8\3\2\2\2\u00e8\u00e6\3\2\2\2\u00e8"+
"\u00e9\3\2\2\2\u00e9\u00f1\3\2\2\2\u00ea\u00ec\7\'\2\2\u00eb\u00ed\5E"+
"#\2\u00ec\u00eb\3\2\2\2\u00ed\u00ee\3\2\2\2\u00ee\u00ec\3\2\2\2\u00ee"+
"\u00ef\3\2\2\2\u00ef\u00f1\3\2\2\2\u00f0\u00e3\3\2\2\2\u00f0\u00ea\3\2"+
"\2\2\u00f1@\3\2\2\2\u00f2\u00f4\5G$\2\u00f3\u00f2\3\2\2\2\u00f4\u00f5"+
"\3\2\2\2\u00f5\u00f3\3\2\2\2\u00f5\u00f6\3\2\2\2\u00f6B\3\2\2\2\u00f7"+
"\u00fd\7&\2\2\u00f8\u00f9\7\62\2\2\u00f9\u00fd\7z\2\2\u00fa\u00fb\7\62"+
"\2\2\u00fb\u00fd\7Z\2\2\u00fc\u00f7\3\2\2\2\u00fc\u00f8\3\2\2\2\u00fc"+
"\u00fa\3\2\2\2\u00fd\u00ff\3\2\2\2\u00fe\u0100\5I%\2\u00ff\u00fe\3\2\2"+
"\2\u0100\u0101\3\2\2\2\u0101\u00ff\3\2\2\2\u0101\u0102\3\2\2\2\u0102D"+
"\3\2\2\2\u0103\u0104\t\4\2\2\u0104F\3\2\2\2\u0105\u0106\t\5\2\2\u0106"+
"H\3\2\2\2\u0107\u0108\t\6\2\2\u0108J\3\2\2\2\u0109\u010d\5M\'\2\u010a"+
"\u010c\5O(\2\u010b\u010a\3\2\2\2\u010c\u010f\3\2\2\2\u010d\u010b\3\2\2"+
"\2\u010d\u010e\3\2\2\2\u010eL\3\2\2\2\u010f\u010d\3\2\2\2\u0110\u0111"+
"\t\7\2\2\u0111N\3\2\2\2\u0112\u0113\t\b\2\2\u0113P\3\2\2\2\u0114\u0116"+
"\t\t\2\2\u0115\u0114\3\2\2\2\u0116\u0117\3\2\2\2\u0117\u0115\3\2\2\2\u0117"+
"\u0118\3\2\2\2\u0118\u0119\3\2\2\2\u0119\u011a\b)\2\2\u011aR\3\2\2\2\31"+
"\2\u0091\u0093\u00a1\u00a5\u00aa\u00b1\u00b6\u00bd\u00c2\u00c9\u00d0\u00d5"+
"\u00dc\u00e1\u00e8\u00ee\u00f0\u00f5\u00fc\u0101\u010d\u0117\3\b\2\2";
public static final ATN _ATN =
new ATNDeserializer().deserialize(_serializedATN.toCharArray());
static {

View File

@ -4,15 +4,54 @@ T__2=3
T__3=4
T__4=5
T__5=6
NAME=7
FLOAT=8
HEXINTEGER=9
DECINTEGER=10
BININTEGER=11
WS=12
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
STRING=23
BOOLEAN=24
NUMBER=25
NUMFLOAT=26
BINFLOAT=27
DECFLOAT=28
HEXFLOAT=29
NUMINT=30
BININTEGER=31
DECINTEGER=32
HEXINTEGER=33
NAME=34
WS=35
'('=1
')'=2
'+'=3
'-'=4
'*'=5
'/'=6
'not'=5
'!'=6
'*'=7
'/'=8
'='=9
'=='=10
'!='=11
'<>'=12
'<'=13
'<='=14
'=<'=15
'>='=16
'=>'=17
'>'=18
'and'=19
'&&'=20
'or'=21
'||'=22

View File

@ -8,13 +8,87 @@ import org.antlr.v4.runtime.tree.ParseTreeListener;
*/
public interface KickCListener extends ParseTreeListener {
/**
* Enter a parse tree produced by {@link KickCParser#expr}.
* Enter a parse tree produced by the {@code exprBinary}
* labeled alternative in {@link KickCParser#expr}.
* @param ctx the parse tree
*/
void enterExpr(KickCParser.ExprContext ctx);
void enterExprBinary(KickCParser.ExprBinaryContext ctx);
/**
* Exit a parse tree produced by {@link KickCParser#expr}.
* Exit a parse tree produced by the {@code exprBinary}
* labeled alternative in {@link KickCParser#expr}.
* @param ctx the parse tree
*/
void exitExpr(KickCParser.ExprContext ctx);
void exitExprBinary(KickCParser.ExprBinaryContext ctx);
/**
* Enter a parse tree produced by the {@code exprPar}
* labeled alternative in {@link KickCParser#expr}.
* @param ctx the parse tree
*/
void enterExprPar(KickCParser.ExprParContext ctx);
/**
* Exit a parse tree produced by the {@code exprPar}
* labeled alternative in {@link KickCParser#expr}.
* @param ctx the parse tree
*/
void exitExprPar(KickCParser.ExprParContext ctx);
/**
* Enter a parse tree produced by the {@code exprString}
* labeled alternative in {@link KickCParser#expr}.
* @param ctx the parse tree
*/
void enterExprString(KickCParser.ExprStringContext ctx);
/**
* Exit a parse tree produced by the {@code exprString}
* labeled alternative in {@link KickCParser#expr}.
* @param ctx the parse tree
*/
void exitExprString(KickCParser.ExprStringContext ctx);
/**
* Enter a parse tree produced by the {@code exprBool}
* labeled alternative in {@link KickCParser#expr}.
* @param ctx the parse tree
*/
void enterExprBool(KickCParser.ExprBoolContext ctx);
/**
* Exit a parse tree produced by the {@code exprBool}
* labeled alternative in {@link KickCParser#expr}.
* @param ctx the parse tree
*/
void exitExprBool(KickCParser.ExprBoolContext ctx);
/**
* Enter a parse tree produced by the {@code exprId}
* labeled alternative in {@link KickCParser#expr}.
* @param ctx the parse tree
*/
void enterExprId(KickCParser.ExprIdContext ctx);
/**
* Exit a parse tree produced by the {@code exprId}
* labeled alternative in {@link KickCParser#expr}.
* @param ctx the parse tree
*/
void exitExprId(KickCParser.ExprIdContext ctx);
/**
* Enter a parse tree produced by the {@code exprUnary}
* labeled alternative in {@link KickCParser#expr}.
* @param ctx the parse tree
*/
void enterExprUnary(KickCParser.ExprUnaryContext ctx);
/**
* Exit a parse tree produced by the {@code exprUnary}
* labeled alternative in {@link KickCParser#expr}.
* @param ctx the parse tree
*/
void exitExprUnary(KickCParser.ExprUnaryContext ctx);
/**
* Enter a parse tree produced by the {@code exprNumber}
* labeled alternative in {@link KickCParser#expr}.
* @param ctx the parse tree
*/
void enterExprNumber(KickCParser.ExprNumberContext ctx);
/**
* Exit a parse tree produced by the {@code exprNumber}
* labeled alternative in {@link KickCParser#expr}.
* @param ctx the parse tree
*/
void exitExprNumber(KickCParser.ExprNumberContext ctx);
}

View File

@ -17,8 +17,11 @@ public class KickCParser extends Parser {
protected static final PredictionContextCache _sharedContextCache =
new PredictionContextCache();
public static final int
T__0=1, T__1=2, T__2=3, T__3=4, T__4=5, T__5=6, NAME=7, FLOAT=8, HEXINTEGER=9,
DECINTEGER=10, BININTEGER=11, WS=12;
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, STRING=23, BOOLEAN=24,
NUMBER=25, NUMFLOAT=26, BINFLOAT=27, DECFLOAT=28, HEXFLOAT=29, NUMINT=30,
BININTEGER=31, DECINTEGER=32, HEXINTEGER=33, NAME=34, WS=35;
public static final int
RULE_expr = 0;
public static final String[] ruleNames = {
@ -26,11 +29,15 @@ public class KickCParser extends Parser {
};
private static final String[] _LITERAL_NAMES = {
null, "'('", "')'", "'+'", "'-'", "'*'", "'/'"
null, "'('", "')'", "'+'", "'-'", "'not'", "'!'", "'*'", "'/'", "'='",
"'=='", "'!='", "'<>'", "'<'", "'<='", "'=<'", "'>='", "'=>'", "'>'",
"'and'", "'&&'", "'or'", "'||'"
};
private static final String[] _SYMBOLIC_NAMES = {
null, null, null, null, null, null, null, "NAME", "FLOAT", "HEXINTEGER",
"DECINTEGER", "BININTEGER", "WS"
null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null, null, "STRING",
"BOOLEAN", "NUMBER", "NUMFLOAT", "BINFLOAT", "DECFLOAT", "HEXFLOAT", "NUMINT",
"BININTEGER", "DECINTEGER", "HEXINTEGER", "NAME", "WS"
};
public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES);
@ -82,28 +89,142 @@ public class KickCParser extends Parser {
_interp = new ParserATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
}
public static class ExprContext extends ParserRuleContext {
public TerminalNode DECINTEGER() { return getToken(KickCParser.DECINTEGER, 0); }
public TerminalNode HEXINTEGER() { return getToken(KickCParser.HEXINTEGER, 0); }
public TerminalNode BININTEGER() { return getToken(KickCParser.BININTEGER, 0); }
public TerminalNode FLOAT() { return getToken(KickCParser.FLOAT, 0); }
public TerminalNode NAME() { return getToken(KickCParser.NAME, 0); }
public ExprContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_expr; }
public ExprContext() { }
public void copyFrom(ExprContext ctx) {
super.copyFrom(ctx);
}
}
public static class ExprBinaryContext extends ExprContext {
public List<ExprContext> expr() {
return getRuleContexts(ExprContext.class);
}
public ExprContext expr(int i) {
return getRuleContext(ExprContext.class,i);
}
public ExprContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_expr; }
public ExprBinaryContext(ExprContext ctx) { copyFrom(ctx); }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof KickCListener ) ((KickCListener)listener).enterExpr(this);
if ( listener instanceof KickCListener ) ((KickCListener)listener).enterExprBinary(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof KickCListener ) ((KickCListener)listener).exitExpr(this);
if ( listener instanceof KickCListener ) ((KickCListener)listener).exitExprBinary(this);
}
@Override
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof KickCVisitor ) return ((KickCVisitor<? extends T>)visitor).visitExprBinary(this);
else return visitor.visitChildren(this);
}
}
public static class ExprParContext extends ExprContext {
public ExprContext expr() {
return getRuleContext(ExprContext.class,0);
}
public ExprParContext(ExprContext ctx) { copyFrom(ctx); }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof KickCListener ) ((KickCListener)listener).enterExprPar(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof KickCListener ) ((KickCListener)listener).exitExprPar(this);
}
@Override
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof KickCVisitor ) return ((KickCVisitor<? extends T>)visitor).visitExprPar(this);
else return visitor.visitChildren(this);
}
}
public static class ExprStringContext extends ExprContext {
public TerminalNode STRING() { return getToken(KickCParser.STRING, 0); }
public ExprStringContext(ExprContext ctx) { copyFrom(ctx); }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof KickCListener ) ((KickCListener)listener).enterExprString(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof KickCListener ) ((KickCListener)listener).exitExprString(this);
}
@Override
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof KickCVisitor ) return ((KickCVisitor<? extends T>)visitor).visitExprString(this);
else return visitor.visitChildren(this);
}
}
public static class ExprBoolContext extends ExprContext {
public TerminalNode BOOLEAN() { return getToken(KickCParser.BOOLEAN, 0); }
public ExprBoolContext(ExprContext ctx) { copyFrom(ctx); }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof KickCListener ) ((KickCListener)listener).enterExprBool(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof KickCListener ) ((KickCListener)listener).exitExprBool(this);
}
@Override
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof KickCVisitor ) return ((KickCVisitor<? extends T>)visitor).visitExprBool(this);
else return visitor.visitChildren(this);
}
}
public static class ExprIdContext extends ExprContext {
public TerminalNode NAME() { return getToken(KickCParser.NAME, 0); }
public ExprIdContext(ExprContext ctx) { copyFrom(ctx); }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof KickCListener ) ((KickCListener)listener).enterExprId(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof KickCListener ) ((KickCListener)listener).exitExprId(this);
}
@Override
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof KickCVisitor ) return ((KickCVisitor<? extends T>)visitor).visitExprId(this);
else return visitor.visitChildren(this);
}
}
public static class ExprUnaryContext extends ExprContext {
public ExprContext expr() {
return getRuleContext(ExprContext.class,0);
}
public ExprUnaryContext(ExprContext ctx) { copyFrom(ctx); }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof KickCListener ) ((KickCListener)listener).enterExprUnary(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof KickCListener ) ((KickCListener)listener).exitExprUnary(this);
}
@Override
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof KickCVisitor ) return ((KickCVisitor<? extends T>)visitor).visitExprUnary(this);
else return visitor.visitChildren(this);
}
}
public static class ExprNumberContext extends ExprContext {
public TerminalNode NUMBER() { return getToken(KickCParser.NUMBER, 0); }
public ExprNumberContext(ExprContext ctx) { copyFrom(ctx); }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof KickCListener ) ((KickCListener)listener).enterExprNumber(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof KickCListener ) ((KickCListener)listener).exitExprNumber(this);
}
@Override
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof KickCVisitor ) return ((KickCVisitor<? extends T>)visitor).visitExprNumber(this);
else return visitor.visitChildren(this);
}
}
@ -123,55 +244,34 @@ public class KickCParser extends Parser {
int _alt;
enterOuterAlt(_localctx, 1);
{
setState(14);
setState(13);
_errHandler.sync(this);
switch (_input.LA(1)) {
case DECINTEGER:
{
setState(3);
match(DECINTEGER);
}
break;
case HEXINTEGER:
{
setState(4);
match(HEXINTEGER);
}
break;
case BININTEGER:
{
setState(5);
match(BININTEGER);
}
break;
case FLOAT:
{
setState(6);
match(FLOAT);
}
break;
case NAME:
{
setState(7);
match(NAME);
}
break;
case T__0:
{
setState(8);
_localctx = new ExprParContext(_localctx);
_ctx = _localctx;
_prevctx = _localctx;
setState(3);
match(T__0);
setState(9);
setState(4);
expr(0);
setState(10);
setState(5);
match(T__1);
}
break;
case T__2:
case T__3:
case T__4:
case T__5:
{
setState(12);
_localctx = new ExprUnaryContext(_localctx);
_ctx = _localctx;
_prevctx = _localctx;
setState(7);
_la = _input.LA(1);
if ( !(_la==T__2 || _la==T__3) ) {
if ( !((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << T__2) | (1L << T__3) | (1L << T__4) | (1L << T__5))) != 0)) ) {
_errHandler.recoverInline(this);
}
else {
@ -179,15 +279,51 @@ public class KickCParser extends Parser {
_errHandler.reportMatch(this);
consume();
}
setState(13);
expr(3);
setState(8);
expr(10);
}
break;
case NAME:
{
_localctx = new ExprIdContext(_localctx);
_ctx = _localctx;
_prevctx = _localctx;
setState(9);
match(NAME);
}
break;
case NUMBER:
{
_localctx = new ExprNumberContext(_localctx);
_ctx = _localctx;
_prevctx = _localctx;
setState(10);
match(NUMBER);
}
break;
case STRING:
{
_localctx = new ExprStringContext(_localctx);
_ctx = _localctx;
_prevctx = _localctx;
setState(11);
match(STRING);
}
break;
case BOOLEAN:
{
_localctx = new ExprBoolContext(_localctx);
_ctx = _localctx;
_prevctx = _localctx;
setState(12);
match(BOOLEAN);
}
break;
default:
throw new NoViableAltException(this);
}
_ctx.stop = _input.LT(-1);
setState(24);
setState(32);
_errHandler.sync(this);
_alt = getInterpreter().adaptivePredict(_input,2,_ctx);
while ( _alt!=2 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER ) {
@ -195,18 +331,18 @@ public class KickCParser extends Parser {
if ( _parseListeners!=null ) triggerExitRuleEvent();
_prevctx = _localctx;
{
setState(22);
setState(30);
_errHandler.sync(this);
switch ( getInterpreter().adaptivePredict(_input,1,_ctx) ) {
case 1:
{
_localctx = new ExprContext(_parentctx, _parentState);
_localctx = new ExprBinaryContext(new ExprContext(_parentctx, _parentState));
pushNewRecursionContext(_localctx, _startState, RULE_expr);
setState(15);
if (!(precpred(_ctx, 9))) throw new FailedPredicateException(this, "precpred(_ctx, 9)");
setState(16);
if (!(precpred(_ctx, 2))) throw new FailedPredicateException(this, "precpred(_ctx, 2)");
setState(17);
_la = _input.LA(1);
if ( !(_la==T__4 || _la==T__5) ) {
if ( !(_la==T__6 || _la==T__7) ) {
_errHandler.recoverInline(this);
}
else {
@ -214,17 +350,17 @@ public class KickCParser extends Parser {
_errHandler.reportMatch(this);
consume();
}
setState(18);
expr(3);
setState(17);
expr(10);
}
break;
case 2:
{
_localctx = new ExprContext(_parentctx, _parentState);
_localctx = new ExprBinaryContext(new ExprContext(_parentctx, _parentState));
pushNewRecursionContext(_localctx, _startState, RULE_expr);
setState(18);
if (!(precpred(_ctx, 8))) throw new FailedPredicateException(this, "precpred(_ctx, 8)");
setState(19);
if (!(precpred(_ctx, 1))) throw new FailedPredicateException(this, "precpred(_ctx, 1)");
setState(20);
_la = _input.LA(1);
if ( !(_la==T__2 || _la==T__3) ) {
_errHandler.recoverInline(this);
@ -234,14 +370,74 @@ public class KickCParser extends Parser {
_errHandler.reportMatch(this);
consume();
}
setState(20);
expr(9);
}
break;
case 3:
{
_localctx = new ExprBinaryContext(new ExprContext(_parentctx, _parentState));
pushNewRecursionContext(_localctx, _startState, RULE_expr);
setState(21);
expr(2);
if (!(precpred(_ctx, 7))) throw new FailedPredicateException(this, "precpred(_ctx, 7)");
setState(22);
_la = _input.LA(1);
if ( !((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << T__8) | (1L << T__9) | (1L << T__10) | (1L << T__11) | (1L << T__12) | (1L << T__13) | (1L << T__14) | (1L << T__15) | (1L << T__16) | (1L << T__17))) != 0)) ) {
_errHandler.recoverInline(this);
}
else {
if ( _input.LA(1)==Token.EOF ) matchedEOF = true;
_errHandler.reportMatch(this);
consume();
}
setState(23);
expr(8);
}
break;
case 4:
{
_localctx = new ExprBinaryContext(new ExprContext(_parentctx, _parentState));
pushNewRecursionContext(_localctx, _startState, RULE_expr);
setState(24);
if (!(precpred(_ctx, 6))) throw new FailedPredicateException(this, "precpred(_ctx, 6)");
setState(25);
_la = _input.LA(1);
if ( !(_la==T__18 || _la==T__19) ) {
_errHandler.recoverInline(this);
}
else {
if ( _input.LA(1)==Token.EOF ) matchedEOF = true;
_errHandler.reportMatch(this);
consume();
}
setState(26);
expr(7);
}
break;
case 5:
{
_localctx = new ExprBinaryContext(new ExprContext(_parentctx, _parentState));
pushNewRecursionContext(_localctx, _startState, RULE_expr);
setState(27);
if (!(precpred(_ctx, 5))) throw new FailedPredicateException(this, "precpred(_ctx, 5)");
setState(28);
_la = _input.LA(1);
if ( !(_la==T__20 || _la==T__21) ) {
_errHandler.recoverInline(this);
}
else {
if ( _input.LA(1)==Token.EOF ) matchedEOF = true;
_errHandler.reportMatch(this);
consume();
}
setState(29);
expr(6);
}
break;
}
}
}
setState(26);
setState(34);
_errHandler.sync(this);
_alt = getInterpreter().adaptivePredict(_input,2,_ctx);
}
@ -268,24 +464,33 @@ public class KickCParser extends Parser {
private boolean expr_sempred(ExprContext _localctx, int predIndex) {
switch (predIndex) {
case 0:
return precpred(_ctx, 2);
return precpred(_ctx, 9);
case 1:
return precpred(_ctx, 1);
return precpred(_ctx, 8);
case 2:
return precpred(_ctx, 7);
case 3:
return precpred(_ctx, 6);
case 4:
return precpred(_ctx, 5);
}
return true;
}
public static final String _serializedATN =
"\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\3\16\36\4\2\t\2\3\2"+
"\3\2\3\2\3\2\3\2\3\2\3\2\3\2\3\2\3\2\3\2\3\2\5\2\21\n\2\3\2\3\2\3\2\3"+
"\2\3\2\3\2\7\2\31\n\2\f\2\16\2\34\13\2\3\2\2\3\2\3\2\2\4\3\2\5\6\3\2\7"+
"\b\2$\2\20\3\2\2\2\4\5\b\2\1\2\5\21\7\f\2\2\6\21\7\13\2\2\7\21\7\r\2\2"+
"\b\21\7\n\2\2\t\21\7\t\2\2\n\13\7\3\2\2\13\f\5\2\2\2\f\r\7\4\2\2\r\21"+
"\3\2\2\2\16\17\t\2\2\2\17\21\5\2\2\5\20\4\3\2\2\2\20\6\3\2\2\2\20\7\3"+
"\2\2\2\20\b\3\2\2\2\20\t\3\2\2\2\20\n\3\2\2\2\20\16\3\2\2\2\21\32\3\2"+
"\2\2\22\23\f\4\2\2\23\24\t\3\2\2\24\31\5\2\2\5\25\26\f\3\2\2\26\27\t\2"+
"\2\2\27\31\5\2\2\4\30\22\3\2\2\2\30\25\3\2\2\2\31\34\3\2\2\2\32\30\3\2"+
"\2\2\32\33\3\2\2\2\33\3\3\2\2\2\34\32\3\2\2\2\5\20\30\32";
"\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\3%&\4\2\t\2\3\2\3\2"+
"\3\2\3\2\3\2\3\2\3\2\3\2\3\2\3\2\3\2\5\2\20\n\2\3\2\3\2\3\2\3\2\3\2\3"+
"\2\3\2\3\2\3\2\3\2\3\2\3\2\3\2\3\2\3\2\7\2!\n\2\f\2\16\2$\13\2\3\2\2\3"+
"\2\3\2\2\b\3\2\5\b\3\2\t\n\3\2\5\6\3\2\13\24\3\2\25\26\3\2\27\30\2.\2"+
"\17\3\2\2\2\4\5\b\2\1\2\5\6\7\3\2\2\6\7\5\2\2\2\7\b\7\4\2\2\b\20\3\2\2"+
"\2\t\n\t\2\2\2\n\20\5\2\2\f\13\20\7$\2\2\f\20\7\33\2\2\r\20\7\31\2\2\16"+
"\20\7\32\2\2\17\4\3\2\2\2\17\t\3\2\2\2\17\13\3\2\2\2\17\f\3\2\2\2\17\r"+
"\3\2\2\2\17\16\3\2\2\2\20\"\3\2\2\2\21\22\f\13\2\2\22\23\t\3\2\2\23!\5"+
"\2\2\f\24\25\f\n\2\2\25\26\t\4\2\2\26!\5\2\2\13\27\30\f\t\2\2\30\31\t"+
"\5\2\2\31!\5\2\2\n\32\33\f\b\2\2\33\34\t\6\2\2\34!\5\2\2\t\35\36\f\7\2"+
"\2\36\37\t\7\2\2\37!\5\2\2\b \21\3\2\2\2 \24\3\2\2\2 \27\3\2\2\2 \32\3"+
"\2\2\2 \35\3\2\2\2!$\3\2\2\2\" \3\2\2\2\"#\3\2\2\2#\3\3\2\2\2$\"\3\2\2"+
"\2\5\17 \"";
public static final ATN _ATN =
new ATNDeserializer().deserialize(_serializedATN.toCharArray());
static {

View File

@ -0,0 +1,62 @@
// Generated from /Users/jespergravgaard/c64/src/kickc/src/dk/camelot64/kickc/parser/KickC.g4 by ANTLR 4.7
package dk.camelot64.kickc.parser;
import org.antlr.v4.runtime.tree.ParseTreeVisitor;
/**
* This interface defines a complete generic visitor for a parse tree produced
* by {@link KickCParser}.
*
* @param <T> The return type of the visit operation. Use {@link Void} for
* operations with no return type.
*/
public interface KickCVisitor<T> extends ParseTreeVisitor<T> {
/**
* Visit a parse tree produced by the {@code exprBinary}
* labeled alternative in {@link KickCParser#expr}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitExprBinary(KickCParser.ExprBinaryContext ctx);
/**
* Visit a parse tree produced by the {@code exprPar}
* labeled alternative in {@link KickCParser#expr}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitExprPar(KickCParser.ExprParContext ctx);
/**
* Visit a parse tree produced by the {@code exprString}
* labeled alternative in {@link KickCParser#expr}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitExprString(KickCParser.ExprStringContext ctx);
/**
* Visit a parse tree produced by the {@code exprBool}
* labeled alternative in {@link KickCParser#expr}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitExprBool(KickCParser.ExprBoolContext ctx);
/**
* Visit a parse tree produced by the {@code exprId}
* labeled alternative in {@link KickCParser#expr}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitExprId(KickCParser.ExprIdContext ctx);
/**
* Visit a parse tree produced by the {@code exprUnary}
* labeled alternative in {@link KickCParser#expr}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitExprUnary(KickCParser.ExprUnaryContext ctx);
/**
* Visit a parse tree produced by the {@code exprNumber}
* labeled alternative in {@link KickCParser#expr}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitExprNumber(KickCParser.ExprNumberContext ctx);
}

View File

@ -0,0 +1,77 @@
package dk.camelot64.kickc.ssa;
import dk.camelot64.kickc.parser.KickCBaseVisitor;
import dk.camelot64.kickc.parser.KickCParser;
import org.antlr.v4.runtime.tree.TerminalNode;
/** Generates program SSA form by visiting the ANTLR4 parse tree*/
public class GenerateSSA extends KickCBaseVisitor<SSAFragment> {
SSAVariableManager variableManager;
public GenerateSSA(SSAVariableManager variableManager) {
this.variableManager = variableManager;
}
@Override
public SSAFragment visitExprNumber(KickCParser.ExprNumberContext ctx) {
Number number = KickCNumberParser.parseLiteral(ctx.getText());
if(number instanceof Integer) {
return new SSAConstantInteger((Integer) number);
} else {
return new SSAConstantDouble((Double) number);
}
}
@Override
public SSAFragment visitExprString(KickCParser.ExprStringContext ctx) {
return new SSAConstantString(ctx.getText());
}
@Override
public SSAFragment visitExprBool(KickCParser.ExprBoolContext ctx) {
String bool = ctx.getText();
return new SSAConstantBool(new Boolean(bool));
}
@Override
public SSAFragment visitExprBinary(KickCParser.ExprBinaryContext ctx) {
SSAFragment left = this.visit(ctx.expr(0));
SSAFragment right = this.visit(ctx.expr(1));
String op = ((TerminalNode)ctx.getChild(1)).getSymbol().getText();
SSAOperator operator = new SSAOperator(op);
SSAVariable tmpVar = variableManager.generateIntermediateVariable();
SSAStatement stmt = new SSAStatement(tmpVar, getSSARValue(left), operator, getSSARValue(right));
System.out.println(stmt);
return stmt;
}
@Override
public SSAFragment visitExprUnary(KickCParser.ExprUnaryContext ctx) {
SSAFragment child = this.visit(ctx.expr());
String op = ((TerminalNode)ctx.getChild(0)).getSymbol().getText();
SSAOperator operator = new SSAOperator(op);
SSAVariable tmpVar = variableManager.generateIntermediateVariable();
SSAStatement stmt = new SSAStatement(tmpVar, operator, getSSARValue(child));
System.out.println(stmt);
return stmt;
}
@Override
public SSAFragment visitExprPar(KickCParser.ExprParContext ctx) {
return this.visit(ctx.expr());
}
SSARValue getSSARValue(SSAFragment ssaFragment) {
if(ssaFragment instanceof SSARValue) {
return (SSARValue) ssaFragment;
} if(ssaFragment instanceof SSAStatement) {
SSAStatement ssaStatement = (SSAStatement) ssaFragment;
return (SSARValue) ssaStatement.getlValue();
}
throw new RuntimeException("Cannot extract SSA RValue");
}
}

View File

@ -0,0 +1,39 @@
package dk.camelot64.kickc.ssa;
/** Parser for converting literal numbers to the corresponding Java Integer/Double */
public class KickCNumberParser {
public static Number parseLiteral(String literal) {
boolean isInt = !literal.contains(".");
if(isInt) {
if(literal.startsWith("0x")) {
return parseHexInt(literal.substring(2));
} else if(literal.startsWith("$")) {
return parseHexInt(literal.substring(1));
} else if(literal.startsWith("0b")) {
return parseBinInt(literal.substring(2));
} else if(literal.startsWith("%")) {
return parseBinInt(literal.substring(1));
} else {
return parseDecInt(literal);
}
} else {
throw new RuntimeException("Not Implemented: non-integer parsing");
}
}
private static Integer parseHexInt(String literal) {
return Integer.parseInt(literal, 16);
}
private static Integer parseBinInt(String literal) {
return Integer.parseInt(literal, 2);
}
private static Integer parseDecInt(String literal) {
return Integer.parseInt(literal);
}
}

View File

@ -0,0 +1,7 @@
package dk.camelot64.kickc.ssa;
/**
* Created by jespergravgaard on 02/05/2017.
*/
public class SSABasicBlock {
}

View File

@ -0,0 +1,7 @@
package dk.camelot64.kickc.ssa;
/** SSA form constant value */
public interface SSAConstant extends SSARValue, SSAFragment {
}

View File

@ -0,0 +1,18 @@
package dk.camelot64.kickc.ssa;
/**
* SSA form constant integer value
*/
public class SSAConstantBool implements SSAConstant {
private Boolean value;
public SSAConstantBool(Boolean value) {
this.value = value;
}
@Override
public String toString() {
return Boolean.toString(value);
}
}

View File

@ -0,0 +1,18 @@
package dk.camelot64.kickc.ssa;
/**
* SSA form constant integer value
*/
public class SSAConstantDouble implements SSAConstant {
private Double number;
public SSAConstantDouble(Double number) {
this.number= number;
}
@Override
public String toString() {
return Double.toString(number);
}
}

View File

@ -0,0 +1,18 @@
package dk.camelot64.kickc.ssa;
/**
* SSA form constant integer value
*/
public class SSAConstantInteger implements SSAConstant {
private Integer number;
public SSAConstantInteger(Integer number) {
this.number = number;
}
@Override
public String toString() {
return Integer.toString(number);
}
}

View File

@ -0,0 +1,18 @@
package dk.camelot64.kickc.ssa;
/**
* SSA form constant integer value
*/
public class SSAConstantString implements SSAConstant {
private String value;
public SSAConstantString(String value) {
this.value = value;
}
@Override
public String toString() {
return "\\"+value+"\\";
}
}

View File

@ -0,0 +1,7 @@
package dk.camelot64.kickc.ssa;
/**
* Any SSA Form fragment resulting from translating a part of the parse tree
*/
public interface SSAFragment {
}

View File

@ -0,0 +1,5 @@
package dk.camelot64.kickc.ssa;
/** Left value in SSA Form */
public interface SSALValue {
}

View File

@ -0,0 +1,16 @@
package dk.camelot64.kickc.ssa;
/** SSA Form Operator. The operation performed on the rvalues in an SSA Statement. */
public class SSAOperator {
private String operator;
public SSAOperator(String operator) {
this.operator = operator;
}
@Override
public String toString() {
return operator ;
}
}

View File

@ -0,0 +1,5 @@
package dk.camelot64.kickc.ssa;
/** Right value in SSA FORM */
public interface SSARValue {
}

View File

@ -0,0 +1,52 @@
package dk.camelot64.kickc.ssa;
/**
* Single Static Assignment Form Statement.
* Intermediate form used for compiler optimization.
* <br>
* <i> X<sub>i</sub> := Y<sub>j</sub> &lt;op&gt; Z<sub>k</sub> </i>
* <br>
* <i> lValue := rValue1 &lt;operator&gt; rValue2 </i>
*/
public class SSAStatement implements SSAFragment {
private SSALValue lValue;
private SSARValue rValue1;
private SSAOperator operator;
private SSARValue rValue2;
public SSAStatement(SSALValue lValue, SSARValue rValue1, SSAOperator operator, SSARValue rValue2) {
this.lValue = lValue;
this.rValue1 = rValue1;
this.operator = operator;
this.rValue2 = rValue2;
}
public SSAStatement(SSALValue lValue, SSAOperator operator, SSARValue rValue2) {
this.lValue = lValue;
this.rValue1 = null;
this.operator = operator;
this.rValue2 = rValue2;
}
public SSALValue getlValue() {
return lValue;
}
public SSARValue getrValue1() {
return rValue1;
}
public SSAOperator getOperator() {
return operator;
}
public SSARValue getrValue2() {
return rValue2;
}
@Override
public String toString() {
return lValue + " := " + (rValue1==null?"":rValue1) + " " + operator + " " + rValue2 ;
}
}

View File

@ -0,0 +1,31 @@
package dk.camelot64.kickc.ssa;
/** An SSA form Variable. SSA form variables come in different flavors:
* <ul>
* <li>Each potential modification of a language variable becomes a separate versioned SSA variable.</li>
* <li>Expressions are broken into separate SSA statements, each defining a new temporary/intermediate variable.</li>
* </ul>*/
public class SSAVariable implements SSARValue, SSALValue {
private String name;
private int serial;
public SSAVariable(String name, int serial) {
this.name = name;
this.serial = serial;
}
public String getName() {
return name;
}
public int getSerial() {
return serial;
}
@Override
public String toString() {
return name + '_' + serial;
}
}

View File

@ -0,0 +1,12 @@
package dk.camelot64.kickc.ssa;
/** Manages creation of new variables from declarations or temporary (intermediate) */
public class SSAVariableManager {
private int nxtTemporaryId = 1;
public SSAVariable generateIntermediateVariable() {
return new SSAVariable("@", nxtTemporaryId++);
}
}

View File

@ -0,0 +1,26 @@
package dk.camelot64.kickc.test;
import dk.camelot64.kickc.parser.KickCLexer;
import dk.camelot64.kickc.parser.KickCParser;
import dk.camelot64.kickc.ssa.GenerateSSA;
import dk.camelot64.kickc.ssa.SSAVariableManager;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CommonTokenStream;
import java.io.IOException;
/** Test my KickC Grammar */
public class main {
public static void main(String [] args) throws IOException {
CharStream input = CharStreams.fromFileName("src/dk/camelot64/kickc/test/test.kc");
System.out.println(input.toString());
KickCLexer lexer = new KickCLexer(input);
KickCParser parser = new KickCParser(new CommonTokenStream(lexer));
parser.setBuildParseTree(true);
KickCParser.ExprContext expr = parser.expr();
GenerateSSA ev = new GenerateSSA(new SSAVariableManager());
Object result = ev.visit(expr);
}
}

View File

@ -0,0 +1 @@
1+2*3/(-$4+%101) = 12 || 1+1=2 && "qwe" < "asd" and not false