Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ambiguity w/ the assignment of Strings #192

Open
GreyWulfos opened this issue Jun 23, 2023 · 6 comments
Open

Ambiguity w/ the assignment of Strings #192

GreyWulfos opened this issue Jun 23, 2023 · 6 comments

Comments

@GreyWulfos
Copy link

Given that strings are currently meant to function with 0 quotes, I'm wondering how strings such as:
const const 8 = Hello! World!

Can be included without a compiler error. When attempting to run the following code, the compiler threw the following error log:

`The provided code is not valid JavaScript syntax and would result in a syntax error.

In JavaScript, variable names cannot start with a number, and "const" is a reserved keyword used to declare a constant variable. Additionally, variable names cannot contain spaces or exclamation marks.

If you want to declare a constant variable with the value "Hello! World!", you can modify the code to adhere to the JavaScript syntax rules, like this:

const myConstant = 'Hello! World!';

In this example, the variable myConstant is declared using the const keyword and assigned the string value 'Hello! World!'.`

@gabrielchl
Copy link

gabrielchl commented Jun 23, 2023

JavaScript is inferior to DreamBerd, never bring that language up again. 👿
/s

@gabrielchl
Copy link

for real tho, yeah, there will be several parts in dreamberd that (probably) couldn't be parsed deterministically

@gabrielchl
Copy link

here's a related comment #74 (comment)

@TodePond
Copy link
Owner

Hey if you were to build a DreamBerd to JavaScript compiler, this is what it would do:

dreamberd

const const 8 = Hello! World!

javascript

const _8 = "Hello";
"World";

there will be several parts in dreamberd that (probably) couldn't be parsed deterministically

Hey, every feature can be done deterministically! For strings, if an error is found in the code, the parser traverses as far along as it can. The next character gets interpreted as a string - then it tries again to parse the code. If that fails again, the next TWO characters are interpreted as a string. It keeps adding more and more characters until it succeeds, or it reaches the end of the file(s). If it's at the end, and it still fails, then a compile-time error happens.

If there are any other cases that you find ambiguous, please let me know :)

@TeraByte-Official
Copy link

const _8 = "Hello";
"World";

WHAT

@james-cnz
Copy link

@TeraByte-Official: I think that's valid JavaScript/ECMAScript. An expression can be used as a statement, I think, but has no effect, other than any side effects caused by evaluating the expression. (None, in this case.)

Due to negative lifetimes, though, I think the code would have to be parsed before the scope of variables could be determined to decide whether something that looks like an identifier is actually an identifier, or should be interpreted as an unquoted string. The easiest approach, I think, would be to only allow unquoted strings that look like identifiers. (That seems to be the approach suggested in the linked comment too.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants