diff options
| author | Cliff Click <cliffc@acm.org> | 2023-09-07 14:32:31 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-09-07 14:32:31 -0700 |
| commit | ee3a2f571897b23caecfe9cfe4f5e4338007f885 (patch) | |
| tree | 5a32a60e3070347c99b4ee6fa572533f90d77085 /chapter01 | |
| parent | 1571eeeb41c3af5cc2da23ce4edbc69cf53bd383 (diff) | |
| parent | dbd9798602c3b80bc00c93c797b942dcb0e234c1 (diff) | |
| download | Simple-ee3a2f571897b23caecfe9cfe4f5e4338007f885.tar.gz Simple-ee3a2f571897b23caecfe9cfe4f5e4338007f885.zip | |
Merge pull request #2 from dibyendumajumdar/main
Initial framework for the project
Diffstat (limited to 'chapter01')
| -rw-r--r-- | chapter01/README.md | 5 | ||||
| -rw-r--r-- | chapter01/docs/01-grammar.md | 39 | ||||
| -rw-r--r-- | chapter01/pom.xml | 14 |
3 files changed, 58 insertions, 0 deletions
diff --git a/chapter01/README.md b/chapter01/README.md new file mode 100644 index 00000000..a641c4ad --- /dev/null +++ b/chapter01/README.md @@ -0,0 +1,5 @@ +# Chapter 1 +Simple start and end node for basic empty script. + + +* [Grammar](docs/01-grammar.md)
\ No newline at end of file diff --git a/chapter01/docs/01-grammar.md b/chapter01/docs/01-grammar.md new file mode 100644 index 00000000..92ed7357 --- /dev/null +++ b/chapter01/docs/01-grammar.md @@ -0,0 +1,39 @@ +# Grammar for Chapter 1 + +```antlrv4 +grammar SimpleLanguage; + +program + : declaration* statement+ EOF + ; + +declaration + : type IDENTIFIER ';' + ; + +type + : 'int' + ; + +statement + : 'if' '(' expression ')' statement + | 'if' '(' expression ')' statement 'else' statement + | 'while' '(' expression ')' statement + | IDENTIFIER '=' expression ';' + | '{' declaration* statement+ '}' + | 'break' ';' + ; + +expression + : primaryExpression # PrimaryExpression_ + | expression ('*' | '/' ) expression # ArithmeticOrLogicalExpression + | expression ('+' | '-') expression # ArithmeticOrLogicalExpression + ; + +primaryExpression + : + | INTEGER_LITERAL + | IDENTIFIER + | '(' expression ')' + ; +```
\ No newline at end of file diff --git a/chapter01/pom.xml b/chapter01/pom.xml new file mode 100644 index 00000000..2204bde8 --- /dev/null +++ b/chapter01/pom.xml @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>com.seaofnodes</groupId> + <artifactId>simple</artifactId> + <version>1.0</version> + </parent> + <artifactId>chapter01</artifactId> + <packaging>jar</packaging> + <name>Chapter 1</name> +</project>
\ No newline at end of file |
