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

Introduce ELIF as token #4

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/PoE.Core/Lexer.fsl
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,12 @@ and realtoken ctxt =
#endif
Parser.ELSE (currPos ctxt)
}
| "elif" {
#if LEXERDEBUG
dbglog "ELIF"
#endif
Parser.ELIF (currPos ctxt)
}
| "true" {
#if LEXERDEBUG
dbglog "TRUE"
Expand Down
31 changes: 25 additions & 6 deletions src/PoE.Core/Parser.fsy
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ open PoE.BitVectorUtils
%token <Annotation> RPIPE ASSIGN COLON
%token <Annotation> PLUS MINUS MUL DIV MOD
%token <Annotation> SHL SHR AND OR XOR NOT
%token <Annotation> IF THEN ELSE
%token <Annotation> IF ELIF THEN ELSE
%token <Annotation> LPAREN RPAREN LBRACK RBRACK COMMA
%token <Annotation> EQ NEQ GT GE LT LE
%token <Annotation> BV INT8 INT16 INT32 INT64 UINT8 UINT16 UINT32 UINT64
Expand Down Expand Up @@ -219,13 +219,32 @@ whilestmt:
WhileStmt ($2, $3, $1) }

ifblockstmt:
IF expr THEN block DEDENT ELSE block { CondStmt ($2, $4, $7, $1) }
| IF expr THEN stmt NEWLINE ELSE block { CondStmt ($2, [ $4 ], $7, $1) }
IF expr THEN block DEDENT ifblockstmtaux
{ CondStmt ($2, $4, $6, $1) }
| IF expr THEN stmt NEWLINE ifblockstmtaux
{ CondStmt ($2, [ $4 ], $6, $1) }

ifblockstmtaux:
ELSE block
{ $2 }
| ELIF expr THEN block DEDENT ifblockstmtaux
{ [ CondStmt ($2, $4, $6, $1) ] }
| ELIF expr THEN stmt NEWLINE ifblockstmtaux
{ [ CondStmt ($2, [ $4 ], $6, $1) ] }

ifsinglestmt:
IF expr THEN stmt NEWLINE ELSE stmt { CondStmt ($2, [ $4 ], [ $7 ], $1) }
| IF expr THEN stmt ELSE stmt { CondStmt ($2, [ $4 ], [ $6 ], $1) }
| IF expr THEN block DEDENT ELSE stmt { CondStmt ($2, $4, [ $7 ], $1) }
IF expr THEN block DEDENT ifsinglestmtaux
{ CondStmt ($2, $4, $6, $1) }
| IF expr THEN stmt NEWLINE ifsinglestmtaux
{ CondStmt ($2, [ $4 ], $6, $1) }

ifsinglestmtaux:
ELSE stmt
{ [ $2 ] }
| ELIF expr THEN block DEDENT ifsinglestmtaux
{ [ CondStmt ($2, $4, $6, $1) ] }
| ELIF expr THEN stmt NEWLINE ifsinglestmtaux
{ [ CondStmt ($2, [ $4 ], $6, $1) ] }

breakstmt:
BREAK { BreakStmt ($1) }
Expand Down