diff options
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 |
