forked from llvm-mirror/llvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@97966 91177308-0d34-0410-b5e6-96231b3b80d8
- Loading branch information
Erick Tryzelaar
committed
Mar 8, 2010
1 parent
9ef76b9
commit 49457b8
Showing
65 changed files
with
3,508 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
##===- examples/OCaml-Kaleidoscope/Chapter2/Makefile -------*- Makefile -*-===## | ||
# | ||
# The LLVM Compiler Infrastructure | ||
# | ||
# This file is distributed under the University of Illinois Open Source | ||
# License. See LICENSE.TXT for details. | ||
# | ||
##===----------------------------------------------------------------------===## | ||
# | ||
# This is the makefile for the Objective Caml kaleidoscope tutorial, chapter 2. | ||
# | ||
##===----------------------------------------------------------------------===## | ||
|
||
LEVEL := ../../.. | ||
TOOLNAME := OCaml-Kaleidoscope-Ch2 | ||
EXAMPLE_TOOL := 1 | ||
UsedComponents := core | ||
UsedOcamLibs := llvm | ||
|
||
OCAMLCFLAGS += -pp camlp4of | ||
|
||
include $(LEVEL)/bindings/ocaml/Makefile.ocaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<{lexer,parser}.ml>: use_camlp4, pp(camlp4of) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
(*===----------------------------------------------------------------------=== | ||
* Abstract Syntax Tree (aka Parse Tree) | ||
*===----------------------------------------------------------------------===*) | ||
|
||
(* expr - Base type for all expression nodes. *) | ||
type expr = | ||
(* variant for numeric literals like "1.0". *) | ||
| Number of float | ||
|
||
(* variant for referencing a variable, like "a". *) | ||
| Variable of string | ||
|
||
(* variant for a binary operator. *) | ||
| Binary of char * expr * expr | ||
|
||
(* variant for function calls. *) | ||
| Call of string * expr array | ||
|
||
(* proto - This type represents the "prototype" for a function, which captures | ||
* its name, and its argument names (thus implicitly the number of arguments the | ||
* function takes). *) | ||
type proto = Prototype of string * string array | ||
|
||
(* func - This type represents a function definition itself. *) | ||
type func = Function of proto * expr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
(*===----------------------------------------------------------------------=== | ||
* Lexer | ||
*===----------------------------------------------------------------------===*) | ||
|
||
let rec lex = parser | ||
(* Skip any whitespace. *) | ||
| [< ' (' ' | '\n' | '\r' | '\t'); stream >] -> lex stream | ||
(* identifier: [a-zA-Z][a-zA-Z0-9] *) | ||
| [< ' ('A' .. 'Z' | 'a' .. 'z' as c); stream >] -> | ||
let buffer = Buffer.create 1 in | ||
Buffer.add_char buffer c; | ||
lex_ident buffer stream | ||
(* number: [0-9.]+ *) | ||
| [< ' ('0' .. '9' as c); stream >] -> | ||
let buffer = Buffer.create 1 in | ||
Buffer.add_char buffer c; | ||
lex_number buffer stream | ||
(* Comment until end of line. *) | ||
| [< ' ('#'); stream >] -> | ||
lex_comment stream | ||
(* Otherwise, just return the character as its ascii value. *) | ||
| [< 'c; stream >] -> | ||
[< 'Token.Kwd c; lex stream >] | ||
(* end of stream. *) | ||
| [< >] -> [< >] | ||
and lex_number buffer = parser | ||
| [< ' ('0' .. '9' | '.' as c); stream >] -> | ||
Buffer.add_char buffer c; | ||
lex_number buffer stream | ||
| [< stream=lex >] -> | ||
[< 'Token.Number (float_of_string (Buffer.contents buffer)); stream >] | ||
and lex_ident buffer = parser | ||
| [< ' ('A' .. 'Z' | 'a' .. 'z' | '0' .. '9' as c); stream >] -> | ||
Buffer.add_char buffer c; | ||
lex_ident buffer stream | ||
| [< stream=lex >] -> | ||
match Buffer.contents buffer with | ||
| "def" -> [< 'Token.Def; stream >] | ||
| "extern" -> [< 'Token.Extern; stream >] | ||
| id -> [< 'Token.Ident id; stream >] | ||
and lex_comment = parser | ||
| [< ' ('\n'); stream=lex >] -> stream | ||
| [< 'c; e=lex_comment >] -> e | ||
| [< >] -> [< >] |
Oops, something went wrong.