I'm currently trying to translate OCaml programs (with a fairly standard/limited grammar) into Racket, and I'm trying to see if there is a way to do the parsing to intermediate representation using camlp4. I tried to build a lexer and parser using ocamlyacc and ocamllex but considering how large the grammar can be, it became quite complicated. So, I searched around and found camlp4 to have some of this already built-in, but I can't seem to look up how to get the AST of some OCaml code using it. Any documentation/examples/ideas? Also, if you have any suggestions on how to do this better, that'd be great as well! Thanks.
How do I use camlp4 in an OCaml program to parse another OCaml program into an AST?
147 Views Asked by podington At
1
There are 1 best solutions below
Related Questions in PARSING
- TypeScript: Type checking while parsing an arbitrary JSON that is typed/
- How to have fixed options using Option.Applicative in haskell?
- How to convert mathematical expression to lambda function in C++?
- JsonObject throws an exception: JSONObject["employer_website"] is not a string (class org.json.JSONObject$Null : null)
- Trying to fix my c++ code for it to read the right amount of nodes from a file
- Selenium get page after "loading" page
- Parse tag in html via Google Sheets (importxml)
- FluentD / Fluent-Bit: Concatenate multiple lines of log files and generate one JSON record for all key-value from each line
- Editing non-String values in JComboBox
- Handling multiple errors in Bison parser
- Which is the most idiomatic way to parse an i32 from ascii in Rust
- I got this error from a JSON Validator - what does this mean?
- Conflict between lexer rules in ANTLR4 for Fortran grammar
- mqtt message parsing problem in a node.js
- How to print error code from URL response in swift
Related Questions in OCAML
- Why can't dune recognize ppx_jane?
- Is there a function that returns a list of values with specific type in OCaml?
- How to use menhir to parse into a GADT expression?
- How to generate Menhir .automaton files with dune in OCaml?
- matching multiple patterns at once in ocaml
- What causes this type mismatch when applying a functor?
- What is the right way to put type declarations in OCaml signatures
- Obtain an interpretation of unbounded variables using Z3 in OCaml
- Using infix operator in the module in OCaml
- Do any OCaml compilers take advantage of the unspecified order of evaluation of let ... and bindings?
- Nesting algebraic handlers from separate modules
- Can I define pattern synonyms in OCaml?
- OCaml functions on uncertain data types
- Module unavailable when compiling another file that uses it in OCaml
- Can't understand the syntax in ocaml code
Related Questions in ABSTRACT-SYNTAX-TREE
- Javascript to Java
- Resolve complex types using Typescript AST
- AST matcher for C++ #include
- How to parse and group hierarchical list items from an unindented string in Python?
- How can I parse the standard Go package and print all constant variables?
- How to share lexical environment with recursive functions in a custom interpreter?
- How can I use custom grammar with the ast-grep Python API?
- Adding new enumerators to an Enum specifier using CDT ASTRewrite
- library to generate embedding of each line of java file and embeddings must contain ast information
- the expressionType and includePath of CDT parser
- Why Golang ast.Field can have multiple names?
- How to find ast dictionary item in Python using xpath-like expressions
- python multiprocessing locks inside async function
- How to find all function calls a defined function makes? (including recursive and futher down the stack calls)
- Changing the format of data in Python
Related Questions in CAMLP4
- Camlp5: Converting a polymorphic type definition to strict syntax
- Install camlp4 version with opam switch
- In Ocaml Camlp5 is not installing (and it is necessary to use Quotations)
- OCaml guards syntax after a value
- Camlp4 Parser function: expression has type int but an expression was expected of type float
- How to display location info from a parser?
- How does one install camlp5 compatible with version 4.05.0 of ocaml?
- OCaml and preprocessor have incompatible versions error when installing tcoq
- js_of_ocaml Camlp4 Parse error in type definition
- utop no longer supporting camlp4?
- OCaml / Camlp4 - renaming polymorphic variants
- camlp5: how to nest antiquotations
- Lexer/filter for comments
- camlp5 IFNDEF STRICT doing the opposite of what I expect
- How do I use camlp4 in an OCaml program to parse another OCaml program into an AST?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Just use compiler-libs, which is distributed with the compiler. You can use the ocaml parser itself directly that way.
Here is an example of code that reads a .ml file. The documentation for the parser is quite decent. You will obtain, after parsing, a Parsetree.