summaryrefslogtreecommitdiff
path: root/Compiler/CGrammar.g4
diff options
context:
space:
mode:
authorMelodi <62381002+Melodi17@users.noreply.github.com>2025-08-27 21:22:55 +1000
committerMelodi <62381002+Melodi17@users.noreply.github.com>2025-08-27 21:22:55 +1000
commit634681ce2bb36cd686943102a0f071cd6a09049f (patch)
tree6710047aa231d50f57114bdd54a27c559fb20a73 /Compiler/CGrammar.g4
parent94ddc02e03ab942d0c881e29053e8df3d2940c30 (diff)
fixed bugs and revolutionized the universe
Diffstat (limited to 'Compiler/CGrammar.g4')
-rw-r--r--Compiler/CGrammar.g417
1 files changed, 12 insertions, 5 deletions
diff --git a/Compiler/CGrammar.g4 b/Compiler/CGrammar.g4
index b0a03f7..f89896a 100644
--- a/Compiler/CGrammar.g4
+++ b/Compiler/CGrammar.g4
@@ -4,13 +4,16 @@ options {
contextSuperClass = Q1.Compiler.Context;
}
-HEX: '0x' [0-9a-fA-F];
+HEX: '0x' [0-9a-fA-F]+;
ID: [a-zA-Z_][a-zA-Z0-9_]*;
INT: [0-9]+;
WS: [ \t\r\n]+ -> skip;
COMMENT: '//' .*? ([\n] | EOF) -> channel(HIDDEN);
+DIRECTIVE: '#' .*? ([\n] | EOF) -> channel(HIDDEN);
+LETTER: '\'' . '\'';
+STRING: '"' .*? '"';
program
: function+ EOF
@@ -52,6 +55,7 @@ declaration
expression
: '(' expression ')' #parenthesizedExpression
// | left=expression ',' right=expression #commaExpression
+ | 'new' type '[' INT? ']' '{' ( params+=expression (',' params+=expression )* )? '}' #arrayExpression
| constant #constantExpression
| target '=' expression #assignmentExpression
| '*' expression #dereferenceExpression
@@ -59,7 +63,7 @@ expression
| ID #variableExpression
| ID '(' ( params+=expression (',' params+=expression )* )? ')' #callExpression
- | obj=expression '[' indexer=expression ']' #indexExpression
+ | obj=target '[' indexer=expression ']' #indexExpression
| '!' expression #notExpression
| '~' expression #invertExpression
@@ -113,14 +117,17 @@ expression
constant
: INT # intConstant
| HEX # hexConstant
+ | LETTER # charConstant
+ | STRING # stringConstant
;
type
- : 'int' #intType
- | 'char' #charType
- | type '*' #pointerType
+ : 'int'
+ | 'char'
+ | type '*'
;
target
: ID # variableTarget
+ | obj=target '[' indexer=expression ']' #indexerTarget
; \ No newline at end of file