straightline-ocaml-2022-2
所属分类:人工智能/神经网络/深度学习
开发工具:OCaml
文件大小:0KB
下载次数:0
上传日期:2022-12-19 17:23:53
上 传 者:
sh-1993
说明: Straightline是《ML中的现代编译器实现》一书中的一种玩具编程语言,
(Straightline is a toy programming language from the book Modern Compiler Implementation in ML,)
文件列表:
LICENSE (1080, 2022-12-19)
bin/ (0, 2022-12-19)
bin/dune (187, 2022-12-19)
bin/main.ml (41, 2022-12-19)
bin/test.ml (97, 2022-12-19)
dune-project (36, 2022-12-19)
lib/ (0, 2022-12-19)
lib/ast.ml (269, 2022-12-19)
lib/dune (86, 2022-12-19)
lib/maxargs.ml (547, 2022-12-19)
shell.nix (437, 2022-12-19)
# The *straightline* programming language
**Straightline** is a micro programming language used in the book series [Modern Compiler Implementation](http://www.cs.princeton.edu/~appel/modern/) by Andrew Appel.
# Grammar
- The syntax of the language is given by a context free grammar.
- Only the production rules are explicitly given.
- The sets of terminals and non-terminals are obtained from the rules.
- The initial symbol is the non-terminal on the left side of the first production rule.
## Production rules
_Stm_ → _Stm_ `;` _Stm_
_Stm_ → `id` `:=` _Exp_
_Stm_ → `print` `(` _ExpList_ `)`
_Exp_ → `id`
_Exp_ → `num`
_Exp_ → _Exp_ _Binop_ _Exp_
_Exp_ → `(` _Stm_ `,` _Exp_ `)`
_ExpList_ → _Exp_
_ExpList_ → _Exp_ `,` _ExpList_
_Binop_ → `+`
_Binop_ → `-`
_Binop_ → `*`
_Binop_ → `/`
## Operator Precedence and Associativity
In order to resolve possible conflicts during syntactic analysis, the following relation of operator precedence and associativity, in descending order, should be observed:
| operators | associativity |
|-|-|
|`*` `/`|left|
|`+` `-`|left|
|`:=`|right|
## Lexical symbols
- Spaces, newlines, and tabulators are **white spaces**.
- **Comments** starts with `#` and extends to the end of the line.
- A **numerical literal** is a sequence of one or more digits, optionally followed by a `.` and another sequence of one or more digits.
- An **identifier** is a sequence of one or more letters, digits and underscores, beginning with a letter, that is not a keyword.
- The **keywords** are: `print`.
- The **operators** are: `:=`, `+`, `-`, `*` and `/`.
- The **special symbols** are: `,`, `;`, `(` and `)`.
# Example
```
a := 5 + 3;
b := ( print(a, a-1), 10*a );
print(b)
```
近期下载者:
相关文件:
收藏者: