mylang | A simple programming language inspired by Python | Interpreter library
kandi X-RAY | mylang Summary
kandi X-RAY | mylang Summary
MyLang is a simple educational programming language inspired by Python, JavaScript, and C, written as a personal challenge, in a short time, mostly to have fun writing a recursive descent parser and explore the world of interpreters. Don't expect a full-blown scripting language with libraries and frameworks ready for production use. However, MyLang has a minimal set of builtins and, it could be used for practical purposes as well.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of mylang
mylang Key Features
mylang Examples and Code Snippets
Community Discussions
Trending Discussions on mylang
QUESTION
I'm working on trying to create and use tree-sitter grammar in a language server I am implementing in order to support features like finding all references of a variable. Given the grammar I would be able to write a query to find all of the references to a variable with a specific name (ex. myVar
). However, the language I am writing a language server for uses case insensitive variables (ex. myVar
can be referenced as MYVAR
, MyVaR
, myvar
, etc.).
How would I be able to write a tree-sitter query to match a pattern where a token must case-insensitively match a particular string?
I could write the query to not filter by the variable name and implement my own filtering of the results, but I was wondering if there was a way to handle this within the query itself rather than implementing custom filtering code.
ExampleHere is a simplified example case to show what I mean.
Given the following grammar, I want to query for all of the set_statements
that set a new value to the variable myVar
.
ANSWER
Answered 2021-Jun-02 at 21:37Change your query to match a regular expression matching all possible upper/lower combinations of an identifier, in this case myvar
.
If you change find_variable.query to use match with a regular expression for all case combinations:
QUESTION
I use BNFC to generate parser bnfc -m -c ./mylang.cf
. Internally, BNFC makefile calls bison to generate C parser.
ANSWER
Answered 2021-Mar-10 at 05:25These sort of questions should be answered in the documentation for the tool. But I couldn't find them there :-( I don't have a lot of experience with BNFC, either, so be cautious applying this answer.
psProc
calls the lexer'sscan_string
interface, and that interface makes a copy of the provided string. Flex likes to modify the input as it tokenises, so it can only deal withconst char*
inputs by copying them. So the string could have been freed immediately after the call toscan_string
, butpsProc
parses the entire input before returning so you don't have anyway to do that. You can certainly free the string whenpsProc
returns.I doubt whether this is an issue for you, but if you are planning on parsing very large in-memory strings, you might want to consider using
fmemopen
(at least, on Posix platforms) to open the string as aFILE*
. That doesn't avoid the copy, but it does it in chunks of 8k or so, which avoids keeping two copies of the entire string during the parse.I have no idea how BNFC expects you to free parse tree nodes. (In fact, I rather suspect that it doesn't expect you to do that.) The nodes are linked with internal pointers, and it would certainly be possible to write an AST walker which free'd all the nodes recursively using a post-order traverse. But I don't see any generated code which does that. Perhaps I haven't looked hard enough.
Calling
free()
on the top-level node will just free one node. The rest of the tree will then be leaked, since no other pointers to it exist.I'm pretty sure your suspicion about thread safety are correct. The global is assigned to by the reduction action for the
Proc
production, and then later returned bypsProc
. There's no locking, so if there were another parser in another thread, the global could get overwritten. The global is just a pointer to the node which is to be returned, and the node itself should be thread-safe, since it is dynamically-allocated by the parser thread. So you could probably change the declaration of the global(s) to use thread-local storage, but that would have to be done by postprocessing the generated code.
QUESTION
I am building my language system using XAML files.
The code I have is as follows:
es.xaml
...ANSWER
Answered 2020-Nov-16 at 14:54What you are trying to do is possible by using DynamicResource
like you did for TextBlock
:
QUESTION
It is a common K idiom to define a programming language's syntax with a top-sort of well-formed programs (e.g. Pgm
) and then to restrict the cell to have this sort in the configuration declaration using the special
$PGM
variable which is passed automatically by krun
. This prevents users from executing programs with krun
that are not well-formed. My question is:
- Are the sort of cells checked only at start-up time or after each rule evaluation?
- Do different cells show different behavior depending on their identity (e.g. the
cell) or how they are typed (e.g. user-defined types versus builtin types)?
Here is a partial example to show what I mean:
...ANSWER
Answered 2020-Jun-10 at 21:43Each rule is sort-checked at kompile
time to be sort-preserving, so it's not needed to check this at runtime. If something of the correct sort goes in, something of the correct sort comes out.
The cell gets sort
K
, at least for example, in this definition: https://github.com/kframework/evm-semantics/blob/272608d70f363ed3d8d921887b98a26102a03032/evm.md#configuration
it results in compiled.txt
(found at .build/defn/java/driver-kompiled/compiled.txt
) which looks like:
QUESTION
I am writing transpiler (myLang -> JS) using ANTLR (javascript target with visitor).
Focus is on target code generation part, from the parse tree.
As in, how to deal with language source codes variations.
To make question clearer, consider two variations below -
source#1:
PRINT 'hello there'
source#2:
...ANSWER
Answered 2020-Mar-21 at 10:18You're using getChild(1)
to access the argument of the print statement. This will give you a TerminalNode
containing either an ID
or STRLIT
token. You can access the token using the getSymbol()
method and you can then access the token's type using the .type
property. The type will be a number that you can compare against constants like MyLanguageParser.ID
or MyLanaguageParser.STRLIT
.
Using getChild
isn't necessarily the best way to access a node's children though. Each context class will have specific accessors for each of its children.
Specifically the PrintContext
object will have methods ID()
and STRLIT()
. One of them will return null
, the other will return a TerminalNode
object containing the given token. So you know whether it was an ID or string literal by seeing which one isn't null.
That said, the more common solution would be to not have a union of possible kinds of arguments in the print
rule, but instead allow any kind of expression as an argument to print
. You can then use labelled alternatives in your expression
rule to get different visitor methods for each kind of expression:
QUESTION
I came to know that dart mirrors is disabled in flutter but hope that there might be some alternate way to achieve. Mirrors must not be disabled in flutter, it is an important & must have feature.
...ANSWER
Answered 2020-Feb-02 at 00:44So far I am able to know field(s) type:
QUESTION
Prefacing the below. A demo project illustrating this issue can be found at: https://github.com/kirksl/so60384141
I can reference an injected grammar within a native VSCode language
specifying this (package.json)
...ANSWER
Answered 2020-Feb-25 at 20:23You need to inject mylang-js.tmLanguage.json
into source.mylang
as well (injectTo
only applies to the top-level scope name, see explanation here):
QUESTION
We have written some time ago custom extension in VS Code for our internal programming language. We used as starting point built-in PHP extension. It worked fine until one moment (not sure exactly which). Signature Help Provider highlights random parameters. However, in our code, parameter index is correct. I have no idea what is wrong and how SignatureHelp class works.
Here is screenshot how it behaves:
And here is code for SignatureHelp (it's mostly untouched old built-in PHP code. Variable activeP contains correct index, its SignatureHelp class doing something wrong):
...ANSWER
Answered 2019-Sep-07 at 16:02Your main issue is on the line with
QUESTION
I am writing an extension for a specific language for Visual Studio Code and I made it so far that I can set the colors for several commands.
I have my mylang.tmLanguage.json
which contains (simplified) the following:
ANSWER
Answered 2018-Jan-15 at 10:54You could simply include goto
in the patterns for strings
:
QUESTION
As silly as it sounds,I want to build my own programming language--actually, a transpiler.
I have been working on it but I have encountered a problem that my throwerr function is being called for a wrong argument
I have a throwerr function which is meant to "throw an error" for the language whenever there is an error.The throwerr("Unk_args",firstword,linenum)
is meant
to throw an Unknown argument error
whenever the firstword in a line is not in the alllowedFirstWords
array.
It is working well except that it is also being called for a whitespace.That is, it is says:
Unknown argument at line 2
ie Unknown argument (whitespace) at line 2
I don;t want that to happen.Please help.
Here is my code (only the neccassary part)
...ANSWER
Answered 2019-Jun-14 at 15:29I had to change file.split(";")
to file.split("\\s*;\\s*")
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install mylang
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page