straightline-ocaml-2022-1

所属分类:人工智能/神经网络/深度学习
开发工具:OCaml
文件大小:0KB
下载次数:0
上传日期:2022-10-17 15:57:18
上 传 者sh-1993
说明:  《Moden编译器ML实现》一书中的玩具编程语言,
(Toy programming language from the book Moden Compiler Implementation in ML,)

文件列表:
LICENSE (1080, 2022-10-17)
bin/ (0, 2022-10-17)
bin/dune (88, 2022-10-17)
bin/main.ml (202, 2022-10-17)
driver/ (0, 2022-10-17)
driver/driver.ml (982, 2022-10-17)
driver/dune (181, 2022-10-17)
dune-project (55, 2022-10-17)
examples/ (0, 2022-10-17)
examples/test1.prg (45, 2022-10-17)
lib/ (0, 2022-10-17)
lib/ast.ml (351, 2022-10-17)
lib/dune (480, 2022-10-17)
lib/error.ml (561, 2022-10-17)
lib/examples.ml (1728, 2022-10-17)
lib/lexer.mll (968, 2022-10-17)
lib/location.ml (1401, 2022-10-17)
lib/maxargs.ml (720, 2022-10-17)
lib/parser.mly (1019, 2022-10-17)
lib/symbol.ml (1309, 2022-10-17)
lib/totree.ml (843, 2022-10-17)
scanner-adhoc/ (0, 2022-10-17)
scanner-adhoc/dune (76, 2022-10-17)
scanner-adhoc/scanner.ml (2353, 2022-10-17)
scanner-adhoc/scanner.mli (360, 2022-10-17)
scanner-adhoc/scanner_test.ml (491, 2022-10-17)
shell.nix (710, 2022-10-17)
straightline.opam (0, 2022-10-17)

# 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. - 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) ```

近期下载者

相关文件


收藏者