-
Notifications
You must be signed in to change notification settings - Fork 0
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
Expression parser #9
Conversation
Changed the grammar
…thout error and end handling
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job!
src/compiler/parser/Expressions.c
Outdated
return id; | ||
} | ||
if(id->token->type = TOKEN_IDENTIFIER){ | ||
IdentifierASTNode *identifierE = new_IdentifierASTNode(id->token->value.string); //string or identifier? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strings are being considered literals; This might not apply if the string is interpolated (we'll discuss this later).
The general idea is that when the string literal is encountered, some sub-procedure should trigger and match pattern like "string expression string ... string expression string". After each string, there should be either an expression (without any direct operator, "str" 2 + 3
) or operator ("str" + 2 + 3
), or some terminator (;
, EOF
, ...).
["str", 2, +, 3]
, should be parsed into:
StringLiteralExpression:
* StringLiteralSegmentList:
- StringSegment
* value: String* ("str")
- BinaryExpression
* left: ... (2)
* right: ... (3)
...
- StringSegment (string literal is guaranteed to end by string)
* value: String* ("")
Note: The strings can be nested: "pre\("in")post"
-> ["pre", "in", "post"]
->
StringLiteralExpression [
StringSegment("pre"),
StringLiteralExpression [ StringSegment("in") ],
StringSegment("post")
]
Notice: This feature is not currently available in the project, but will be implemented in the upcoming time.
…into expressionParser
Add new AST nodes, functions for creating them, expression parsing wi
thout error and end handling